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