| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 * checks expressed using an is expression. | 365 * checks expressed using an is expression. |
| 366 * | 366 * |
| 367 * @param node the is expression to check | 367 * @param node the is expression to check |
| 368 * @return `true` if and only if a hint code is generated on the passed node | 368 * @return `true` if and only if a hint code is generated on the passed node |
| 369 * See [HintCode.TYPE_CHECK_IS_NOT_NULL], [HintCode.TYPE_CHECK_IS_NULL], | 369 * See [HintCode.TYPE_CHECK_IS_NOT_NULL], [HintCode.TYPE_CHECK_IS_NULL], |
| 370 * [HintCode.UNNECESSARY_TYPE_CHECK_TRUE], and | 370 * [HintCode.UNNECESSARY_TYPE_CHECK_TRUE], and |
| 371 * [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]. | 371 * [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]. |
| 372 */ | 372 */ |
| 373 bool _checkAllTypeChecks(IsExpression node) { | 373 bool _checkAllTypeChecks(IsExpression node) { |
| 374 Expression expression = node.expression; | 374 Expression expression = node.expression; |
| 375 TypeName typeName = node.type; | 375 TypeAnnotation typeName = node.type; |
| 376 DartType lhsType = expression.staticType; | 376 DartType lhsType = expression.staticType; |
| 377 DartType rhsType = typeName.type; | 377 DartType rhsType = typeName.type; |
| 378 if (lhsType == null || rhsType == null) { | 378 if (lhsType == null || rhsType == null) { |
| 379 return false; | 379 return false; |
| 380 } | 380 } |
| 381 String rhsNameStr = typeName.name.name; | 381 String rhsNameStr = typeName is TypeName ? typeName.name.name : null; |
| 382 // if x is dynamic | 382 // if x is dynamic |
| 383 if (rhsType.isDynamic && rhsNameStr == Keyword.DYNAMIC.syntax) { | 383 if (rhsType.isDynamic && rhsNameStr == Keyword.DYNAMIC.syntax) { |
| 384 if (node.notOperator == null) { | 384 if (node.notOperator == null) { |
| 385 // the is case | 385 // the is case |
| 386 _errorReporter.reportErrorForNode( | 386 _errorReporter.reportErrorForNode( |
| 387 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node); | 387 HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node); |
| 388 } else { | 388 } else { |
| 389 // the is not case | 389 // the is not case |
| 390 _errorReporter.reportErrorForNode( | 390 _errorReporter.reportErrorForNode( |
| 391 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node); | 391 HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 * `null`, avoiding these implicit returns is considered a best practice. | 877 * `null`, avoiding these implicit returns is considered a best practice. |
| 878 * | 878 * |
| 879 * Note: for async functions/methods, this hint only applies when the | 879 * Note: for async functions/methods, this hint only applies when the |
| 880 * function has a return type that Future<Null> is not assignable to. | 880 * function has a return type that Future<Null> is not assignable to. |
| 881 * | 881 * |
| 882 * @param node the binary expression to check | 882 * @param node the binary expression to check |
| 883 * @param body the function body | 883 * @param body the function body |
| 884 * @return `true` if and only if a hint code is generated on the passed node | 884 * @return `true` if and only if a hint code is generated on the passed node |
| 885 * See [HintCode.MISSING_RETURN]. | 885 * See [HintCode.MISSING_RETURN]. |
| 886 */ | 886 */ |
| 887 void _checkForMissingReturn(TypeName returnType, FunctionBody body) { | 887 void _checkForMissingReturn(TypeAnnotation returnType, FunctionBody body) { |
| 888 // Check that the method or function has a return type, and a function body | 888 // Check that the method or function has a return type, and a function body |
| 889 if (returnType == null || body == null) { | 889 if (returnType == null || body == null) { |
| 890 return; | 890 return; |
| 891 } | 891 } |
| 892 // Check that the body is a BlockFunctionBody | 892 // Check that the body is a BlockFunctionBody |
| 893 if (body is BlockFunctionBody) { | 893 if (body is BlockFunctionBody) { |
| 894 // Generators are never required to have a return statement. | 894 // Generators are never required to have a return statement. |
| 895 if (body.isGenerator) { | 895 if (body.isGenerator) { |
| 896 return; | 896 return; |
| 897 } | 897 } |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 * `x is! int`. | 1840 * `x is! int`. |
| 1841 * | 1841 * |
| 1842 * @param node the is expression to check | 1842 * @param node the is expression to check |
| 1843 * @return `true` if and only if a hint code is generated on the passed node | 1843 * @return `true` if and only if a hint code is generated on the passed node |
| 1844 * See [HintCode.IS_DOUBLE], | 1844 * See [HintCode.IS_DOUBLE], |
| 1845 * [HintCode.IS_INT], | 1845 * [HintCode.IS_INT], |
| 1846 * [HintCode.IS_NOT_DOUBLE], and | 1846 * [HintCode.IS_NOT_DOUBLE], and |
| 1847 * [HintCode.IS_NOT_INT]. | 1847 * [HintCode.IS_NOT_INT]. |
| 1848 */ | 1848 */ |
| 1849 bool _checkForIsDoubleHints(IsExpression node) { | 1849 bool _checkForIsDoubleHints(IsExpression node) { |
| 1850 TypeName typeName = node.type; | 1850 DartType type = node.type.type; |
| 1851 DartType type = typeName.type; | |
| 1852 Element element = type?.element; | 1851 Element element = type?.element; |
| 1853 if (element != null) { | 1852 if (element != null) { |
| 1854 String typeNameStr = element.name; | 1853 String typeNameStr = element.name; |
| 1855 LibraryElement libraryElement = element.library; | 1854 LibraryElement libraryElement = element.library; |
| 1856 // if (typeNameStr.equals(INT_TYPE_NAME) && libraryElement != null | 1855 // if (typeNameStr.equals(INT_TYPE_NAME) && libraryElement != null |
| 1857 // && libraryElement.isDartCore()) { | 1856 // && libraryElement.isDartCore()) { |
| 1858 // if (node.getNotOperator() == null) { | 1857 // if (node.getNotOperator() == null) { |
| 1859 // errorReporter.reportError(HintCode.IS_INT, node); | 1858 // errorReporter.reportError(HintCode.IS_INT, node); |
| 1860 // } else { | 1859 // } else { |
| 1861 // errorReporter.reportError(HintCode.IS_NOT_INT, node); | 1860 // errorReporter.reportError(HintCode.IS_NOT_INT, node); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3013 | 3012 |
| 3014 @override | 3013 @override |
| 3015 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 3014 bool visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 3016 if (_nodeExits(node.function)) { | 3015 if (_nodeExits(node.function)) { |
| 3017 return true; | 3016 return true; |
| 3018 } | 3017 } |
| 3019 return node.argumentList.accept(this); | 3018 return node.argumentList.accept(this); |
| 3020 } | 3019 } |
| 3021 | 3020 |
| 3022 @override | 3021 @override |
| 3022 bool visitGenericFunctionType(GenericFunctionType node) => false; |
| 3023 |
| 3024 @override |
| 3023 bool visitIdentifier(Identifier node) => false; | 3025 bool visitIdentifier(Identifier node) => false; |
| 3024 | 3026 |
| 3025 @override | 3027 @override |
| 3026 bool visitIfStatement(IfStatement node) { | 3028 bool visitIfStatement(IfStatement node) { |
| 3027 Expression conditionExpression = node.condition; | 3029 Expression conditionExpression = node.condition; |
| 3028 Statement thenStatement = node.thenStatement; | 3030 Statement thenStatement = node.thenStatement; |
| 3029 Statement elseStatement = node.elseStatement; | 3031 Statement elseStatement = node.elseStatement; |
| 3030 if (_nodeExits(conditionExpression)) { | 3032 if (_nodeExits(conditionExpression)) { |
| 3031 return true; | 3033 return true; |
| 3032 } | 3034 } |
| (...skipping 3052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6085 return null; | 6087 return null; |
| 6086 } | 6088 } |
| 6087 | 6089 |
| 6088 @override | 6090 @override |
| 6089 void visitFunctionTypeAliasInScope(FunctionTypeAlias node) { | 6091 void visitFunctionTypeAliasInScope(FunctionTypeAlias node) { |
| 6090 super.visitFunctionTypeAliasInScope(node); | 6092 super.visitFunctionTypeAliasInScope(node); |
| 6091 safelyVisitComment(node.documentationComment); | 6093 safelyVisitComment(node.documentationComment); |
| 6092 } | 6094 } |
| 6093 | 6095 |
| 6094 @override | 6096 @override |
| 6097 Object visitGenericFunctionType(GenericFunctionType node) => null; |
| 6098 |
| 6099 @override |
| 6095 Object visitHideCombinator(HideCombinator node) => null; | 6100 Object visitHideCombinator(HideCombinator node) => null; |
| 6096 | 6101 |
| 6097 @override | 6102 @override |
| 6098 Object visitIfStatement(IfStatement node) { | 6103 Object visitIfStatement(IfStatement node) { |
| 6099 Expression condition = node.condition; | 6104 Expression condition = node.condition; |
| 6100 condition?.accept(this); | 6105 condition?.accept(this); |
| 6101 Map<VariableElement, DartType> thenOverrides = | 6106 Map<VariableElement, DartType> thenOverrides = |
| 6102 const <VariableElement, DartType>{}; | 6107 const <VariableElement, DartType>{}; |
| 6103 Statement thenStatement = node.thenStatement; | 6108 Statement thenStatement = node.thenStatement; |
| 6104 if (thenStatement != null) { | 6109 if (thenStatement != null) { |
| (...skipping 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8019 for (Match match in matches) { | 8024 for (Match match in matches) { |
| 8020 int offset = commentToken.offset + match.start + match.group(1).length; | 8025 int offset = commentToken.offset + match.start + match.group(1).length; |
| 8021 int length = match.group(2).length; | 8026 int length = match.group(2).length; |
| 8022 _errorReporter.reportErrorForOffset( | 8027 _errorReporter.reportErrorForOffset( |
| 8023 TodoCode.TODO, offset, length, [match.group(2)]); | 8028 TodoCode.TODO, offset, length, [match.group(2)]); |
| 8024 } | 8029 } |
| 8025 } | 8030 } |
| 8026 } | 8031 } |
| 8027 | 8032 |
| 8028 /** | 8033 /** |
| 8029 * Helper for resolving [TypeName]s. | 8034 * Helper for resolving types. |
| 8030 * | 8035 * |
| 8031 * The client must set [nameScope] before calling [resolveTypeName]. | 8036 * The client must set [nameScope] before calling [resolveTypeName]. |
| 8032 */ | 8037 */ |
| 8033 class TypeNameResolver { | 8038 class TypeNameResolver { |
| 8034 final TypeSystem typeSystem; | 8039 final TypeSystem typeSystem; |
| 8035 final DartType dynamicType; | 8040 final DartType dynamicType; |
| 8036 final DartType undefinedType; | 8041 final DartType undefinedType; |
| 8037 final LibraryElement definingLibrary; | 8042 final LibraryElement definingLibrary; |
| 8038 final Source source; | 8043 final Source source; |
| 8039 final AnalysisErrorListener errorListener; | 8044 final AnalysisErrorListener errorListener; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8298 } else { | 8303 } else { |
| 8299 reportErrorForNode( | 8304 reportErrorForNode( |
| 8300 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); | 8305 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); |
| 8301 } | 8306 } |
| 8302 } | 8307 } |
| 8303 typeName.staticType = dynamicType; | 8308 typeName.staticType = dynamicType; |
| 8304 node.type = dynamicType; | 8309 node.type = dynamicType; |
| 8305 return; | 8310 return; |
| 8306 } | 8311 } |
| 8307 if (argumentList != null) { | 8312 if (argumentList != null) { |
| 8308 NodeList<TypeName> arguments = argumentList.arguments; | 8313 NodeList<TypeAnnotation> arguments = argumentList.arguments; |
| 8309 int argumentCount = arguments.length; | 8314 int argumentCount = arguments.length; |
| 8310 List<DartType> parameters = typeSystem.typeFormalsAsTypes(type); | 8315 List<DartType> parameters = typeSystem.typeFormalsAsTypes(type); |
| 8311 int parameterCount = parameters.length; | 8316 int parameterCount = parameters.length; |
| 8312 List<DartType> typeArguments = new List<DartType>(parameterCount); | 8317 List<DartType> typeArguments = new List<DartType>(parameterCount); |
| 8313 if (argumentCount == parameterCount) { | 8318 if (argumentCount == parameterCount) { |
| 8314 for (int i = 0; i < parameterCount; i++) { | 8319 for (int i = 0; i < parameterCount; i++) { |
| 8315 TypeName argumentTypeName = arguments[i]; | 8320 DartType argumentType = _getType(arguments[i]); |
| 8316 DartType argumentType = _getType(argumentTypeName); | |
| 8317 if (argumentType == null) { | 8321 if (argumentType == null) { |
| 8318 argumentType = dynamicType; | 8322 argumentType = dynamicType; |
| 8319 } | 8323 } |
| 8320 typeArguments[i] = argumentType; | 8324 typeArguments[i] = argumentType; |
| 8321 } | 8325 } |
| 8322 } else { | 8326 } else { |
| 8323 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, | 8327 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, |
| 8324 [typeName.name, parameterCount, argumentCount]); | 8328 [typeName.name, parameterCount, argumentCount]); |
| 8325 for (int i = 0; i < parameterCount; i++) { | 8329 for (int i = 0; i < parameterCount; i++) { |
| 8326 typeArguments[i] = dynamicType; | 8330 typeArguments[i] = dynamicType; |
| 8327 } | 8331 } |
| 8328 } | 8332 } |
| 8329 type = typeSystem.instantiateType(type, typeArguments); | 8333 type = typeSystem.instantiateType(type, typeArguments); |
| 8330 } else { | 8334 } else { |
| 8331 type = typeSystem.instantiateToBounds(type); | 8335 type = typeSystem.instantiateToBounds(type); |
| 8332 } | 8336 } |
| 8333 typeName.staticType = type; | 8337 typeName.staticType = type; |
| 8334 node.type = type; | 8338 node.type = type; |
| 8335 } | 8339 } |
| 8336 | 8340 |
| 8337 /** | 8341 /** |
| 8338 * The number of type arguments in the given type name does not match the numb
er of parameters in | 8342 * The number of type arguments in the given [typeName] does not match the |
| 8339 * the corresponding class element. Return the error code that should be used
to report this | 8343 * number of parameters in the corresponding class element. Return the error |
| 8340 * error. | 8344 * code that should be used to report this error. |
| 8341 * | |
| 8342 * @param node the type name with the wrong number of type arguments | |
| 8343 * @return the error code that should be used to report that the wrong number
of type arguments | |
| 8344 * were provided | |
| 8345 */ | 8345 */ |
| 8346 ErrorCode _getInvalidTypeParametersErrorCode(TypeName node) { | 8346 ErrorCode _getInvalidTypeParametersErrorCode(TypeName typeName) { |
| 8347 AstNode parent = node.parent; | 8347 AstNode parent = typeName.parent; |
| 8348 if (parent is ConstructorName) { | 8348 if (parent is ConstructorName) { |
| 8349 parent = parent.parent; | 8349 parent = parent.parent; |
| 8350 if (parent is InstanceCreationExpression) { | 8350 if (parent is InstanceCreationExpression) { |
| 8351 if (parent.isConst) { | 8351 if (parent.isConst) { |
| 8352 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; | 8352 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; |
| 8353 } else { | 8353 } else { |
| 8354 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS; | 8354 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS; |
| 8355 } | 8355 } |
| 8356 } | 8356 } |
| 8357 } | 8357 } |
| 8358 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; | 8358 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; |
| 8359 } | 8359 } |
| 8360 | 8360 |
| 8361 /** | 8361 /** |
| 8362 * Checks if the given type name is the target in a redirected constructor. | 8362 * Checks if the given [typeName] is the target in a redirected constructor. |
| 8363 * | |
| 8364 * @param typeName the type name to analyze | |
| 8365 * @return some [RedirectingConstructorKind] if the given type name is used as
the type in a | |
| 8366 * redirected constructor, or `null` otherwise | |
| 8367 */ | 8363 */ |
| 8368 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) { | 8364 RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) { |
| 8369 AstNode parent = typeName.parent; | 8365 AstNode parent = typeName.parent; |
| 8370 if (parent is ConstructorName) { | 8366 if (parent is ConstructorName) { |
| 8371 AstNode grandParent = parent.parent; | 8367 AstNode grandParent = parent.parent; |
| 8372 if (grandParent is ConstructorDeclaration) { | 8368 if (grandParent is ConstructorDeclaration) { |
| 8373 if (identical(grandParent.redirectedConstructor, parent)) { | 8369 if (identical(grandParent.redirectedConstructor, parent)) { |
| 8374 if (grandParent.constKeyword != null) { | 8370 if (grandParent.constKeyword != null) { |
| 8375 return RedirectingConstructorKind.CONST; | 8371 return RedirectingConstructorKind.CONST; |
| 8376 } | 8372 } |
| 8377 return RedirectingConstructorKind.NORMAL; | 8373 return RedirectingConstructorKind.NORMAL; |
| 8378 } | 8374 } |
| 8379 } | 8375 } |
| 8380 } | 8376 } |
| 8381 return null; | 8377 return null; |
| 8382 } | 8378 } |
| 8383 | 8379 |
| 8384 /** | 8380 /** |
| 8385 * Return the type represented by the given type name. | 8381 * Return the type represented by the given type [annotation]. |
| 8386 * | |
| 8387 * @param typeName the type name representing the type to be returned | |
| 8388 * @return the type represented by the type name | |
| 8389 */ | 8382 */ |
| 8390 DartType _getType(TypeName typeName) { | 8383 DartType _getType(TypeAnnotation annotation) { |
| 8391 DartType type = typeName.type; | 8384 DartType type = annotation.type; |
| 8392 if (type == null) { | 8385 if (type == null) { |
| 8393 return undefinedType; | 8386 return undefinedType; |
| 8394 } | 8387 } |
| 8395 return type; | 8388 return type; |
| 8396 } | 8389 } |
| 8397 | 8390 |
| 8398 /** | 8391 /** |
| 8399 * Returns the simple identifier of the given (may be qualified) type name. | 8392 * Returns the simple identifier of the given (may be qualified) type name. |
| 8400 * | 8393 * |
| 8401 * @param typeName the (may be qualified) qualified type name | 8394 * @param typeName the (may be qualified) qualified type name |
| (...skipping 23 matching lines...) Expand all Loading... |
| 8425 if (type != null) { | 8418 if (type != null) { |
| 8426 return null; | 8419 return null; |
| 8427 } | 8420 } |
| 8428 type = element.type; | 8421 type = element.type; |
| 8429 } | 8422 } |
| 8430 } | 8423 } |
| 8431 return type; | 8424 return type; |
| 8432 } | 8425 } |
| 8433 | 8426 |
| 8434 /** | 8427 /** |
| 8435 * Checks if the given type name is used as the type in an as expression. | 8428 * Checks if the given [typeName] is used as the type in an as expression. |
| 8436 * | |
| 8437 * @param typeName the type name to analyzer | |
| 8438 * @return `true` if the given type name is used as the type in an as expressi
on | |
| 8439 */ | 8429 */ |
| 8440 bool _isTypeNameInAsExpression(TypeName typeName) { | 8430 bool _isTypeNameInAsExpression(TypeName typeName) { |
| 8441 AstNode parent = typeName.parent; | 8431 AstNode parent = typeName.parent; |
| 8442 if (parent is AsExpression) { | 8432 if (parent is AsExpression) { |
| 8443 return identical(parent.type, typeName); | 8433 return identical(parent.type, typeName); |
| 8444 } | 8434 } |
| 8445 return false; | 8435 return false; |
| 8446 } | 8436 } |
| 8447 | 8437 |
| 8448 /** | 8438 /** |
| 8449 * Checks if the given type name is used as the exception type in a catch clau
se. | 8439 * Checks if the given [typeName] is used as the exception type in a catch |
| 8450 * | 8440 * clause. |
| 8451 * @param typeName the type name to analyzer | |
| 8452 * @return `true` if the given type name is used as the exception type in a ca
tch clause | |
| 8453 */ | 8441 */ |
| 8454 bool _isTypeNameInCatchClause(TypeName typeName) { | 8442 bool _isTypeNameInCatchClause(TypeName typeName) { |
| 8455 AstNode parent = typeName.parent; | 8443 AstNode parent = typeName.parent; |
| 8456 if (parent is CatchClause) { | 8444 if (parent is CatchClause) { |
| 8457 return identical(parent.exceptionType, typeName); | 8445 return identical(parent.exceptionType, typeName); |
| 8458 } | 8446 } |
| 8459 return false; | 8447 return false; |
| 8460 } | 8448 } |
| 8461 | 8449 |
| 8462 /** | 8450 /** |
| 8463 * Checks if the given type name is used as the type in an instance creation e
xpression. | 8451 * Checks if the given [typeName] is used as the type in an instance creation |
| 8464 * | 8452 * expression. |
| 8465 * @param typeName the type name to analyzer | |
| 8466 * @return `true` if the given type name is used as the type in an instance cr
eation | |
| 8467 * expression | |
| 8468 */ | 8453 */ |
| 8469 bool _isTypeNameInInstanceCreationExpression(TypeName typeName) { | 8454 bool _isTypeNameInInstanceCreationExpression(TypeName typeName) { |
| 8470 AstNode parent = typeName.parent; | 8455 AstNode parent = typeName.parent; |
| 8471 if (parent is ConstructorName && | 8456 if (parent is ConstructorName && |
| 8472 parent.parent is InstanceCreationExpression) { | 8457 parent.parent is InstanceCreationExpression) { |
| 8473 return parent != null && identical(parent.type, typeName); | 8458 return parent != null && identical(parent.type, typeName); |
| 8474 } | 8459 } |
| 8475 return false; | 8460 return false; |
| 8476 } | 8461 } |
| 8477 | 8462 |
| 8478 /** | 8463 /** |
| 8479 * Checks if the given type name is used as the type in an is expression. | 8464 * Checks if the given [typeName] is used as the type in an is expression. |
| 8480 * | |
| 8481 * @param typeName the type name to analyzer | |
| 8482 * @return `true` if the given type name is used as the type in an is expressi
on | |
| 8483 */ | 8465 */ |
| 8484 bool _isTypeNameInIsExpression(TypeName typeName) { | 8466 bool _isTypeNameInIsExpression(TypeName typeName) { |
| 8485 AstNode parent = typeName.parent; | 8467 AstNode parent = typeName.parent; |
| 8486 if (parent is IsExpression) { | 8468 if (parent is IsExpression) { |
| 8487 return identical(parent.type, typeName); | 8469 return identical(parent.type, typeName); |
| 8488 } | 8470 } |
| 8489 return false; | 8471 return false; |
| 8490 } | 8472 } |
| 8491 | 8473 |
| 8492 /** | 8474 /** |
| 8493 * Checks if the given type name used in a type argument list. | 8475 * Checks if the given [typeName] used in a type argument list. |
| 8494 * | |
| 8495 * @param typeName the type name to analyzer | |
| 8496 * @return `true` if the given type name is in a type argument list | |
| 8497 */ | 8476 */ |
| 8498 bool _isTypeNameInTypeArgumentList(TypeName typeName) => | 8477 bool _isTypeNameInTypeArgumentList(TypeName typeName) => |
| 8499 typeName.parent is TypeArgumentList; | 8478 typeName.parent is TypeArgumentList; |
| 8500 | 8479 |
| 8501 /** | 8480 /** |
| 8502 * Records the new Element for a TypeName's Identifier. | 8481 * Records the new Element for a TypeName's Identifier. |
| 8503 * | 8482 * |
| 8504 * A null may be passed in to indicate that the element can't be resolved. | 8483 * A null may be passed in to indicate that the element can't be resolved. |
| 8505 * (During a re-run of a task, it's important to clear any previous value | 8484 * (During a re-run of a task, it's important to clear any previous value |
| 8506 * of the element.) | 8485 * of the element.) |
| 8507 */ | 8486 */ |
| 8508 void _setElement(Identifier typeName, Element element) { | 8487 void _setElement(Identifier typeName, Element element) { |
| 8509 if (typeName is SimpleIdentifier) { | 8488 if (typeName is SimpleIdentifier) { |
| 8510 typeName.staticElement = element; | 8489 typeName.staticElement = element; |
| 8511 } else if (typeName is PrefixedIdentifier) { | 8490 } else if (typeName is PrefixedIdentifier) { |
| 8512 typeName.identifier.staticElement = element; | 8491 typeName.identifier.staticElement = element; |
| 8513 SimpleIdentifier prefix = typeName.prefix; | 8492 SimpleIdentifier prefix = typeName.prefix; |
| 8514 prefix.staticElement = nameScope.lookup(prefix, definingLibrary); | 8493 prefix.staticElement = nameScope.lookup(prefix, definingLibrary); |
| 8515 } | 8494 } |
| 8516 } | 8495 } |
| 8517 | 8496 |
| 8518 /** | 8497 /** |
| 8519 * @return `true` if the name of the given [TypeName] is an built-in identifie
r. | 8498 * Return `true` if the name of the given [typeName] is an built-in identifier
. |
| 8520 */ | 8499 */ |
| 8521 static bool _isBuiltInIdentifier(TypeName node) { | 8500 static bool _isBuiltInIdentifier(TypeName typeName) { |
| 8522 Token token = node.name.beginToken; | 8501 Token token = typeName.name.beginToken; |
| 8523 return token.type == TokenType.KEYWORD; | 8502 return token.type == TokenType.KEYWORD; |
| 8524 } | 8503 } |
| 8525 | 8504 |
| 8526 /** | 8505 /** |
| 8527 * @return `true` if given [TypeName] is used as a type annotation. | 8506 * @return `true` if given [typeName] is used as a type annotation. |
| 8528 */ | 8507 */ |
| 8529 static bool _isTypeAnnotation(TypeName node) { | 8508 static bool _isTypeAnnotation(TypeName typeName) { |
| 8530 AstNode parent = node.parent; | 8509 AstNode parent = typeName.parent; |
| 8531 if (parent is VariableDeclarationList) { | 8510 if (parent is VariableDeclarationList) { |
| 8532 return identical(parent.type, node); | 8511 return identical(parent.type, typeName); |
| 8533 } else if (parent is FieldFormalParameter) { | 8512 } else if (parent is FieldFormalParameter) { |
| 8534 return identical(parent.type, node); | 8513 return identical(parent.type, typeName); |
| 8535 } else if (parent is SimpleFormalParameter) { | 8514 } else if (parent is SimpleFormalParameter) { |
| 8536 return identical(parent.type, node); | 8515 return identical(parent.type, typeName); |
| 8537 } | 8516 } |
| 8538 return false; | 8517 return false; |
| 8539 } | 8518 } |
| 8540 } | 8519 } |
| 8541 | 8520 |
| 8542 /** | 8521 /** |
| 8543 * Instances of the class `TypeOverrideManager` manage the ability to override t
he type of an | 8522 * Instances of the class `TypeOverrideManager` manage the ability to override t
he type of an |
| 8544 * element within a given context. | 8523 * element within a given context. |
| 8545 */ | 8524 */ |
| 8546 class TypeOverrideManager { | 8525 class TypeOverrideManager { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8794 } else if (unitMember is ClassTypeAlias) { | 8773 } else if (unitMember is ClassTypeAlias) { |
| 8795 _resolveTypeParameters(unitMember.typeParameters, | 8774 _resolveTypeParameters(unitMember.typeParameters, |
| 8796 () => new TypeParameterScope(libraryScope, unitMember.element)); | 8775 () => new TypeParameterScope(libraryScope, unitMember.element)); |
| 8797 } else if (unitMember is FunctionTypeAlias) { | 8776 } else if (unitMember is FunctionTypeAlias) { |
| 8798 _resolveTypeParameters(unitMember.typeParameters, | 8777 _resolveTypeParameters(unitMember.typeParameters, |
| 8799 () => new FunctionTypeScope(libraryScope, unitMember.element)); | 8778 () => new FunctionTypeScope(libraryScope, unitMember.element)); |
| 8800 } | 8779 } |
| 8801 } | 8780 } |
| 8802 } | 8781 } |
| 8803 | 8782 |
| 8804 void _resolveTypeName(TypeName typeName) { | 8783 void _resolveTypeName(TypeAnnotation type) { |
| 8805 typeName.typeArguments?.arguments?.forEach(_resolveTypeName); | 8784 if (type is TypeName) { |
| 8806 typeNameResolver.resolveTypeName(typeName); | 8785 type.typeArguments?.arguments?.forEach(_resolveTypeName); |
| 8807 // TODO(scheglov) report error when don't apply type bounds for type bounds | 8786 typeNameResolver.resolveTypeName(type); |
| 8787 // TODO(scheglov) report error when don't apply type bounds for type bound
s |
| 8788 } else { |
| 8789 // TODO(brianwilkerson) Add resolution of GenericFunctionType |
| 8790 throw new ArgumentError('Cannot resolve a ${type.runtimeType}'); |
| 8791 } |
| 8808 } | 8792 } |
| 8809 | 8793 |
| 8810 void _resolveTypeParameters( | 8794 void _resolveTypeParameters( |
| 8811 TypeParameterList typeParameters, Scope createTypeParametersScope()) { | 8795 TypeParameterList typeParameters, Scope createTypeParametersScope()) { |
| 8812 if (typeParameters != null) { | 8796 if (typeParameters != null) { |
| 8813 Scope typeParametersScope = null; | 8797 Scope typeParametersScope = null; |
| 8814 for (TypeParameter typeParameter in typeParameters.typeParameters) { | 8798 for (TypeParameter typeParameter in typeParameters.typeParameters) { |
| 8815 TypeName bound = typeParameter.bound; | 8799 TypeAnnotation bound = typeParameter.bound; |
| 8816 if (bound != null) { | 8800 if (bound != null) { |
| 8817 Element typeParameterElement = typeParameter.name.staticElement; | 8801 Element typeParameterElement = typeParameter.name.staticElement; |
| 8818 if (typeParameterElement is TypeParameterElementImpl) { | 8802 if (typeParameterElement is TypeParameterElementImpl) { |
| 8819 if (LibraryElementImpl.hasResolutionCapability( | 8803 if (LibraryElementImpl.hasResolutionCapability( |
| 8820 library, LibraryResolutionCapability.resolvedTypeNames)) { | 8804 library, LibraryResolutionCapability.resolvedTypeNames)) { |
| 8821 bound.type = typeParameterElement.bound; | 8805 if (bound is TypeName) { |
| 8806 bound.type = typeParameterElement.bound; |
| 8807 } else { |
| 8808 // TODO(brianwilkerson) Add resolution of GenericFunctionType |
| 8809 throw new ArgumentError( |
| 8810 'Cannot resolve a ${bound.runtimeType}'); |
| 8811 } |
| 8822 } else { | 8812 } else { |
| 8823 libraryScope ??= new LibraryScope(library); | 8813 libraryScope ??= new LibraryScope(library); |
| 8824 typeParametersScope ??= createTypeParametersScope(); | 8814 typeParametersScope ??= createTypeParametersScope(); |
| 8825 typeNameResolver ??= new TypeNameResolver(new TypeSystemImpl(), | 8815 typeNameResolver ??= new TypeNameResolver(new TypeSystemImpl(), |
| 8826 typeProvider, library, source, errorListener); | 8816 typeProvider, library, source, errorListener); |
| 8827 typeNameResolver.nameScope = typeParametersScope; | 8817 typeNameResolver.nameScope = typeParametersScope; |
| 8828 _resolveTypeName(bound); | 8818 _resolveTypeName(bound); |
| 8829 typeParameterElement.bound = bound.type; | 8819 typeParameterElement.bound = bound.type; |
| 8830 } | 8820 } |
| 8831 } | 8821 } |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9485 * True if we're analyzing in strong mode. | 9475 * True if we're analyzing in strong mode. |
| 9486 */ | 9476 */ |
| 9487 bool _strongMode; | 9477 bool _strongMode; |
| 9488 | 9478 |
| 9489 /** | 9479 /** |
| 9490 * Type type system in use for this resolver pass. | 9480 * Type type system in use for this resolver pass. |
| 9491 */ | 9481 */ |
| 9492 TypeSystem _typeSystem; | 9482 TypeSystem _typeSystem; |
| 9493 | 9483 |
| 9494 /** | 9484 /** |
| 9495 * The helper to resolve [TypeName]s. | 9485 * The helper to resolve types. |
| 9496 */ | 9486 */ |
| 9497 TypeNameResolver _typeNameResolver; | 9487 TypeNameResolver _typeNameResolver; |
| 9498 | 9488 |
| 9499 final TypeResolverMode mode; | 9489 final TypeResolverMode mode; |
| 9500 | 9490 |
| 9501 /** | 9491 /** |
| 9502 * Is `true` when we are visiting all nodes in [TypeResolverMode.local] mode. | 9492 * Is `true` when we are visiting all nodes in [TypeResolverMode.local] mode. |
| 9503 */ | 9493 */ |
| 9504 bool _localModeVisitAll = false; | 9494 bool _localModeVisitAll = false; |
| 9505 | 9495 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9567 } | 9557 } |
| 9568 | 9558 |
| 9569 @override | 9559 @override |
| 9570 Object visitCatchClause(CatchClause node) { | 9560 Object visitCatchClause(CatchClause node) { |
| 9571 super.visitCatchClause(node); | 9561 super.visitCatchClause(node); |
| 9572 SimpleIdentifier exception = node.exceptionParameter; | 9562 SimpleIdentifier exception = node.exceptionParameter; |
| 9573 if (exception != null) { | 9563 if (exception != null) { |
| 9574 // If an 'on' clause is provided the type of the exception parameter is | 9564 // If an 'on' clause is provided the type of the exception parameter is |
| 9575 // the type in the 'on' clause. Otherwise, the type of the exception | 9565 // the type in the 'on' clause. Otherwise, the type of the exception |
| 9576 // parameter is 'Object'. | 9566 // parameter is 'Object'. |
| 9577 TypeName exceptionTypeName = node.exceptionType; | 9567 TypeAnnotation exceptionTypeName = node.exceptionType; |
| 9578 DartType exceptionType; | 9568 DartType exceptionType; |
| 9579 if (exceptionTypeName == null) { | 9569 if (exceptionTypeName == null) { |
| 9580 exceptionType = typeProvider.dynamicType; | 9570 exceptionType = typeProvider.dynamicType; |
| 9581 } else { | 9571 } else { |
| 9582 exceptionType = _typeNameResolver._getType(exceptionTypeName); | 9572 exceptionType = _typeNameResolver._getType(exceptionTypeName); |
| 9583 } | 9573 } |
| 9584 _recordType(exception, exceptionType); | 9574 _recordType(exception, exceptionType); |
| 9585 Element element = exception.staticElement; | 9575 Element element = exception.staticElement; |
| 9586 if (element is VariableElementImpl) { | 9576 if (element is VariableElementImpl) { |
| 9587 element.declaredType = exceptionType; | 9577 element.declaredType = exceptionType; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9706 AnalysisEngine.instance.logger.logError(buffer.toString(), | 9696 AnalysisEngine.instance.logger.logError(buffer.toString(), |
| 9707 new CaughtException(new AnalysisException(), null)); | 9697 new CaughtException(new AnalysisException(), null)); |
| 9708 } | 9698 } |
| 9709 return null; | 9699 return null; |
| 9710 } | 9700 } |
| 9711 | 9701 |
| 9712 @override | 9702 @override |
| 9713 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 9703 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 9714 super.visitDeclaredIdentifier(node); | 9704 super.visitDeclaredIdentifier(node); |
| 9715 DartType declaredType; | 9705 DartType declaredType; |
| 9716 TypeName typeName = node.type; | 9706 TypeAnnotation typeName = node.type; |
| 9717 if (typeName == null) { | 9707 if (typeName == null) { |
| 9718 declaredType = _dynamicType; | 9708 declaredType = _dynamicType; |
| 9719 } else { | 9709 } else { |
| 9720 declaredType = _typeNameResolver._getType(typeName); | 9710 declaredType = _typeNameResolver._getType(typeName); |
| 9721 } | 9711 } |
| 9722 LocalVariableElementImpl element = node.element as LocalVariableElementImpl; | 9712 LocalVariableElementImpl element = node.element as LocalVariableElementImpl; |
| 9723 element.declaredType = declaredType; | 9713 element.declaredType = declaredType; |
| 9724 return null; | 9714 return null; |
| 9725 } | 9715 } |
| 9726 | 9716 |
| 9727 @override | 9717 @override |
| 9728 Object visitFieldFormalParameter(FieldFormalParameter node) { | 9718 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 9729 super.visitFieldFormalParameter(node); | 9719 super.visitFieldFormalParameter(node); |
| 9730 Element element = node.identifier.staticElement; | 9720 Element element = node.identifier.staticElement; |
| 9731 if (element is ParameterElementImpl) { | 9721 if (element is ParameterElementImpl) { |
| 9732 FormalParameterList parameterList = node.parameters; | 9722 FormalParameterList parameterList = node.parameters; |
| 9733 if (parameterList == null) { | 9723 if (parameterList == null) { |
| 9734 DartType type; | 9724 DartType type; |
| 9735 TypeName typeName = node.type; | 9725 TypeAnnotation typeName = node.type; |
| 9736 if (typeName == null) { | 9726 if (typeName == null) { |
| 9737 element.hasImplicitType = true; | 9727 element.hasImplicitType = true; |
| 9738 if (element is FieldFormalParameterElement) { | 9728 if (element is FieldFormalParameterElement) { |
| 9739 FieldElement fieldElement = | 9729 FieldElement fieldElement = |
| 9740 (element as FieldFormalParameterElement).field; | 9730 (element as FieldFormalParameterElement).field; |
| 9741 type = fieldElement?.type; | 9731 type = fieldElement?.type; |
| 9742 } | 9732 } |
| 9743 } else { | 9733 } else { |
| 9744 type = _typeNameResolver._getType(typeName); | 9734 type = _typeNameResolver._getType(typeName); |
| 9745 } | 9735 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9948 } | 9938 } |
| 9949 | 9939 |
| 9950 // The mode in which we visit all nodes. | 9940 // The mode in which we visit all nodes. |
| 9951 return super.visitNode(node); | 9941 return super.visitNode(node); |
| 9952 } | 9942 } |
| 9953 | 9943 |
| 9954 @override | 9944 @override |
| 9955 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 9945 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 9956 super.visitSimpleFormalParameter(node); | 9946 super.visitSimpleFormalParameter(node); |
| 9957 DartType declaredType; | 9947 DartType declaredType; |
| 9958 TypeName typeName = node.type; | 9948 TypeAnnotation typeName = node.type; |
| 9959 if (typeName == null) { | 9949 if (typeName == null) { |
| 9960 declaredType = _dynamicType; | 9950 declaredType = _dynamicType; |
| 9961 } else { | 9951 } else { |
| 9962 declaredType = _typeNameResolver._getType(typeName); | 9952 declaredType = _typeNameResolver._getType(typeName); |
| 9963 } | 9953 } |
| 9964 Element element = node.identifier.staticElement; | 9954 Element element = node.identifier.staticElement; |
| 9965 if (element is ParameterElementImpl) { | 9955 if (element is ParameterElementImpl) { |
| 9966 element.declaredType = declaredType; | 9956 element.declaredType = declaredType; |
| 9967 } else { | 9957 } else { |
| 9968 // TODO(brianwilkerson) Report the internal error. | 9958 // TODO(brianwilkerson) Report the internal error. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 9987 @override | 9977 @override |
| 9988 Object visitTypeParameter(TypeParameter node) { | 9978 Object visitTypeParameter(TypeParameter node) { |
| 9989 super.visitTypeParameter(node); | 9979 super.visitTypeParameter(node); |
| 9990 AstNode parent2 = node.parent?.parent; | 9980 AstNode parent2 = node.parent?.parent; |
| 9991 if (parent2 is ClassDeclaration || | 9981 if (parent2 is ClassDeclaration || |
| 9992 parent2 is ClassTypeAlias || | 9982 parent2 is ClassTypeAlias || |
| 9993 parent2 is FunctionTypeAlias) { | 9983 parent2 is FunctionTypeAlias) { |
| 9994 // Bounds of parameters of classes and function type aliases are | 9984 // Bounds of parameters of classes and function type aliases are |
| 9995 // already resolved. | 9985 // already resolved. |
| 9996 } else { | 9986 } else { |
| 9997 TypeName bound = node.bound; | 9987 TypeAnnotation bound = node.bound; |
| 9998 if (bound != null) { | 9988 if (bound != null) { |
| 9999 TypeParameterElementImpl typeParameter = | 9989 TypeParameterElementImpl typeParameter = |
| 10000 node.name.staticElement as TypeParameterElementImpl; | 9990 node.name.staticElement as TypeParameterElementImpl; |
| 10001 if (typeParameter != null) { | 9991 if (typeParameter != null) { |
| 10002 typeParameter.bound = bound.type; | 9992 typeParameter.bound = bound.type; |
| 10003 } | 9993 } |
| 10004 } | 9994 } |
| 10005 } | 9995 } |
| 10006 return null; | 9996 return null; |
| 10007 } | 9997 } |
| 10008 | 9998 |
| 10009 @override | 9999 @override |
| 10010 Object visitVariableDeclaration(VariableDeclaration node) { | 10000 Object visitVariableDeclaration(VariableDeclaration node) { |
| 10011 super.visitVariableDeclaration(node); | 10001 super.visitVariableDeclaration(node); |
| 10012 var variableList = node.parent as VariableDeclarationList; | 10002 var variableList = node.parent as VariableDeclarationList; |
| 10013 // When the library is resynthesized, the types of field elements are | 10003 // When the library is resynthesized, the types of field elements are |
| 10014 // already set - statically or inferred. We don't want to overwrite them. | 10004 // already set - statically or inferred. We don't want to overwrite them. |
| 10015 if (variableList.parent is FieldDeclaration && | 10005 if (variableList.parent is FieldDeclaration && |
| 10016 LibraryElementImpl.hasResolutionCapability( | 10006 LibraryElementImpl.hasResolutionCapability( |
| 10017 definingLibrary, LibraryResolutionCapability.resolvedTypeNames)) { | 10007 definingLibrary, LibraryResolutionCapability.resolvedTypeNames)) { |
| 10018 return null; | 10008 return null; |
| 10019 } | 10009 } |
| 10020 // Resolve the type. | 10010 // Resolve the type. |
| 10021 DartType declaredType; | 10011 DartType declaredType; |
| 10022 TypeName typeName = variableList.type; | 10012 TypeAnnotation typeName = variableList.type; |
| 10023 if (typeName == null) { | 10013 if (typeName == null) { |
| 10024 declaredType = _dynamicType; | 10014 declaredType = _dynamicType; |
| 10025 } else { | 10015 } else { |
| 10026 declaredType = _typeNameResolver._getType(typeName); | 10016 declaredType = _typeNameResolver._getType(typeName); |
| 10027 } | 10017 } |
| 10028 Element element = node.name.staticElement; | 10018 Element element = node.name.staticElement; |
| 10029 if (element is VariableElementImpl) { | 10019 if (element is VariableElementImpl) { |
| 10030 element.declaredType = declaredType; | 10020 element.declaredType = declaredType; |
| 10031 } | 10021 } |
| 10032 return null; | 10022 return null; |
| 10033 } | 10023 } |
| 10034 | 10024 |
| 10035 /** | 10025 /** |
| 10036 * Given a type name representing the return type of a function, compute the r
eturn type of the | 10026 * Given the [returnType] of a function, compute the return type of the |
| 10037 * function. | 10027 * function. |
| 10038 * | |
| 10039 * @param returnType the type name representing the return type of the functio
n | |
| 10040 * @return the return type that was computed | |
| 10041 */ | 10028 */ |
| 10042 DartType _computeReturnType(TypeName returnType) { | 10029 DartType _computeReturnType(TypeAnnotation returnType) { |
| 10043 if (returnType == null) { | 10030 if (returnType == null) { |
| 10044 return _dynamicType; | 10031 return _dynamicType; |
| 10045 } else { | 10032 } else { |
| 10046 return returnType.type; | 10033 return returnType.type; |
| 10047 } | 10034 } |
| 10048 } | 10035 } |
| 10049 | 10036 |
| 10050 /** | 10037 /** |
| 10051 * Return the class element that represents the class whose name was provided. | 10038 * Return the class element that represents the class whose name was provided. |
| 10052 * | 10039 * |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10114 Object _recordType(Expression expression, DartType type) { | 10101 Object _recordType(Expression expression, DartType type) { |
| 10115 if (type == null) { | 10102 if (type == null) { |
| 10116 expression.staticType = _dynamicType; | 10103 expression.staticType = _dynamicType; |
| 10117 } else { | 10104 } else { |
| 10118 expression.staticType = type; | 10105 expression.staticType = type; |
| 10119 } | 10106 } |
| 10120 return null; | 10107 return null; |
| 10121 } | 10108 } |
| 10122 | 10109 |
| 10123 /** | 10110 /** |
| 10124 * Resolve the types in the given with and implements clauses and associate th
ose types with the | 10111 * Resolve the types in the given [withClause] and [implementsClause] and |
| 10125 * given class element. | 10112 * associate those types with the given [classElement]. |
| 10126 * | |
| 10127 * @param classElement the class element with which the mixin and interface ty
pes are to be | |
| 10128 * associated | |
| 10129 * @param withClause the with clause to be resolved | |
| 10130 * @param implementsClause the implements clause to be resolved | |
| 10131 */ | 10113 */ |
| 10132 void _resolve(ClassElementImpl classElement, WithClause withClause, | 10114 void _resolve(ClassElementImpl classElement, WithClause withClause, |
| 10133 ImplementsClause implementsClause) { | 10115 ImplementsClause implementsClause) { |
| 10134 if (withClause != null) { | 10116 if (withClause != null) { |
| 10135 List<InterfaceType> mixinTypes = _resolveTypes( | 10117 List<InterfaceType> mixinTypes = _resolveTypes( |
| 10136 withClause.mixinTypes, | 10118 withClause.mixinTypes, |
| 10137 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, | 10119 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, |
| 10138 CompileTimeErrorCode.MIXIN_OF_ENUM, | 10120 CompileTimeErrorCode.MIXIN_OF_ENUM, |
| 10139 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); | 10121 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); |
| 10140 if (classElement != null) { | 10122 if (classElement != null) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10229 InterfaceType type = | 10211 InterfaceType type = |
| 10230 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); | 10212 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); |
| 10231 if (type != null) { | 10213 if (type != null) { |
| 10232 types.add(type); | 10214 types.add(type); |
| 10233 } | 10215 } |
| 10234 } | 10216 } |
| 10235 return types; | 10217 return types; |
| 10236 } | 10218 } |
| 10237 | 10219 |
| 10238 /** | 10220 /** |
| 10239 * Given a parameter element, create a function type based on the given return
type and parameter | 10221 * Given a parameter [element], create a function type based on the given |
| 10240 * list and associate the created type with the element. | 10222 * [returnType] and [parameterList] and associate the created type with the |
| 10241 * | 10223 * element. |
| 10242 * @param element the parameter element whose type is to be set | |
| 10243 * @param returnType the (possibly `null`) return type of the function | |
| 10244 * @param parameterList the list of parameters to the function | |
| 10245 */ | 10224 */ |
| 10246 void _setFunctionTypedParameterType(ParameterElementImpl element, | 10225 void _setFunctionTypedParameterType(ParameterElementImpl element, |
| 10247 TypeName returnType, FormalParameterList parameterList) { | 10226 TypeAnnotation returnType, FormalParameterList parameterList) { |
| 10248 List<ParameterElement> parameters = _getElements(parameterList); | 10227 List<ParameterElement> parameters = _getElements(parameterList); |
| 10249 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(null); | 10228 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(null); |
| 10250 functionElement.isSynthetic = true; | 10229 functionElement.isSynthetic = true; |
| 10251 functionElement.shareParameters(parameters); | 10230 functionElement.shareParameters(parameters); |
| 10252 functionElement.declaredReturnType = _computeReturnType(returnType); | 10231 functionElement.declaredReturnType = _computeReturnType(returnType); |
| 10253 functionElement.enclosingElement = element; | 10232 functionElement.enclosingElement = element; |
| 10254 functionElement.shareTypeParameters(element.typeParameters); | 10233 functionElement.shareTypeParameters(element.typeParameters); |
| 10255 element.type = new FunctionTypeImpl(functionElement); | 10234 element.type = new FunctionTypeImpl(functionElement); |
| 10256 functionElement.type = element.type; | 10235 functionElement.type = element.type; |
| 10257 } | 10236 } |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10795 return null; | 10774 return null; |
| 10796 } | 10775 } |
| 10797 if (identical(node.staticElement, variable)) { | 10776 if (identical(node.staticElement, variable)) { |
| 10798 if (node.inSetterContext()) { | 10777 if (node.inSetterContext()) { |
| 10799 result = true; | 10778 result = true; |
| 10800 } | 10779 } |
| 10801 } | 10780 } |
| 10802 return null; | 10781 return null; |
| 10803 } | 10782 } |
| 10804 } | 10783 } |
| OLD | NEW |