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

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

Issue 2622303006: Reapply "Add support for generic function type syntax, part 1" (Closed)
Patch Set: Created 3 years, 11 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/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 2e1b856312f52d726e107c78bcbf743e86831b60..6e3ecfcfdb5f744d75d8850096b2936b3b3c9fae 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -372,13 +372,13 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
*/
bool _checkAllTypeChecks(IsExpression node) {
Expression expression = node.expression;
- TypeName typeName = node.type;
+ TypeAnnotation typeName = node.type;
DartType lhsType = expression.staticType;
DartType rhsType = typeName.type;
if (lhsType == null || rhsType == null) {
return false;
}
- String rhsNameStr = typeName.name.name;
+ String rhsNameStr = typeName is TypeName ? typeName.name.name : null;
// if x is dynamic
if (rhsType.isDynamic && rhsNameStr == Keyword.DYNAMIC.syntax) {
if (node.notOperator == null) {
@@ -884,7 +884,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
* @return `true` if and only if a hint code is generated on the passed node
* See [HintCode.MISSING_RETURN].
*/
- void _checkForMissingReturn(TypeName returnType, FunctionBody body) {
+ void _checkForMissingReturn(TypeAnnotation returnType, FunctionBody body) {
// Check that the method or function has a return type, and a function body
if (returnType == null || body == null) {
return;
@@ -1847,8 +1847,7 @@ class Dart2JSVerifier extends RecursiveAstVisitor<Object> {
* [HintCode.IS_NOT_INT].
*/
bool _checkForIsDoubleHints(IsExpression node) {
- TypeName typeName = node.type;
- DartType type = typeName.type;
+ DartType type = node.type.type;
Element element = type?.element;
if (element != null) {
String typeNameStr = element.name;
@@ -3020,6 +3019,9 @@ class ExitDetector extends GeneralizingAstVisitor<bool> {
}
@override
+ bool visitGenericFunctionType(GenericFunctionType node) => false;
+
+ @override
bool visitIdentifier(Identifier node) => false;
@override
@@ -6092,6 +6094,9 @@ class ResolverVisitor extends ScopedVisitor {
}
@override
+ Object visitGenericFunctionType(GenericFunctionType node) => null;
+
+ @override
Object visitHideCombinator(HideCombinator node) => null;
@override
@@ -8025,7 +8030,7 @@ class ToDoFinder {
}
/**
- * Helper for resolving [TypeName]s.
+ * Helper for resolving types.
*
* The client must set [nameScope] before calling [resolveTypeName].
*/
@@ -8304,15 +8309,14 @@ class TypeNameResolver {
return;
}
if (argumentList != null) {
- NodeList<TypeName> arguments = argumentList.arguments;
+ NodeList<TypeAnnotation> arguments = argumentList.arguments;
int argumentCount = arguments.length;
List<DartType> parameters = typeSystem.typeFormalsAsTypes(type);
int parameterCount = parameters.length;
List<DartType> typeArguments = new List<DartType>(parameterCount);
if (argumentCount == parameterCount) {
for (int i = 0; i < parameterCount; i++) {
- TypeName argumentTypeName = arguments[i];
- DartType argumentType = _getType(argumentTypeName);
+ DartType argumentType = _getType(arguments[i]);
if (argumentType == null) {
argumentType = dynamicType;
}
@@ -8334,16 +8338,12 @@ class TypeNameResolver {
}
/**
- * The number of type arguments in the given type name does not match the number of parameters in
- * the corresponding class element. Return the error code that should be used to report this
- * error.
- *
- * @param node the type name with the wrong number of type arguments
- * @return the error code that should be used to report that the wrong number of type arguments
- * were provided
+ * The number of type arguments in the given [typeName] does not match the
+ * number of parameters in the corresponding class element. Return the error
+ * code that should be used to report this error.
*/
- ErrorCode _getInvalidTypeParametersErrorCode(TypeName node) {
- AstNode parent = node.parent;
+ ErrorCode _getInvalidTypeParametersErrorCode(TypeName typeName) {
+ AstNode parent = typeName.parent;
if (parent is ConstructorName) {
parent = parent.parent;
if (parent is InstanceCreationExpression) {
@@ -8358,11 +8358,7 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name is the target in a redirected constructor.
- *
- * @param typeName the type name to analyze
- * @return some [RedirectingConstructorKind] if the given type name is used as the type in a
- * redirected constructor, or `null` otherwise
+ * Checks if the given [typeName] is the target in a redirected constructor.
*/
RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) {
AstNode parent = typeName.parent;
@@ -8381,13 +8377,10 @@ class TypeNameResolver {
}
/**
- * Return the type represented by the given type name.
- *
- * @param typeName the type name representing the type to be returned
- * @return the type represented by the type name
+ * Return the type represented by the given type [annotation].
*/
- DartType _getType(TypeName typeName) {
- DartType type = typeName.type;
+ DartType _getType(TypeAnnotation annotation) {
+ DartType type = annotation.type;
if (type == null) {
return undefinedType;
}
@@ -8431,10 +8424,7 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name is used as the type in an as expression.
- *
- * @param typeName the type name to analyzer
- * @return `true` if the given type name is used as the type in an as expression
+ * Checks if the given [typeName] is used as the type in an as expression.
*/
bool _isTypeNameInAsExpression(TypeName typeName) {
AstNode parent = typeName.parent;
@@ -8445,10 +8435,8 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name is used as the exception type in a catch clause.
- *
- * @param typeName the type name to analyzer
- * @return `true` if the given type name is used as the exception type in a catch clause
+ * Checks if the given [typeName] is used as the exception type in a catch
+ * clause.
*/
bool _isTypeNameInCatchClause(TypeName typeName) {
AstNode parent = typeName.parent;
@@ -8459,11 +8447,8 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name is used as the type in an instance creation expression.
- *
- * @param typeName the type name to analyzer
- * @return `true` if the given type name is used as the type in an instance creation
- * expression
+ * Checks if the given [typeName] is used as the type in an instance creation
+ * expression.
*/
bool _isTypeNameInInstanceCreationExpression(TypeName typeName) {
AstNode parent = typeName.parent;
@@ -8475,10 +8460,7 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name is used as the type in an is expression.
- *
- * @param typeName the type name to analyzer
- * @return `true` if the given type name is used as the type in an is expression
+ * Checks if the given [typeName] is used as the type in an is expression.
*/
bool _isTypeNameInIsExpression(TypeName typeName) {
AstNode parent = typeName.parent;
@@ -8489,10 +8471,7 @@ class TypeNameResolver {
}
/**
- * Checks if the given type name used in a type argument list.
- *
- * @param typeName the type name to analyzer
- * @return `true` if the given type name is in a type argument list
+ * Checks if the given [typeName] used in a type argument list.
*/
bool _isTypeNameInTypeArgumentList(TypeName typeName) =>
typeName.parent is TypeArgumentList;
@@ -8515,24 +8494,24 @@ class TypeNameResolver {
}
/**
- * @return `true` if the name of the given [TypeName] is an built-in identifier.
+ * Return `true` if the name of the given [typeName] is an built-in identifier.
*/
- static bool _isBuiltInIdentifier(TypeName node) {
- Token token = node.name.beginToken;
+ static bool _isBuiltInIdentifier(TypeName typeName) {
+ Token token = typeName.name.beginToken;
return token.type == TokenType.KEYWORD;
}
/**
- * @return `true` if given [TypeName] is used as a type annotation.
+ * @return `true` if given [typeName] is used as a type annotation.
*/
- static bool _isTypeAnnotation(TypeName node) {
- AstNode parent = node.parent;
+ static bool _isTypeAnnotation(TypeName typeName) {
+ AstNode parent = typeName.parent;
if (parent is VariableDeclarationList) {
- return identical(parent.type, node);
+ return identical(parent.type, typeName);
} else if (parent is FieldFormalParameter) {
- return identical(parent.type, node);
+ return identical(parent.type, typeName);
} else if (parent is SimpleFormalParameter) {
- return identical(parent.type, node);
+ return identical(parent.type, typeName);
}
return false;
}
@@ -8800,10 +8779,15 @@ class TypeParameterBoundsResolver {
}
}
- void _resolveTypeName(TypeName typeName) {
- typeName.typeArguments?.arguments?.forEach(_resolveTypeName);
- typeNameResolver.resolveTypeName(typeName);
- // TODO(scheglov) report error when don't apply type bounds for type bounds
+ void _resolveTypeName(TypeAnnotation type) {
+ if (type is TypeName) {
+ type.typeArguments?.arguments?.forEach(_resolveTypeName);
+ typeNameResolver.resolveTypeName(type);
+ // TODO(scheglov) report error when don't apply type bounds for type bounds
+ } else {
+ // TODO(brianwilkerson) Add resolution of GenericFunctionType
+ throw new ArgumentError('Cannot resolve a ${type.runtimeType}');
+ }
}
void _resolveTypeParameters(
@@ -8811,13 +8795,19 @@ class TypeParameterBoundsResolver {
if (typeParameters != null) {
Scope typeParametersScope = null;
for (TypeParameter typeParameter in typeParameters.typeParameters) {
- TypeName bound = typeParameter.bound;
+ TypeAnnotation bound = typeParameter.bound;
if (bound != null) {
Element typeParameterElement = typeParameter.name.staticElement;
if (typeParameterElement is TypeParameterElementImpl) {
if (LibraryElementImpl.hasResolutionCapability(
library, LibraryResolutionCapability.resolvedTypeNames)) {
- bound.type = typeParameterElement.bound;
+ if (bound is TypeName) {
+ bound.type = typeParameterElement.bound;
+ } else {
+ // TODO(brianwilkerson) Add resolution of GenericFunctionType
+ throw new ArgumentError(
+ 'Cannot resolve a ${bound.runtimeType}');
+ }
} else {
libraryScope ??= new LibraryScope(library);
typeParametersScope ??= createTypeParametersScope();
@@ -9495,7 +9485,7 @@ class TypeResolverVisitor extends ScopedVisitor {
TypeSystem _typeSystem;
/**
- * The helper to resolve [TypeName]s.
+ * The helper to resolve types.
*/
TypeNameResolver _typeNameResolver;
@@ -9577,7 +9567,7 @@ class TypeResolverVisitor extends ScopedVisitor {
// If an 'on' clause is provided the type of the exception parameter is
// the type in the 'on' clause. Otherwise, the type of the exception
// parameter is 'Object'.
- TypeName exceptionTypeName = node.exceptionType;
+ TypeAnnotation exceptionTypeName = node.exceptionType;
DartType exceptionType;
if (exceptionTypeName == null) {
exceptionType = typeProvider.dynamicType;
@@ -9716,7 +9706,7 @@ class TypeResolverVisitor extends ScopedVisitor {
Object visitDeclaredIdentifier(DeclaredIdentifier node) {
super.visitDeclaredIdentifier(node);
DartType declaredType;
- TypeName typeName = node.type;
+ TypeAnnotation typeName = node.type;
if (typeName == null) {
declaredType = _dynamicType;
} else {
@@ -9735,7 +9725,7 @@ class TypeResolverVisitor extends ScopedVisitor {
FormalParameterList parameterList = node.parameters;
if (parameterList == null) {
DartType type;
- TypeName typeName = node.type;
+ TypeAnnotation typeName = node.type;
if (typeName == null) {
element.hasImplicitType = true;
if (element is FieldFormalParameterElement) {
@@ -9958,7 +9948,7 @@ class TypeResolverVisitor extends ScopedVisitor {
Object visitSimpleFormalParameter(SimpleFormalParameter node) {
super.visitSimpleFormalParameter(node);
DartType declaredType;
- TypeName typeName = node.type;
+ TypeAnnotation typeName = node.type;
if (typeName == null) {
declaredType = _dynamicType;
} else {
@@ -9997,7 +9987,7 @@ class TypeResolverVisitor extends ScopedVisitor {
// Bounds of parameters of classes and function type aliases are
// already resolved.
} else {
- TypeName bound = node.bound;
+ TypeAnnotation bound = node.bound;
if (bound != null) {
TypeParameterElementImpl typeParameter =
node.name.staticElement as TypeParameterElementImpl;
@@ -10022,7 +10012,7 @@ class TypeResolverVisitor extends ScopedVisitor {
}
// Resolve the type.
DartType declaredType;
- TypeName typeName = variableList.type;
+ TypeAnnotation typeName = variableList.type;
if (typeName == null) {
declaredType = _dynamicType;
} else {
@@ -10036,13 +10026,10 @@ class TypeResolverVisitor extends ScopedVisitor {
}
/**
- * Given a type name representing the return type of a function, compute the return type of the
+ * Given the [returnType] of a function, compute the return type of the
* function.
- *
- * @param returnType the type name representing the return type of the function
- * @return the return type that was computed
*/
- DartType _computeReturnType(TypeName returnType) {
+ DartType _computeReturnType(TypeAnnotation returnType) {
if (returnType == null) {
return _dynamicType;
} else {
@@ -10124,13 +10111,8 @@ class TypeResolverVisitor extends ScopedVisitor {
}
/**
- * Resolve the types in the given with and implements clauses and associate those types with the
- * given class element.
- *
- * @param classElement the class element with which the mixin and interface types are to be
- * associated
- * @param withClause the with clause to be resolved
- * @param implementsClause the implements clause to be resolved
+ * Resolve the types in the given [withClause] and [implementsClause] and
+ * associate those types with the given [classElement].
*/
void _resolve(ClassElementImpl classElement, WithClause withClause,
ImplementsClause implementsClause) {
@@ -10239,15 +10221,12 @@ class TypeResolverVisitor extends ScopedVisitor {
}
/**
- * Given a parameter element, create a function type based on the given return type and parameter
- * list and associate the created type with the element.
- *
- * @param element the parameter element whose type is to be set
- * @param returnType the (possibly `null`) return type of the function
- * @param parameterList the list of parameters to the function
+ * Given a parameter [element], create a function type based on the given
+ * [returnType] and [parameterList] and associate the created type with the
+ * element.
*/
void _setFunctionTypedParameterType(ParameterElementImpl element,
- TypeName returnType, FormalParameterList parameterList) {
+ TypeAnnotation returnType, FormalParameterList parameterList) {
List<ParameterElement> parameters = _getElements(parameterList);
FunctionElementImpl functionElement = new FunctionElementImpl.forNode(null);
functionElement.isSynthetic = true;
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698