Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: pkg/analyzer-experimental/lib/src/generated/resolver.dart

Issue 12543003: Use limited JavaStringBuilder implementation instead of Dart StringBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer-experimental/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer-experimental/lib/src/generated/resolver.dart b/pkg/analyzer-experimental/lib/src/generated/resolver.dart
index 78ea5a431ba2d14bac9439a4347f548eb7cb1a91..f89a51b542b428a1ac9e453a0f9bb5a49abecb3d 100644
--- a/pkg/analyzer-experimental/lib/src/generated/resolver.dart
+++ b/pkg/analyzer-experimental/lib/src/generated/resolver.dart
@@ -869,6 +869,20 @@ class ElementResolver extends SimpleASTVisitor<Object> {
element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrary);
if (element == null) {
element = lookUpMethod(_resolver.enclosingClass, methodName2.name);
+ if (element == null) {
+ PropertyAccessorElement getter = lookUpGetter(_resolver.enclosingClass, methodName2.name);
+ if (getter != null) {
+ FunctionType getterType = getter.type;
+ if (getterType != null) {
+ Type2 returnType4 = getterType.returnType;
+ if (!returnType4.isDynamic() && returnType4 is! FunctionType && !returnType4.isDartCoreFunction()) {
+ _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
+ }
+ }
+ recordResolution(methodName2, getter);
+ return null;
+ }
+ }
}
} else {
Type2 targetType = getType(target);
@@ -877,8 +891,8 @@ class ElementResolver extends SimpleASTVisitor<Object> {
if (element == null) {
PropertyAccessorElement accessor = lookUpGetterInType((targetType.element as ClassElement), methodName2.name);
if (accessor != null) {
- Type2 returnType4 = accessor.type.returnType;
- if (!returnType4.isDynamic() && returnType4 is! FunctionType) {
+ Type2 returnType5 = accessor.type.returnType;
+ if (!returnType5.isDynamic() && returnType5 is! FunctionType && !returnType5.isDartCoreFunction()) {
_resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
return null;
}
@@ -910,8 +924,8 @@ class ElementResolver extends SimpleASTVisitor<Object> {
PropertyAccessorElement getter3 = ((element as PropertyInducingElement)).getter;
FunctionType getterType = getter3.type;
if (getterType != null) {
- Type2 returnType5 = getterType.returnType;
- if (!returnType5.isDynamic() && returnType5 is! FunctionType) {
+ Type2 returnType6 = getterType.returnType;
+ if (!returnType6.isDynamic() && returnType6 is! FunctionType && !returnType6.isDartCoreFunction()) {
_resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
}
}
@@ -919,7 +933,7 @@ class ElementResolver extends SimpleASTVisitor<Object> {
return null;
} else if (element is VariableElement) {
Type2 variableType = ((element as VariableElement)).type;
- if (!variableType.isDynamic() && variableType is! FunctionType) {
+ if (!variableType.isDynamic() && variableType is! FunctionType && !variableType.isDartCoreFunction()) {
_resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
}
recordResolution(methodName2, element);
@@ -1789,9 +1803,9 @@ class Library {
* @throws IllegalArgumentException if the string is not a constant string without any string
* interpolation
*/
- void appendStringValue(StringBuffer builder, StringLiteral literal) {
+ void appendStringValue(JavaStringBuilder builder, StringLiteral literal) {
if (literal is SimpleStringLiteral) {
- builder.write(((literal as SimpleStringLiteral)).value);
+ builder.append(((literal as SimpleStringLiteral)).value);
} else if (literal is AdjacentStrings) {
for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings) {
appendStringValue(builder, stringLiteral);
@@ -1819,7 +1833,7 @@ class Library {
* @return the value of the given string literal
*/
String getStringValue(StringLiteral literal) {
- StringBuffer builder = new StringBuffer();
+ JavaStringBuilder builder = new JavaStringBuilder();
try {
appendStringValue(builder, literal);
} on IllegalArgumentException catch (exception) {
@@ -3453,11 +3467,11 @@ class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
* @return the return type that was computed
*/
Type2 computeReturnType(FunctionDeclaration node) {
- TypeName returnType6 = node.returnType;
- if (returnType6 == null) {
+ TypeName returnType7 = node.returnType;
+ if (returnType7 == null) {
return computeReturnType2(node.functionExpression);
}
- return returnType6.type;
+ return returnType7.type;
}
/**
* Given a function expression, compute the return type of the function. The return type of
@@ -3584,7 +3598,7 @@ class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
* @param returnType the return type of the function, or {@code null} if no type was declared
* @param parameters the elements representing the parameters to the function
*/
- void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType9, FormalParameterList parameterList) {
+ void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType10, FormalParameterList parameterList) {
List<Type2> normalParameterTypes = new List<Type2>();
List<Type2> optionalParameterTypes = new List<Type2>();
LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
@@ -3605,7 +3619,7 @@ class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
functionType.normalParameterTypes = new List.from(normalParameterTypes);
functionType.optionalParameterTypes = new List.from(optionalParameterTypes);
functionType.namedParameterTypes = namedParameterTypes;
- functionType.returnType = returnType9;
+ functionType.returnType = returnType10;
}
}
/**
@@ -4293,7 +4307,7 @@ class TypeResolverVisitor extends ScopedVisitor {
* @param returnType the return type of the function, or {@code null} if no type was declared
* @param parameters the elements representing the parameters to the function
*/
- void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType10, List<ParameterElement> parameters) {
+ void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType11, List<ParameterElement> parameters) {
List<Type2> normalParameterTypes = new List<Type2>();
List<Type2> optionalParameterTypes = new List<Type2>();
LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
@@ -4318,10 +4332,10 @@ class TypeResolverVisitor extends ScopedVisitor {
if (!namedParameterTypes.isEmpty) {
functionType.namedParameterTypes = namedParameterTypes;
}
- if (returnType10 == null) {
+ if (returnType11 == null) {
functionType.returnType = _dynamicType;
} else {
- functionType.returnType = returnType10.type;
+ functionType.returnType = returnType11.type;
}
}
}
@@ -5167,6 +5181,14 @@ class ErrorVerifier extends RecursiveASTVisitor<Object> {
}
return super.visitAssignmentExpression(node);
}
+ Object visitClassDeclaration(ClassDeclaration node) {
+ checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME);
+ return super.visitClassDeclaration(node);
+ }
+ Object visitClassTypeAlias(ClassTypeAlias node) {
+ checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
+ return super.visitClassTypeAlias(node);
+ }
Object visitConditionalExpression(ConditionalExpression node) {
checkForNonBoolCondition(node.condition);
return super.visitConditionalExpression(node);
@@ -5202,6 +5224,10 @@ class ErrorVerifier extends RecursiveASTVisitor<Object> {
_currentFunction = previousFunction;
}
}
+ Object visitFunctionTypeAlias(FunctionTypeAlias node) {
+ checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
+ return super.visitFunctionTypeAlias(node);
+ }
Object visitIfStatement(IfStatement node) {
checkForNonBoolCondition(node.condition);
return super.visitIfStatement(node);
@@ -5265,11 +5291,28 @@ class ErrorVerifier extends RecursiveASTVisitor<Object> {
}
return super.visitReturnStatement(node);
}
+ Object visitTypeParameter(TypeParameter node) {
+ checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME);
+ return super.visitTypeParameter(node);
+ }
Object visitWhileStatement(WhileStatement node) {
checkForNonBoolCondition(node.condition);
return super.visitWhileStatement(node);
}
/**
+ * This verifies that the passed identifier is not a keyword, and generates the passed error code
+ * on the identifier if it is a keyword.
+ * @param identifier the identifier to check to ensure that it is not a keyword
+ * @param errorCode if the passed identifier is a keyword then this error code is created on the
+ * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME}
+ */
+ void checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode errorCode) {
+ Token token13 = identifier.token;
+ if (identical(token13.type, TokenType.KEYWORD)) {
+ _errorReporter.reportError(errorCode, identifier, [identifier.name]);
+ }
+ }
+ /**
* Checks to ensure that the expressions that need to be of type bool, are. Otherwise an error is
* reported on the expression.
* @see StaticTypeWarningCode#NON_BOOL_CONDITION

Powered by Google App Engine
This is Rietveld 408576698