| 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 * | 286 * |
| 287 * @param expression the expression to evaluate | 287 * @param expression the expression to evaluate |
| 288 * @param expectedStaticType the expected static type of the parameter | 288 * @param expectedStaticType the expected static type of the parameter |
| 289 * @param actualStaticType the actual static type of the argument | 289 * @param actualStaticType the actual static type of the argument |
| 290 * @param expectedPropagatedType the expected propagated type of the parameter
, may be | 290 * @param expectedPropagatedType the expected propagated type of the parameter
, may be |
| 291 * `null` | 291 * `null` |
| 292 * @param actualPropagatedType the expected propagated type of the parameter,
may be `null` | 292 * @param actualPropagatedType the expected propagated type of the parameter,
may be `null` |
| 293 * @return `true` if and only if an hint code is generated on the passed node | 293 * @return `true` if and only if an hint code is generated on the passed node |
| 294 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 294 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
| 295 */ | 295 */ |
| 296 bool _checkForArgumentTypeNotAssignable(Expression expression, | 296 bool _checkForArgumentTypeNotAssignable( |
| 297 DartType expectedStaticType, DartType actualStaticType, | 297 Expression expression, |
| 298 DartType expectedPropagatedType, DartType actualPropagatedType, | 298 DartType expectedStaticType, |
| 299 DartType actualStaticType, |
| 300 DartType expectedPropagatedType, |
| 301 DartType actualPropagatedType, |
| 299 ErrorCode hintCode) { | 302 ErrorCode hintCode) { |
| 300 // | 303 // |
| 301 // Warning case: test static type information | 304 // Warning case: test static type information |
| 302 // | 305 // |
| 303 if (actualStaticType != null && expectedStaticType != null) { | 306 if (actualStaticType != null && expectedStaticType != null) { |
| 304 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 307 if (!actualStaticType.isAssignableTo(expectedStaticType)) { |
| 305 // A warning was created in the ErrorVerifier, return false, don't | 308 // A warning was created in the ErrorVerifier, return false, don't |
| 306 // create a hint when a warning has already been created. | 309 // create a hint when a warning has already been created. |
| 307 return false; | 310 return false; |
| 308 } | 311 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 return false; | 343 return false; |
| 341 } | 344 } |
| 342 ParameterElement staticParameterElement = argument.staticParameterElement; | 345 ParameterElement staticParameterElement = argument.staticParameterElement; |
| 343 DartType staticParameterType = | 346 DartType staticParameterType = |
| 344 staticParameterElement == null ? null : staticParameterElement.type; | 347 staticParameterElement == null ? null : staticParameterElement.type; |
| 345 ParameterElement propagatedParameterElement = | 348 ParameterElement propagatedParameterElement = |
| 346 argument.propagatedParameterElement; | 349 argument.propagatedParameterElement; |
| 347 DartType propagatedParameterType = propagatedParameterElement == null | 350 DartType propagatedParameterType = propagatedParameterElement == null |
| 348 ? null | 351 ? null |
| 349 : propagatedParameterElement.type; | 352 : propagatedParameterElement.type; |
| 350 return _checkForArgumentTypeNotAssignableWithExpectedTypes(argument, | 353 return _checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 351 staticParameterType, propagatedParameterType, | 354 argument, |
| 355 staticParameterType, |
| 356 propagatedParameterType, |
| 352 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); | 357 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); |
| 353 } | 358 } |
| 354 | 359 |
| 355 /** | 360 /** |
| 356 * This verifies that the passed expression can be assigned to its correspondi
ng parameters. | 361 * This verifies that the passed expression can be assigned to its correspondi
ng parameters. |
| 357 * | 362 * |
| 358 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableWithE
xpectedTypes. | 363 * This method corresponds to ErrorCode.checkForArgumentTypeNotAssignableWithE
xpectedTypes. |
| 359 * | 364 * |
| 360 * @param expression the expression to evaluate | 365 * @param expression the expression to evaluate |
| 361 * @param expectedStaticType the expected static type | 366 * @param expectedStaticType the expected static type |
| 362 * @param expectedPropagatedType the expected propagated type, may be `null` | 367 * @param expectedPropagatedType the expected propagated type, may be `null` |
| 363 * @return `true` if and only if an hint code is generated on the passed node | 368 * @return `true` if and only if an hint code is generated on the passed node |
| 364 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 369 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
| 365 */ | 370 */ |
| 366 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( | 371 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 367 Expression expression, DartType expectedStaticType, | 372 Expression expression, |
| 368 DartType expectedPropagatedType, ErrorCode errorCode) => | 373 DartType expectedStaticType, |
| 369 _checkForArgumentTypeNotAssignable(expression, expectedStaticType, | 374 DartType expectedPropagatedType, |
| 370 expression.staticType, expectedPropagatedType, | 375 ErrorCode errorCode) => |
| 371 expression.propagatedType, errorCode); | 376 _checkForArgumentTypeNotAssignable( |
| 377 expression, |
| 378 expectedStaticType, |
| 379 expression.staticType, |
| 380 expectedPropagatedType, |
| 381 expression.propagatedType, |
| 382 errorCode); |
| 372 | 383 |
| 373 /** | 384 /** |
| 374 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. | 385 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. |
| 375 * | 386 * |
| 376 * This method corresponds to ErrorCode.checkForArgumentTypesNotAssignableInLi
st. | 387 * This method corresponds to ErrorCode.checkForArgumentTypesNotAssignableInLi
st. |
| 377 * | 388 * |
| 378 * @param node the arguments to evaluate | 389 * @param node the arguments to evaluate |
| 379 * @return `true` if and only if an hint code is generated on the passed node | 390 * @return `true` if and only if an hint code is generated on the passed node |
| 380 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 391 * See [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
| 381 */ | 392 */ |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. | 545 * See [CompileTimeErrorCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]. |
| 535 */ | 546 */ |
| 536 bool _checkForLoadLibraryFunction( | 547 bool _checkForLoadLibraryFunction( |
| 537 ImportDirective node, ImportElement importElement) { | 548 ImportDirective node, ImportElement importElement) { |
| 538 LibraryElement importedLibrary = importElement.importedLibrary; | 549 LibraryElement importedLibrary = importElement.importedLibrary; |
| 539 if (importedLibrary == null) { | 550 if (importedLibrary == null) { |
| 540 return false; | 551 return false; |
| 541 } | 552 } |
| 542 if (importedLibrary.hasLoadLibraryFunction) { | 553 if (importedLibrary.hasLoadLibraryFunction) { |
| 543 _errorReporter.reportErrorForNode( | 554 _errorReporter.reportErrorForNode( |
| 544 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, node, | 555 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION, |
| 556 node, |
| 545 [importedLibrary.name]); | 557 [importedLibrary.name]); |
| 546 return true; | 558 return true; |
| 547 } | 559 } |
| 548 return false; | 560 return false; |
| 549 } | 561 } |
| 550 | 562 |
| 551 /** | 563 /** |
| 552 * Generate a hint for functions or methods that have a return type, but do no
t have a return | 564 * Generate a hint for functions or methods that have a return type, but do no
t have a return |
| 553 * statement on all branches. At the end of blocks with no return, Dart implic
itly returns | 565 * statement on all branches. At the end of blocks with no return, Dart implic
itly returns |
| 554 * `null`, avoiding these implicit returns is considered a best practice. | 566 * `null`, avoiding these implicit returns is considered a best practice. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 if (typeElement == null) { | 745 if (typeElement == null) { |
| 734 throw new IllegalArgumentException("class element cannot be null"); | 746 throw new IllegalArgumentException("class element cannot be null"); |
| 735 } | 747 } |
| 736 _defineMembers(typeElement); | 748 _defineMembers(typeElement); |
| 737 } | 749 } |
| 738 | 750 |
| 739 @override | 751 @override |
| 740 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 752 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
| 741 if (existing is PropertyAccessorElement && duplicate is MethodElement) { | 753 if (existing is PropertyAccessorElement && duplicate is MethodElement) { |
| 742 if (existing.nameOffset < duplicate.nameOffset) { | 754 if (existing.nameOffset < duplicate.nameOffset) { |
| 743 return new AnalysisError(duplicate.source, duplicate.nameOffset, | 755 return new AnalysisError( |
| 756 duplicate.source, |
| 757 duplicate.nameOffset, |
| 744 duplicate.displayName.length, | 758 duplicate.displayName.length, |
| 745 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, | 759 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, |
| 746 [existing.displayName]); | 760 [existing.displayName]); |
| 747 } else { | 761 } else { |
| 748 return new AnalysisError(existing.source, existing.nameOffset, | 762 return new AnalysisError( |
| 763 existing.source, |
| 764 existing.nameOffset, |
| 749 existing.displayName.length, | 765 existing.displayName.length, |
| 750 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, | 766 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, |
| 751 [existing.displayName]); | 767 [existing.displayName]); |
| 752 } | 768 } |
| 753 } | 769 } |
| 754 return super.getErrorForDuplicate(existing, duplicate); | 770 return super.getErrorForDuplicate(existing, duplicate); |
| 755 } | 771 } |
| 756 | 772 |
| 757 /** | 773 /** |
| 758 * Define the instance members defined by the class. | 774 * Define the instance members defined by the class. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 928 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 913 if (node.isConst) { | 929 if (node.isConst) { |
| 914 // We need to evaluate the constant to see if any errors occur during its | 930 // We need to evaluate the constant to see if any errors occur during its |
| 915 // evaluation. | 931 // evaluation. |
| 916 ConstructorElement constructor = node.staticElement; | 932 ConstructorElement constructor = node.staticElement; |
| 917 if (constructor != null) { | 933 if (constructor != null) { |
| 918 ConstantEvaluationEngine evaluationEngine = | 934 ConstantEvaluationEngine evaluationEngine = |
| 919 new ConstantEvaluationEngine(_typeProvider, declaredVariables); | 935 new ConstantEvaluationEngine(_typeProvider, declaredVariables); |
| 920 ConstantVisitor constantVisitor = | 936 ConstantVisitor constantVisitor = |
| 921 new ConstantVisitor(evaluationEngine, _errorReporter); | 937 new ConstantVisitor(evaluationEngine, _errorReporter); |
| 922 evaluationEngine.evaluateConstructorCall(node, | 938 evaluationEngine.evaluateConstructorCall( |
| 923 node.argumentList.arguments, constructor, constantVisitor, | 939 node, |
| 940 node.argumentList.arguments, |
| 941 constructor, |
| 942 constantVisitor, |
| 924 _errorReporter); | 943 _errorReporter); |
| 925 } | 944 } |
| 926 } | 945 } |
| 927 _validateInstanceCreationArguments(node); | 946 _validateInstanceCreationArguments(node); |
| 928 return super.visitInstanceCreationExpression(node); | 947 return super.visitInstanceCreationExpression(node); |
| 929 } | 948 } |
| 930 | 949 |
| 931 @override | 950 @override |
| 932 Object visitListLiteral(ListLiteral node) { | 951 Object visitListLiteral(ListLiteral node) { |
| 933 super.visitListLiteral(node); | 952 super.visitListLiteral(node); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY); | 988 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY); |
| 970 if (keys.contains(keyResult)) { | 989 if (keys.contains(keyResult)) { |
| 971 invalidKeys.add(key); | 990 invalidKeys.add(key); |
| 972 } else { | 991 } else { |
| 973 keys.add(keyResult); | 992 keys.add(keyResult); |
| 974 } | 993 } |
| 975 DartType type = keyResult.type; | 994 DartType type = keyResult.type; |
| 976 if (_implementsEqualsWhenNotAllowed(type)) { | 995 if (_implementsEqualsWhenNotAllowed(type)) { |
| 977 _errorReporter.reportErrorForNode( | 996 _errorReporter.reportErrorForNode( |
| 978 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ
UALS, | 997 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQ
UALS, |
| 979 key, [type.displayName]); | 998 key, |
| 999 [type.displayName]); |
| 980 } | 1000 } |
| 981 } | 1001 } |
| 982 } else { | 1002 } else { |
| 983 // Note: we throw the errors away because this isn't actually a const. | 1003 // Note: we throw the errors away because this isn't actually a const. |
| 984 AnalysisErrorListener errorListener = | 1004 AnalysisErrorListener errorListener = |
| 985 AnalysisErrorListener.NULL_LISTENER; | 1005 AnalysisErrorListener.NULL_LISTENER; |
| 986 ErrorReporter subErrorReporter = | 1006 ErrorReporter subErrorReporter = |
| 987 new ErrorReporter(errorListener, _errorReporter.source); | 1007 new ErrorReporter(errorListener, _errorReporter.source); |
| 988 DartObjectImpl result = key.accept(new ConstantVisitor( | 1008 DartObjectImpl result = key.accept(new ConstantVisitor( |
| 989 new ConstantEvaluationEngine(_typeProvider, declaredVariables), | 1009 new ConstantEvaluationEngine(_typeProvider, declaredVariables), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 _reportErrorIfFromDeferredLibrary(expression, | 1053 _reportErrorIfFromDeferredLibrary(expression, |
| 1034 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LI
BRARY); | 1054 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LI
BRARY); |
| 1035 DartObject value = caseResult; | 1055 DartObject value = caseResult; |
| 1036 if (firstType == null) { | 1056 if (firstType == null) { |
| 1037 firstType = value.type; | 1057 firstType = value.type; |
| 1038 } else { | 1058 } else { |
| 1039 DartType nType = value.type; | 1059 DartType nType = value.type; |
| 1040 if (firstType != nType) { | 1060 if (firstType != nType) { |
| 1041 _errorReporter.reportErrorForNode( | 1061 _errorReporter.reportErrorForNode( |
| 1042 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, | 1062 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
| 1043 expression, [expression.toSource(), firstType.displayName]); | 1063 expression, |
| 1064 [expression.toSource(), firstType.displayName]); |
| 1044 foundError = true; | 1065 foundError = true; |
| 1045 } | 1066 } |
| 1046 } | 1067 } |
| 1047 } | 1068 } |
| 1048 } | 1069 } |
| 1049 } | 1070 } |
| 1050 if (!foundError) { | 1071 if (!foundError) { |
| 1051 _checkForCaseExpressionTypeImplementsEquals(node, firstType); | 1072 _checkForCaseExpressionTypeImplementsEquals(node, firstType); |
| 1052 } | 1073 } |
| 1053 return super.visitSwitchStatement(node); | 1074 return super.visitSwitchStatement(node); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 * See [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]. | 1107 * See [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]. |
| 1087 */ | 1108 */ |
| 1088 bool _checkForCaseExpressionTypeImplementsEquals( | 1109 bool _checkForCaseExpressionTypeImplementsEquals( |
| 1089 SwitchStatement node, DartType type) { | 1110 SwitchStatement node, DartType type) { |
| 1090 if (!_implementsEqualsWhenNotAllowed(type)) { | 1111 if (!_implementsEqualsWhenNotAllowed(type)) { |
| 1091 return false; | 1112 return false; |
| 1092 } | 1113 } |
| 1093 // report error | 1114 // report error |
| 1094 _errorReporter.reportErrorForToken( | 1115 _errorReporter.reportErrorForToken( |
| 1095 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, | 1116 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, |
| 1096 node.switchKeyword, [type.displayName]); | 1117 node.switchKeyword, |
| 1118 [type.displayName]); |
| 1097 return true; | 1119 return true; |
| 1098 } | 1120 } |
| 1099 | 1121 |
| 1100 /** | 1122 /** |
| 1101 * @return `true` if given [Type] implements operator <i>==</i>, and it is not | 1123 * @return `true` if given [Type] implements operator <i>==</i>, and it is not |
| 1102 * <i>int</i> or <i>String</i>. | 1124 * <i>int</i> or <i>String</i>. |
| 1103 */ | 1125 */ |
| 1104 bool _implementsEqualsWhenNotAllowed(DartType type) { | 1126 bool _implementsEqualsWhenNotAllowed(DartType type) { |
| 1105 // ignore int or String | 1127 // ignore int or String |
| 1106 if (type == null || type == _intType || type == _typeProvider.stringType) { | 1128 if (type == null || type == _intType || type == _typeProvider.stringType) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 Expression initializer = variableDeclaration.initializer; | 1314 Expression initializer = variableDeclaration.initializer; |
| 1293 if (initializer != null) { | 1315 if (initializer != null) { |
| 1294 // Ignore any errors produced during validation--if the constant | 1316 // Ignore any errors produced during validation--if the constant |
| 1295 // can't be eavluated we'll just report a single error. | 1317 // can't be eavluated we'll just report a single error. |
| 1296 AnalysisErrorListener errorListener = | 1318 AnalysisErrorListener errorListener = |
| 1297 AnalysisErrorListener.NULL_LISTENER; | 1319 AnalysisErrorListener.NULL_LISTENER; |
| 1298 ErrorReporter subErrorReporter = | 1320 ErrorReporter subErrorReporter = |
| 1299 new ErrorReporter(errorListener, _errorReporter.source); | 1321 new ErrorReporter(errorListener, _errorReporter.source); |
| 1300 DartObjectImpl result = initializer.accept(new ConstantVisitor( | 1322 DartObjectImpl result = initializer.accept(new ConstantVisitor( |
| 1301 new ConstantEvaluationEngine( | 1323 new ConstantEvaluationEngine( |
| 1302 _typeProvider, declaredVariables), subErrorReporter)); | 1324 _typeProvider, declaredVariables), |
| 1325 subErrorReporter)); |
| 1303 if (result == null) { | 1326 if (result == null) { |
| 1304 _errorReporter.reportErrorForNode( | 1327 _errorReporter.reportErrorForNode( |
| 1305 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE
D_BY_NON_CONST, | 1328 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE
D_BY_NON_CONST, |
| 1306 errorSite, [variableDeclaration.name.name]); | 1329 errorSite, |
| 1330 [variableDeclaration.name.name]); |
| 1307 } | 1331 } |
| 1308 } | 1332 } |
| 1309 } | 1333 } |
| 1310 } | 1334 } |
| 1311 } | 1335 } |
| 1312 } | 1336 } |
| 1313 } | 1337 } |
| 1314 | 1338 |
| 1315 /** | 1339 /** |
| 1316 * Validates that the given expression is a compile time constant. | 1340 * Validates that the given expression is a compile time constant. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length); | 1642 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length); |
| 1619 return null; | 1643 return null; |
| 1620 } | 1644 } |
| 1621 } | 1645 } |
| 1622 for (DartType type in visitedTypes) { | 1646 for (DartType type in visitedTypes) { |
| 1623 if (currentType.isSubtypeOf(type)) { | 1647 if (currentType.isSubtypeOf(type)) { |
| 1624 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 1648 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 1625 int offset = catchClause.offset; | 1649 int offset = catchClause.offset; |
| 1626 int length = lastCatchClause.end - offset; | 1650 int length = lastCatchClause.end - offset; |
| 1627 _errorReporter.reportErrorForOffset( | 1651 _errorReporter.reportErrorForOffset( |
| 1628 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, offset, length, [ | 1652 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, |
| 1629 currentType.displayName, | 1653 offset, |
| 1630 type.displayName | 1654 length, |
| 1631 ]); | 1655 [currentType.displayName, type.displayName]); |
| 1632 return null; | 1656 return null; |
| 1633 } | 1657 } |
| 1634 } | 1658 } |
| 1635 visitedTypes.add(currentType); | 1659 visitedTypes.add(currentType); |
| 1636 } | 1660 } |
| 1637 _safelyVisit(catchClause); | 1661 _safelyVisit(catchClause); |
| 1638 } else { | 1662 } else { |
| 1639 // Found catch clause clause that doesn't have an exception type, | 1663 // Found catch clause clause that doesn't have an exception type, |
| 1640 // visit the block, but generate an error on any following catch clauses | 1664 // visit the block, but generate an error on any following catch clauses |
| 1641 // (and don't visit them). | 1665 // (and don't visit them). |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 _findIdentifier(constants, constant.name); | 1942 _findIdentifier(constants, constant.name); |
| 1919 } | 1943 } |
| 1920 return super.visitEnumDeclaration(node); | 1944 return super.visitEnumDeclaration(node); |
| 1921 } | 1945 } |
| 1922 | 1946 |
| 1923 @override | 1947 @override |
| 1924 Object visitExportDirective(ExportDirective node) { | 1948 Object visitExportDirective(ExportDirective node) { |
| 1925 String uri = _getStringValue(node.uri); | 1949 String uri = _getStringValue(node.uri); |
| 1926 if (uri != null) { | 1950 if (uri != null) { |
| 1927 LibraryElement library = _enclosingUnit.library; | 1951 LibraryElement library = _enclosingUnit.library; |
| 1928 ExportElement exportElement = _findExport(library.exports, | 1952 ExportElement exportElement = _findExport( |
| 1929 _enclosingUnit.context.sourceFactory.resolveUri( | 1953 library.exports, |
| 1930 _enclosingUnit.source, uri)); | 1954 _enclosingUnit.context.sourceFactory |
| 1955 .resolveUri(_enclosingUnit.source, uri)); |
| 1931 node.element = exportElement; | 1956 node.element = exportElement; |
| 1932 } | 1957 } |
| 1933 return super.visitExportDirective(node); | 1958 return super.visitExportDirective(node); |
| 1934 } | 1959 } |
| 1935 | 1960 |
| 1936 @override | 1961 @override |
| 1937 Object visitFieldFormalParameter(FieldFormalParameter node) { | 1962 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 1938 if (node.parent is! DefaultFormalParameter) { | 1963 if (node.parent is! DefaultFormalParameter) { |
| 1939 SimpleIdentifier parameterName = node.identifier; | 1964 SimpleIdentifier parameterName = node.identifier; |
| 1940 ParameterElement element = _getElementForParameter(node, parameterName); | 1965 ParameterElement element = _getElementForParameter(node, parameterName); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 } else { | 2049 } else { |
| 2025 return super.visitFunctionTypedFormalParameter(node); | 2050 return super.visitFunctionTypedFormalParameter(node); |
| 2026 } | 2051 } |
| 2027 } | 2052 } |
| 2028 | 2053 |
| 2029 @override | 2054 @override |
| 2030 Object visitImportDirective(ImportDirective node) { | 2055 Object visitImportDirective(ImportDirective node) { |
| 2031 String uri = _getStringValue(node.uri); | 2056 String uri = _getStringValue(node.uri); |
| 2032 if (uri != null) { | 2057 if (uri != null) { |
| 2033 LibraryElement library = _enclosingUnit.library; | 2058 LibraryElement library = _enclosingUnit.library; |
| 2034 ImportElement importElement = _findImport(library.imports, | 2059 ImportElement importElement = _findImport( |
| 2035 _enclosingUnit.context.sourceFactory.resolveUri( | 2060 library.imports, |
| 2036 _enclosingUnit.source, uri), node.prefix); | 2061 _enclosingUnit.context.sourceFactory |
| 2062 .resolveUri(_enclosingUnit.source, uri), |
| 2063 node.prefix); |
| 2037 node.element = importElement; | 2064 node.element = importElement; |
| 2038 } | 2065 } |
| 2039 return super.visitImportDirective(node); | 2066 return super.visitImportDirective(node); |
| 2040 } | 2067 } |
| 2041 | 2068 |
| 2042 @override | 2069 @override |
| 2043 Object visitLabeledStatement(LabeledStatement node) { | 2070 Object visitLabeledStatement(LabeledStatement node) { |
| 2044 for (Label label in node.labels) { | 2071 for (Label label in node.labels) { |
| 2045 SimpleIdentifier labelName = label.label; | 2072 SimpleIdentifier labelName = label.label; |
| 2046 _findIdentifier(_enclosingExecutable.labels, labelName); | 2073 _findIdentifier(_enclosingExecutable.labels, labelName); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2077 return super.visitMethodDeclaration(node); | 2104 return super.visitMethodDeclaration(node); |
| 2078 } finally { | 2105 } finally { |
| 2079 _enclosingExecutable = outerExecutable; | 2106 _enclosingExecutable = outerExecutable; |
| 2080 } | 2107 } |
| 2081 } | 2108 } |
| 2082 | 2109 |
| 2083 @override | 2110 @override |
| 2084 Object visitPartDirective(PartDirective node) { | 2111 Object visitPartDirective(PartDirective node) { |
| 2085 String uri = _getStringValue(node.uri); | 2112 String uri = _getStringValue(node.uri); |
| 2086 if (uri != null) { | 2113 if (uri != null) { |
| 2087 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri( | 2114 Source partSource = _enclosingUnit.context.sourceFactory |
| 2088 _enclosingUnit.source, uri); | 2115 .resolveUri(_enclosingUnit.source, uri); |
| 2089 node.element = _findPart(_enclosingUnit.library.parts, partSource); | 2116 node.element = _findPart(_enclosingUnit.library.parts, partSource); |
| 2090 } | 2117 } |
| 2091 return super.visitPartDirective(node); | 2118 return super.visitPartDirective(node); |
| 2092 } | 2119 } |
| 2093 | 2120 |
| 2094 @override | 2121 @override |
| 2095 Object visitPartOfDirective(PartOfDirective node) { | 2122 Object visitPartOfDirective(PartOfDirective node) { |
| 2096 node.element = _enclosingUnit.library; | 2123 node.element = _enclosingUnit.library; |
| 2097 return super.visitPartOfDirective(node); | 2124 return super.visitPartOfDirective(node); |
| 2098 } | 2125 } |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3005 buffer.write("The element for the method "); | 3032 buffer.write("The element for the method "); |
| 3006 buffer.write(node.name); | 3033 buffer.write(node.name); |
| 3007 buffer.write(" in "); | 3034 buffer.write(" in "); |
| 3008 buffer.write(classNode.name); | 3035 buffer.write(classNode.name); |
| 3009 buffer.write(" was not set while trying to build the element model."); | 3036 buffer.write(" was not set while trying to build the element model."); |
| 3010 AnalysisEngine.instance.logger.logError( | 3037 AnalysisEngine.instance.logger.logError( |
| 3011 buffer.toString(), new CaughtException(exception, stackTrace)); | 3038 buffer.toString(), new CaughtException(exception, stackTrace)); |
| 3012 } else { | 3039 } else { |
| 3013 String message = | 3040 String message = |
| 3014 "Exception caught in ElementBuilder.visitMethodDeclaration()"; | 3041 "Exception caught in ElementBuilder.visitMethodDeclaration()"; |
| 3015 AnalysisEngine.instance.logger.logError( | 3042 AnalysisEngine.instance.logger |
| 3016 message, new CaughtException(exception, stackTrace)); | 3043 .logError(message, new CaughtException(exception, stackTrace)); |
| 3017 } | 3044 } |
| 3018 } finally { | 3045 } finally { |
| 3019 if (node.name.staticElement == null) { | 3046 if (node.name.staticElement == null) { |
| 3020 ClassDeclaration classNode = | 3047 ClassDeclaration classNode = |
| 3021 node.getAncestor((node) => node is ClassDeclaration); | 3048 node.getAncestor((node) => node is ClassDeclaration); |
| 3022 StringBuffer buffer = new StringBuffer(); | 3049 StringBuffer buffer = new StringBuffer(); |
| 3023 buffer.write("The element for the method "); | 3050 buffer.write("The element for the method "); |
| 3024 buffer.write(node.name); | 3051 buffer.write(node.name); |
| 3025 buffer.write(" in "); | 3052 buffer.write(" in "); |
| 3026 buffer.write(classNode.name); | 3053 buffer.write(classNode.name); |
| 3027 buffer.write(" was not set while trying to resolve types."); | 3054 buffer.write(" was not set while trying to resolve types."); |
| 3028 AnalysisEngine.instance.logger.logError(buffer.toString(), | 3055 AnalysisEngine.instance.logger.logError( |
| 3056 buffer.toString(), |
| 3029 new CaughtException( | 3057 new CaughtException( |
| 3030 new AnalysisException(buffer.toString()), null)); | 3058 new AnalysisException(buffer.toString()), null)); |
| 3031 } | 3059 } |
| 3032 } | 3060 } |
| 3033 return null; | 3061 return null; |
| 3034 } | 3062 } |
| 3035 | 3063 |
| 3036 @override | 3064 @override |
| 3037 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 3065 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 3038 if (node.parent is! DefaultFormalParameter) { | 3066 if (node.parent is! DefaultFormalParameter) { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3719 Element internalLookup( | 3747 Element internalLookup( |
| 3720 Identifier identifier, String name, LibraryElement referencingLibrary) { | 3748 Identifier identifier, String name, LibraryElement referencingLibrary) { |
| 3721 Element element = localLookup(name, referencingLibrary); | 3749 Element element = localLookup(name, referencingLibrary); |
| 3722 if (element != null) { | 3750 if (element != null) { |
| 3723 return element; | 3751 return element; |
| 3724 } | 3752 } |
| 3725 // May be there is a hidden Element. | 3753 // May be there is a hidden Element. |
| 3726 if (_hasHiddenName) { | 3754 if (_hasHiddenName) { |
| 3727 Element hiddenElement = _hiddenElements[name]; | 3755 Element hiddenElement = _hiddenElements[name]; |
| 3728 if (hiddenElement != null) { | 3756 if (hiddenElement != null) { |
| 3729 errorListener.onError(new AnalysisError(getSource(identifier), | 3757 errorListener.onError(new AnalysisError( |
| 3730 identifier.offset, identifier.length, | 3758 getSource(identifier), |
| 3759 identifier.offset, |
| 3760 identifier.length, |
| 3731 CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, [])); | 3761 CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, [])); |
| 3732 return hiddenElement; | 3762 return hiddenElement; |
| 3733 } | 3763 } |
| 3734 } | 3764 } |
| 3735 // Check enclosing scope. | 3765 // Check enclosing scope. |
| 3736 return enclosingScope.internalLookup(identifier, name, referencingLibrary); | 3766 return enclosingScope.internalLookup(identifier, name, referencingLibrary); |
| 3737 } | 3767 } |
| 3738 } | 3768 } |
| 3739 | 3769 |
| 3740 /** | 3770 /** |
| (...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5666 * This method takes some inherited [FunctionType], and resolves all the param
eterized types | 5696 * This method takes some inherited [FunctionType], and resolves all the param
eterized types |
| 5667 * in the function type, dependent on the class in which it is being overridde
n. | 5697 * in the function type, dependent on the class in which it is being overridde
n. |
| 5668 * | 5698 * |
| 5669 * @param baseFunctionType the function type that is being overridden | 5699 * @param baseFunctionType the function type that is being overridden |
| 5670 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the | 5700 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the |
| 5671 * override | 5701 * override |
| 5672 * @param definingType the type that is overriding the member | 5702 * @param definingType the type that is overriding the member |
| 5673 * @return the passed function type with any parameterized types substituted | 5703 * @return the passed function type with any parameterized types substituted |
| 5674 */ | 5704 */ |
| 5675 FunctionType substituteTypeArgumentsInMemberFromInheritance( | 5705 FunctionType substituteTypeArgumentsInMemberFromInheritance( |
| 5676 FunctionType baseFunctionType, String memberName, | 5706 FunctionType baseFunctionType, |
| 5707 String memberName, |
| 5677 InterfaceType definingType) { | 5708 InterfaceType definingType) { |
| 5678 // if the baseFunctionType is null, or does not have any parameters, | 5709 // if the baseFunctionType is null, or does not have any parameters, |
| 5679 // return it. | 5710 // return it. |
| 5680 if (baseFunctionType == null || | 5711 if (baseFunctionType == null || |
| 5681 baseFunctionType.typeArguments.length == 0) { | 5712 baseFunctionType.typeArguments.length == 0) { |
| 5682 return baseFunctionType; | 5713 return baseFunctionType; |
| 5683 } | 5714 } |
| 5684 // First, generate the path from the defining type to the overridden member | 5715 // First, generate the path from the defining type to the overridden member |
| 5685 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); | 5716 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); |
| 5686 _computeInheritancePath(inheritancePath, definingType, memberName); | 5717 _computeInheritancePath(inheritancePath, definingType, memberName); |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6223 } | 6254 } |
| 6224 // | 6255 // |
| 6225 // Example: class A inherited only 2 method named 'm'. | 6256 // Example: class A inherited only 2 method named 'm'. |
| 6226 // One has the function type '() -> int' and one has the function | 6257 // One has the function type '() -> int' and one has the function |
| 6227 // type '() -> String'. Since neither is a subtype of the other, | 6258 // type '() -> String'. Since neither is a subtype of the other, |
| 6228 // we create a warning, and have this class inherit nothing. | 6259 // we create a warning, and have this class inherit nothing. |
| 6229 // | 6260 // |
| 6230 if (!classHasMember) { | 6261 if (!classHasMember) { |
| 6231 String firstTwoFuntionTypesStr = | 6262 String firstTwoFuntionTypesStr = |
| 6232 "${executableElementTypes[0]}, ${executableElementTypes[1]}"
; | 6263 "${executableElementTypes[0]}, ${executableElementTypes[1]}"
; |
| 6233 _reportError(classElt, classElt.nameOffset, | 6264 _reportError( |
| 6265 classElt, |
| 6266 classElt.nameOffset, |
| 6234 classElt.displayName.length, | 6267 classElt.displayName.length, |
| 6235 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [ | 6268 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, |
| 6236 key, | 6269 [key, firstTwoFuntionTypesStr]); |
| 6237 firstTwoFuntionTypesStr | |
| 6238 ]); | |
| 6239 } | 6270 } |
| 6240 } else { | 6271 } else { |
| 6241 // | 6272 // |
| 6242 // Example: class A inherits 2 methods named 'm'. | 6273 // Example: class A inherits 2 methods named 'm'. |
| 6243 // One has the function type '(int) -> dynamic' and one has the | 6274 // One has the function type '(int) -> dynamic' and one has the |
| 6244 // function type '(num) -> dynamic'. Since they are both a subtype | 6275 // function type '(num) -> dynamic'. Since they are both a subtype |
| 6245 // of the other, a synthetic function '(dynamic) -> dynamic' is | 6276 // of the other, a synthetic function '(dynamic) -> dynamic' is |
| 6246 // inherited. | 6277 // inherited. |
| 6247 // Tests: test_getMapOfMembersInheritedFromInterfaces_ | 6278 // Tests: test_getMapOfMembersInheritedFromInterfaces_ |
| 6248 // union_multipleSubtypes_* | 6279 // union_multipleSubtypes_* |
| 6249 // | 6280 // |
| 6250 List<ExecutableElement> elementArrayToMerge = | 6281 List<ExecutableElement> elementArrayToMerge = new List< |
| 6251 new List<ExecutableElement>( | 6282 ExecutableElement>(subtypesOfAllOtherTypesIndexes.length); |
| 6252 subtypesOfAllOtherTypesIndexes.length); | |
| 6253 for (int i = 0; i < elementArrayToMerge.length; i++) { | 6283 for (int i = 0; i < elementArrayToMerge.length; i++) { |
| 6254 elementArrayToMerge[i] = | 6284 elementArrayToMerge[i] = |
| 6255 elements[subtypesOfAllOtherTypesIndexes[i]]; | 6285 elements[subtypesOfAllOtherTypesIndexes[i]]; |
| 6256 } | 6286 } |
| 6257 ExecutableElement mergedExecutableElement = | 6287 ExecutableElement mergedExecutableElement = |
| 6258 _computeMergedExecutableElement(elementArrayToMerge); | 6288 _computeMergedExecutableElement(elementArrayToMerge); |
| 6259 resultMap.put(key, mergedExecutableElement); | 6289 resultMap.put(key, mergedExecutableElement); |
| 6260 } | 6290 } |
| 6261 } | 6291 } |
| 6262 } else { | 6292 } else { |
| 6263 _reportError(classElt, classElt.nameOffset, | 6293 _reportError( |
| 6294 classElt, |
| 6295 classElt.nameOffset, |
| 6264 classElt.displayName.length, | 6296 classElt.displayName.length, |
| 6265 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO
D, | 6297 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO
D, |
| 6266 [key]); | 6298 [key]); |
| 6267 } | 6299 } |
| 6268 } | 6300 } |
| 6269 }); | 6301 }); |
| 6270 return resultMap; | 6302 return resultMap; |
| 6271 } | 6303 } |
| 6272 | 6304 |
| 6273 /** | 6305 /** |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6376 int numOfPositionalParams = _getNumOfPositionalParameters(element); | 6408 int numOfPositionalParams = _getNumOfPositionalParameters(element); |
| 6377 if (h < numOfPositionalParams) { | 6409 if (h < numOfPositionalParams) { |
| 6378 h = numOfPositionalParams; | 6410 h = numOfPositionalParams; |
| 6379 } | 6411 } |
| 6380 int numOfRequiredParams = _getNumOfRequiredParameters(element); | 6412 int numOfRequiredParams = _getNumOfRequiredParameters(element); |
| 6381 if (r > numOfRequiredParams) { | 6413 if (r > numOfRequiredParams) { |
| 6382 r = numOfRequiredParams; | 6414 r = numOfRequiredParams; |
| 6383 } | 6415 } |
| 6384 namedParametersList.addAll(_getNamedParameterNames(element)); | 6416 namedParametersList.addAll(_getNamedParameterNames(element)); |
| 6385 } | 6417 } |
| 6386 return _createSyntheticExecutableElement(elementArrayToMerge, | 6418 return _createSyntheticExecutableElement( |
| 6387 elementArrayToMerge[0].displayName, r, h - r, | 6419 elementArrayToMerge, |
| 6420 elementArrayToMerge[0].displayName, |
| 6421 r, |
| 6422 h - r, |
| 6388 new List.from(namedParametersList)); | 6423 new List.from(namedParametersList)); |
| 6389 } | 6424 } |
| 6390 | 6425 |
| 6391 /** | 6426 /** |
| 6392 * Used by [computeMergedExecutableElement] to actually create the | 6427 * Used by [computeMergedExecutableElement] to actually create the |
| 6393 * synthetic element. | 6428 * synthetic element. |
| 6394 * | 6429 * |
| 6395 * @param elementArrayToMerge the array used to create the synthetic element | 6430 * @param elementArrayToMerge the array used to create the synthetic element |
| 6396 * @param name the name of the method, getter or setter | 6431 * @param name the name of the method, getter or setter |
| 6397 * @param numOfRequiredParameters the number of required parameters | 6432 * @param numOfRequiredParameters the number of required parameters |
| 6398 * @param numOfPositionalParameters the number of positional parameters | 6433 * @param numOfPositionalParameters the number of positional parameters |
| 6399 * @param namedParameters the list of [String]s that are the named parameters | 6434 * @param namedParameters the list of [String]s that are the named parameters |
| 6400 * @return the created synthetic element | 6435 * @return the created synthetic element |
| 6401 */ | 6436 */ |
| 6402 static ExecutableElement _createSyntheticExecutableElement( | 6437 static ExecutableElement _createSyntheticExecutableElement( |
| 6403 List<ExecutableElement> elementArrayToMerge, String name, | 6438 List<ExecutableElement> elementArrayToMerge, |
| 6404 int numOfRequiredParameters, int numOfPositionalParameters, | 6439 String name, |
| 6440 int numOfRequiredParameters, |
| 6441 int numOfPositionalParameters, |
| 6405 List<String> namedParameters) { | 6442 List<String> namedParameters) { |
| 6406 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; | 6443 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; |
| 6407 SimpleIdentifier nameIdentifier = new SimpleIdentifier( | 6444 SimpleIdentifier nameIdentifier = new SimpleIdentifier( |
| 6408 new sc.StringToken(sc.TokenType.IDENTIFIER, name, 0)); | 6445 new sc.StringToken(sc.TokenType.IDENTIFIER, name, 0)); |
| 6409 ExecutableElementImpl executable; | 6446 ExecutableElementImpl executable; |
| 6410 if (elementArrayToMerge[0] is MethodElement) { | 6447 if (elementArrayToMerge[0] is MethodElement) { |
| 6411 MultiplyInheritedMethodElementImpl unionedMethod = | 6448 MultiplyInheritedMethodElementImpl unionedMethod = |
| 6412 new MultiplyInheritedMethodElementImpl(nameIdentifier); | 6449 new MultiplyInheritedMethodElementImpl(nameIdentifier); |
| 6413 unionedMethod.inheritedElements = elementArrayToMerge; | 6450 unionedMethod.inheritedElements = elementArrayToMerge; |
| 6414 executable = unionedMethod; | 6451 executable = unionedMethod; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6776 } | 6813 } |
| 6777 | 6814 |
| 6778 /** | 6815 /** |
| 6779 * Return the library element representing this library, creating it if necess
ary. | 6816 * Return the library element representing this library, creating it if necess
ary. |
| 6780 * | 6817 * |
| 6781 * @return the library element representing this library | 6818 * @return the library element representing this library |
| 6782 */ | 6819 */ |
| 6783 LibraryElementImpl get libraryElement { | 6820 LibraryElementImpl get libraryElement { |
| 6784 if (_libraryElement == null) { | 6821 if (_libraryElement == null) { |
| 6785 try { | 6822 try { |
| 6786 _libraryElement = _analysisContext | 6823 _libraryElement = _analysisContext.computeLibraryElement(librarySource) |
| 6787 .computeLibraryElement(librarySource) as LibraryElementImpl; | 6824 as LibraryElementImpl; |
| 6788 } on AnalysisException catch (exception, stackTrace) { | 6825 } on AnalysisException catch (exception, stackTrace) { |
| 6789 AnalysisEngine.instance.logger.logError( | 6826 AnalysisEngine.instance.logger.logError( |
| 6790 "Could not compute library element for ${librarySource.fullName}", | 6827 "Could not compute library element for ${librarySource.fullName}", |
| 6791 new CaughtException(exception, stackTrace)); | 6828 new CaughtException(exception, stackTrace)); |
| 6792 } | 6829 } |
| 6793 } | 6830 } |
| 6794 return _libraryElement; | 6831 return _libraryElement; |
| 6795 } | 6832 } |
| 6796 | 6833 |
| 6797 /** | 6834 /** |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6854 if (directive is ImportDirective && | 6891 if (directive is ImportDirective && |
| 6855 uriContent.startsWith(_DART_EXT_SCHEME)) { | 6892 uriContent.startsWith(_DART_EXT_SCHEME)) { |
| 6856 _libraryElement.hasExtUri = true; | 6893 _libraryElement.hasExtUri = true; |
| 6857 return null; | 6894 return null; |
| 6858 } | 6895 } |
| 6859 try { | 6896 try { |
| 6860 parseUriWithException(uriContent); | 6897 parseUriWithException(uriContent); |
| 6861 Source source = | 6898 Source source = |
| 6862 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent); | 6899 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent); |
| 6863 if (!_analysisContext.exists(source)) { | 6900 if (!_analysisContext.exists(source)) { |
| 6864 errorListener.onError(new AnalysisError(librarySource, | 6901 errorListener.onError(new AnalysisError( |
| 6865 uriLiteral.offset, uriLiteral.length, | 6902 librarySource, |
| 6866 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent])); | 6903 uriLiteral.offset, |
| 6904 uriLiteral.length, |
| 6905 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 6906 [uriContent])); |
| 6867 } | 6907 } |
| 6868 return source; | 6908 return source; |
| 6869 } on URISyntaxException { | 6909 } on URISyntaxException { |
| 6870 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset, | 6910 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset, |
| 6871 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); | 6911 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); |
| 6872 } | 6912 } |
| 6873 return null; | 6913 return null; |
| 6874 } | 6914 } |
| 6875 | 6915 |
| 6876 /** | 6916 /** |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6961 part.uriOffset = partUri.offset; | 7001 part.uriOffset = partUri.offset; |
| 6962 part.uriEnd = partUri.end; | 7002 part.uriEnd = partUri.end; |
| 6963 part.uri = partDirective.uriContent; | 7003 part.uri = partDirective.uriContent; |
| 6964 // | 7004 // |
| 6965 // Validate that the part contains a part-of directive with the same | 7005 // Validate that the part contains a part-of directive with the same |
| 6966 // name as the library. | 7006 // name as the library. |
| 6967 // | 7007 // |
| 6968 String partLibraryName = | 7008 String partLibraryName = |
| 6969 _getPartLibraryName(partSource, partUnit, directivesToResolve); | 7009 _getPartLibraryName(partSource, partUnit, directivesToResolve); |
| 6970 if (partLibraryName == null) { | 7010 if (partLibraryName == null) { |
| 6971 _errorListener.onError(new AnalysisError(librarySource, | 7011 _errorListener.onError(new AnalysisError( |
| 6972 partUri.offset, partUri.length, | 7012 librarySource, |
| 6973 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()])); | 7013 partUri.offset, |
| 7014 partUri.length, |
| 7015 CompileTimeErrorCode.PART_OF_NON_PART, |
| 7016 [partUri.toSource()])); |
| 6974 } else if (libraryNameNode == null) { | 7017 } else if (libraryNameNode == null) { |
| 6975 // TODO(brianwilkerson) Collect the names declared by the part. | 7018 // TODO(brianwilkerson) Collect the names declared by the part. |
| 6976 // If they are all the same then we can use that name as the | 7019 // If they are all the same then we can use that name as the |
| 6977 // inferred name of the library and present it in a quick-fix. | 7020 // inferred name of the library and present it in a quick-fix. |
| 6978 // partLibraryNames.add(partLibraryName); | 7021 // partLibraryNames.add(partLibraryName); |
| 6979 } else if (libraryNameNode.name != partLibraryName) { | 7022 } else if (libraryNameNode.name != partLibraryName) { |
| 6980 _errorListener.onError(new AnalysisError(librarySource, | 7023 _errorListener.onError(new AnalysisError( |
| 6981 partUri.offset, partUri.length, | 7024 librarySource, |
| 6982 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ | 7025 partUri.offset, |
| 6983 libraryNameNode.name, | 7026 partUri.length, |
| 6984 partLibraryName | 7027 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, |
| 6985 ])); | 7028 [libraryNameNode.name, partLibraryName])); |
| 6986 } | 7029 } |
| 6987 if (entryPoint == null) { | 7030 if (entryPoint == null) { |
| 6988 entryPoint = _findEntryPoint(part); | 7031 entryPoint = _findEntryPoint(part); |
| 6989 } | 7032 } |
| 6990 directive.element = part; | 7033 directive.element = part; |
| 6991 sourcedCompilationUnits.add(part); | 7034 sourcedCompilationUnits.add(part); |
| 6992 } | 7035 } |
| 6993 } | 7036 } |
| 6994 } | 7037 } |
| 6995 if (hasPartDirective && libraryNameNode == null) { | 7038 if (hasPartDirective && libraryNameNode == null) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7065 part.uriOffset = partUri.offset; | 7108 part.uriOffset = partUri.offset; |
| 7066 part.uriEnd = partUri.end; | 7109 part.uriEnd = partUri.end; |
| 7067 part.uri = partDirective.uriContent; | 7110 part.uri = partDirective.uriContent; |
| 7068 // | 7111 // |
| 7069 // Validate that the part contains a part-of directive with the same | 7112 // Validate that the part contains a part-of directive with the same |
| 7070 // name as the library. | 7113 // name as the library. |
| 7071 // | 7114 // |
| 7072 String partLibraryName = | 7115 String partLibraryName = |
| 7073 _getPartLibraryName(partSource, partUnit, directivesToResolve); | 7116 _getPartLibraryName(partSource, partUnit, directivesToResolve); |
| 7074 if (partLibraryName == null) { | 7117 if (partLibraryName == null) { |
| 7075 _errorListener.onError(new AnalysisError(librarySource, | 7118 _errorListener.onError(new AnalysisError( |
| 7076 partUri.offset, partUri.length, | 7119 librarySource, |
| 7077 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()])); | 7120 partUri.offset, |
| 7121 partUri.length, |
| 7122 CompileTimeErrorCode.PART_OF_NON_PART, |
| 7123 [partUri.toSource()])); |
| 7078 } else if (libraryNameNode == null) { | 7124 } else if (libraryNameNode == null) { |
| 7079 // TODO(brianwilkerson) Collect the names declared by the part. | 7125 // TODO(brianwilkerson) Collect the names declared by the part. |
| 7080 // If they are all the same then we can use that name as the | 7126 // If they are all the same then we can use that name as the |
| 7081 // inferred name of the library and present it in a quick-fix. | 7127 // inferred name of the library and present it in a quick-fix. |
| 7082 // partLibraryNames.add(partLibraryName); | 7128 // partLibraryNames.add(partLibraryName); |
| 7083 } else if (libraryNameNode.name != partLibraryName) { | 7129 } else if (libraryNameNode.name != partLibraryName) { |
| 7084 _errorListener.onError(new AnalysisError(librarySource, | 7130 _errorListener.onError(new AnalysisError( |
| 7085 partUri.offset, partUri.length, | 7131 librarySource, |
| 7086 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ | 7132 partUri.offset, |
| 7087 libraryNameNode.name, | 7133 partUri.length, |
| 7088 partLibraryName | 7134 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, |
| 7089 ])); | 7135 [libraryNameNode.name, partLibraryName])); |
| 7090 } | 7136 } |
| 7091 if (entryPoint == null) { | 7137 if (entryPoint == null) { |
| 7092 entryPoint = _findEntryPoint(part); | 7138 entryPoint = _findEntryPoint(part); |
| 7093 } | 7139 } |
| 7094 directive.element = part; | 7140 directive.element = part; |
| 7095 sourcedCompilationUnits.add(part); | 7141 sourcedCompilationUnits.add(part); |
| 7096 } | 7142 } |
| 7097 } | 7143 } |
| 7098 } | 7144 } |
| 7099 } | 7145 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7284 } | 7330 } |
| 7285 if (foundElement is MultiplyDefinedElementImpl) { | 7331 if (foundElement is MultiplyDefinedElementImpl) { |
| 7286 String foundEltName = foundElement.displayName; | 7332 String foundEltName = foundElement.displayName; |
| 7287 List<Element> conflictingMembers = foundElement.conflictingElements; | 7333 List<Element> conflictingMembers = foundElement.conflictingElements; |
| 7288 int count = conflictingMembers.length; | 7334 int count = conflictingMembers.length; |
| 7289 List<String> libraryNames = new List<String>(count); | 7335 List<String> libraryNames = new List<String>(count); |
| 7290 for (int i = 0; i < count; i++) { | 7336 for (int i = 0; i < count; i++) { |
| 7291 libraryNames[i] = _getLibraryName(conflictingMembers[i]); | 7337 libraryNames[i] = _getLibraryName(conflictingMembers[i]); |
| 7292 } | 7338 } |
| 7293 libraryNames.sort(); | 7339 libraryNames.sort(); |
| 7294 errorListener.onError(new AnalysisError(getSource(identifier), | 7340 errorListener.onError(new AnalysisError( |
| 7295 identifier.offset, identifier.length, | 7341 getSource(identifier), |
| 7342 identifier.offset, |
| 7343 identifier.length, |
| 7296 StaticWarningCode.AMBIGUOUS_IMPORT, [ | 7344 StaticWarningCode.AMBIGUOUS_IMPORT, [ |
| 7297 foundEltName, | 7345 foundEltName, |
| 7298 StringUtilities.printListOfQuotedNames(libraryNames) | 7346 StringUtilities.printListOfQuotedNames(libraryNames) |
| 7299 ])); | 7347 ])); |
| 7300 return foundElement; | 7348 return foundElement; |
| 7301 } | 7349 } |
| 7302 if (foundElement != null) { | 7350 if (foundElement != null) { |
| 7303 defineNameWithoutChecking(name, foundElement); | 7351 defineNameWithoutChecking(name, foundElement); |
| 7304 } | 7352 } |
| 7305 return foundElement; | 7353 return foundElement; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7386 for (Element member in conflictingElements) { | 7434 for (Element member in conflictingElements) { |
| 7387 if (member.library.isInSdk) { | 7435 if (member.library.isInSdk) { |
| 7388 sdkElement = member; | 7436 sdkElement = member; |
| 7389 } else { | 7437 } else { |
| 7390 nonSdkElements.add(member); | 7438 nonSdkElements.add(member); |
| 7391 } | 7439 } |
| 7392 } | 7440 } |
| 7393 if (sdkElement != null && nonSdkElements.length > 0) { | 7441 if (sdkElement != null && nonSdkElements.length > 0) { |
| 7394 String sdkLibName = _getLibraryName(sdkElement); | 7442 String sdkLibName = _getLibraryName(sdkElement); |
| 7395 String otherLibName = _getLibraryName(nonSdkElements[0]); | 7443 String otherLibName = _getLibraryName(nonSdkElements[0]); |
| 7396 errorListener.onError(new AnalysisError(getSource(identifier), | 7444 errorListener.onError(new AnalysisError( |
| 7397 identifier.offset, identifier.length, | 7445 getSource(identifier), |
| 7398 StaticWarningCode.CONFLICTING_DART_IMPORT, [ | 7446 identifier.offset, |
| 7399 name, | 7447 identifier.length, |
| 7400 sdkLibName, | 7448 StaticWarningCode.CONFLICTING_DART_IMPORT, |
| 7401 otherLibName | 7449 [name, sdkLibName, otherLibName])); |
| 7402 ])); | |
| 7403 } | 7450 } |
| 7404 if (nonSdkElements.length == conflictingElements.length) { | 7451 if (nonSdkElements.length == conflictingElements.length) { |
| 7405 // None of the members were removed | 7452 // None of the members were removed |
| 7406 return foundElement; | 7453 return foundElement; |
| 7407 } else if (nonSdkElements.length == 1) { | 7454 } else if (nonSdkElements.length == 1) { |
| 7408 // All but one member was removed | 7455 // All but one member was removed |
| 7409 return nonSdkElements[0]; | 7456 return nonSdkElements[0]; |
| 7410 } else if (nonSdkElements.length == 0) { | 7457 } else if (nonSdkElements.length == 0) { |
| 7411 // All members were removed | 7458 // All members were removed |
| 7412 AnalysisEngine.instance.logger | 7459 AnalysisEngine.instance.logger |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7741 | 7788 |
| 7742 /** | 7789 /** |
| 7743 * Add the given library, and all libraries reachable from it that have not al
ready been visited, | 7790 * Add the given library, and all libraries reachable from it that have not al
ready been visited, |
| 7744 * to the given dependency map. | 7791 * to the given dependency map. |
| 7745 * | 7792 * |
| 7746 * @param library the library currently being added to the dependency map | 7793 * @param library the library currently being added to the dependency map |
| 7747 * @param dependencyMap the dependency map being computed | 7794 * @param dependencyMap the dependency map being computed |
| 7748 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite | 7795 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite |
| 7749 * recursion | 7796 * recursion |
| 7750 */ | 7797 */ |
| 7751 void _addToDependencyMap(Library library, | 7798 void _addToDependencyMap( |
| 7799 Library library, |
| 7752 HashMap<Library, List<Library>> dependencyMap, | 7800 HashMap<Library, List<Library>> dependencyMap, |
| 7753 Set<Library> visitedLibraries) { | 7801 Set<Library> visitedLibraries) { |
| 7754 if (visitedLibraries.add(library)) { | 7802 if (visitedLibraries.add(library)) { |
| 7755 bool asyncFound = false; | 7803 bool asyncFound = false; |
| 7756 for (Library referencedLibrary in library.importsAndExports) { | 7804 for (Library referencedLibrary in library.importsAndExports) { |
| 7757 _addDependencyToMap(dependencyMap, library, referencedLibrary); | 7805 _addDependencyToMap(dependencyMap, library, referencedLibrary); |
| 7758 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); | 7806 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); |
| 7759 if (identical(referencedLibrary, _asyncLibrary)) { | 7807 if (identical(referencedLibrary, _asyncLibrary)) { |
| 7760 asyncFound = true; | 7808 asyncFound = true; |
| 7761 } | 7809 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7846 importElement.prefix = prefix; | 7894 importElement.prefix = prefix; |
| 7847 prefixNode.staticElement = prefix; | 7895 prefixNode.staticElement = prefix; |
| 7848 } | 7896 } |
| 7849 directive.element = importElement; | 7897 directive.element = importElement; |
| 7850 imports.add(importElement); | 7898 imports.add(importElement); |
| 7851 if (analysisContext.computeKindOf(importedSource) != | 7899 if (analysisContext.computeKindOf(importedSource) != |
| 7852 SourceKind.LIBRARY) { | 7900 SourceKind.LIBRARY) { |
| 7853 ErrorCode errorCode = (importElement.isDeferred | 7901 ErrorCode errorCode = (importElement.isDeferred |
| 7854 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY | 7902 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY |
| 7855 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); | 7903 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); |
| 7856 _errorListener.onError(new AnalysisError(library.librarySource, | 7904 _errorListener.onError(new AnalysisError( |
| 7857 uriLiteral.offset, uriLiteral.length, errorCode, | 7905 library.librarySource, |
| 7906 uriLiteral.offset, |
| 7907 uriLiteral.length, |
| 7908 errorCode, |
| 7858 [uriLiteral.toSource()])); | 7909 [uriLiteral.toSource()])); |
| 7859 } | 7910 } |
| 7860 } | 7911 } |
| 7861 } | 7912 } |
| 7862 } else if (directive is ExportDirective) { | 7913 } else if (directive is ExportDirective) { |
| 7863 ExportDirective exportDirective = directive; | 7914 ExportDirective exportDirective = directive; |
| 7864 Source exportedSource = exportDirective.source; | 7915 Source exportedSource = exportDirective.source; |
| 7865 if (exportedSource != null) { | 7916 if (exportedSource != null) { |
| 7866 // The exported source will be null if the URI in the export | 7917 // The exported source will be null if the URI in the export |
| 7867 // directive was invalid. | 7918 // directive was invalid. |
| 7868 Library exportedLibrary = _libraryMap[exportedSource]; | 7919 Library exportedLibrary = _libraryMap[exportedSource]; |
| 7869 if (exportedLibrary != null) { | 7920 if (exportedLibrary != null) { |
| 7870 ExportElementImpl exportElement = | 7921 ExportElementImpl exportElement = |
| 7871 new ExportElementImpl(directive.offset); | 7922 new ExportElementImpl(directive.offset); |
| 7872 StringLiteral uriLiteral = exportDirective.uri; | 7923 StringLiteral uriLiteral = exportDirective.uri; |
| 7873 exportElement.uriOffset = uriLiteral.offset; | 7924 exportElement.uriOffset = uriLiteral.offset; |
| 7874 exportElement.uriEnd = uriLiteral.end; | 7925 exportElement.uriEnd = uriLiteral.end; |
| 7875 exportElement.uri = exportDirective.uriContent; | 7926 exportElement.uri = exportDirective.uriContent; |
| 7876 exportElement.combinators = _buildCombinators(exportDirective); | 7927 exportElement.combinators = _buildCombinators(exportDirective); |
| 7877 LibraryElement exportedLibraryElement = | 7928 LibraryElement exportedLibraryElement = |
| 7878 exportedLibrary.libraryElement; | 7929 exportedLibrary.libraryElement; |
| 7879 if (exportedLibraryElement != null) { | 7930 if (exportedLibraryElement != null) { |
| 7880 exportElement.exportedLibrary = exportedLibraryElement; | 7931 exportElement.exportedLibrary = exportedLibraryElement; |
| 7881 } | 7932 } |
| 7882 directive.element = exportElement; | 7933 directive.element = exportElement; |
| 7883 exports.add(exportElement); | 7934 exports.add(exportElement); |
| 7884 if (analysisContext.computeKindOf(exportedSource) != | 7935 if (analysisContext.computeKindOf(exportedSource) != |
| 7885 SourceKind.LIBRARY) { | 7936 SourceKind.LIBRARY) { |
| 7886 _errorListener.onError(new AnalysisError(library.librarySource, | 7937 _errorListener.onError(new AnalysisError( |
| 7887 uriLiteral.offset, uriLiteral.length, | 7938 library.librarySource, |
| 7939 uriLiteral.offset, |
| 7940 uriLiteral.length, |
| 7888 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, | 7941 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, |
| 7889 [uriLiteral.toSource()])); | 7942 [uriLiteral.toSource()])); |
| 7890 } | 7943 } |
| 7891 } | 7944 } |
| 7892 } | 7945 } |
| 7893 } | 7946 } |
| 7894 } | 7947 } |
| 7895 Source librarySource = library.librarySource; | 7948 Source librarySource = library.librarySource; |
| 7896 if (!library.explicitlyImportsCore && | 7949 if (!library.explicitlyImportsCore && |
| 7897 _coreLibrarySource != librarySource) { | 7950 _coreLibrarySource != librarySource) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8034 | 8087 |
| 8035 /** | 8088 /** |
| 8036 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 8089 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 8037 * class [Library] to represent them, and record the references in the library
objects. | 8090 * class [Library] to represent them, and record the references in the library
objects. |
| 8038 * | 8091 * |
| 8039 * @param library the library to be processed to find libraries that have not
yet been traversed | 8092 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 8040 * @throws AnalysisException if some portion of the library graph could not be
traversed | 8093 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 8041 */ | 8094 */ |
| 8042 void _computeLibraryDependencies(Library library) { | 8095 void _computeLibraryDependencies(Library library) { |
| 8043 Source librarySource = library.librarySource; | 8096 Source librarySource = library.librarySource; |
| 8044 _computeLibraryDependenciesFromDirectives(library, | 8097 _computeLibraryDependenciesFromDirectives( |
| 8098 library, |
| 8045 analysisContext.computeImportedLibraries(librarySource), | 8099 analysisContext.computeImportedLibraries(librarySource), |
| 8046 analysisContext.computeExportedLibraries(librarySource)); | 8100 analysisContext.computeExportedLibraries(librarySource)); |
| 8047 } | 8101 } |
| 8048 | 8102 |
| 8049 /** | 8103 /** |
| 8050 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 8104 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 8051 * class [Library] to represent them, and record the references in the library
objects. | 8105 * class [Library] to represent them, and record the references in the library
objects. |
| 8052 * | 8106 * |
| 8053 * @param library the library to be processed to find libraries that have not
yet been traversed | 8107 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 8054 * @param importedSources an array containing the sources that are imported in
to the given library | 8108 * @param importedSources an array containing the sources that are imported in
to the given library |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8188 computer.computeValues(); | 8242 computer.computeValues(); |
| 8189 // As a temporary workaround for issue 21572, run ConstantVerifier now. | 8243 // As a temporary workaround for issue 21572, run ConstantVerifier now. |
| 8190 // TODO(paulberry): remove this workaround once issue 21572 is fixed. | 8244 // TODO(paulberry): remove this workaround once issue 21572 is fixed. |
| 8191 for (Library library in _librariesInCycles) { | 8245 for (Library library in _librariesInCycles) { |
| 8192 for (Source source in library.compilationUnitSources) { | 8246 for (Source source in library.compilationUnitSources) { |
| 8193 try { | 8247 try { |
| 8194 CompilationUnit unit = library.getAST(source); | 8248 CompilationUnit unit = library.getAST(source); |
| 8195 ErrorReporter errorReporter = | 8249 ErrorReporter errorReporter = |
| 8196 new ErrorReporter(_errorListener, source); | 8250 new ErrorReporter(_errorListener, source); |
| 8197 ConstantVerifier constantVerifier = new ConstantVerifier( | 8251 ConstantVerifier constantVerifier = new ConstantVerifier( |
| 8198 errorReporter, library.libraryElement, _typeProvider, | 8252 errorReporter, |
| 8253 library.libraryElement, |
| 8254 _typeProvider, |
| 8199 analysisContext.declaredVariables); | 8255 analysisContext.declaredVariables); |
| 8200 unit.accept(constantVerifier); | 8256 unit.accept(constantVerifier); |
| 8201 } on AnalysisException catch (exception, stackTrace) { | 8257 } on AnalysisException catch (exception, stackTrace) { |
| 8202 AnalysisEngine.instance.logger.logError( | 8258 AnalysisEngine.instance.logger.logError( |
| 8203 "Internal Error: Could not access AST for ${source.fullName} " | 8259 "Internal Error: Could not access AST for ${source.fullName} " |
| 8204 "during constant verification", | 8260 "during constant verification", |
| 8205 new CaughtException(exception, stackTrace)); | 8261 new CaughtException(exception, stackTrace)); |
| 8206 } | 8262 } |
| 8207 } | 8263 } |
| 8208 } | 8264 } |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8491 importElement.prefix = prefix; | 8547 importElement.prefix = prefix; |
| 8492 prefixNode.staticElement = prefix; | 8548 prefixNode.staticElement = prefix; |
| 8493 } | 8549 } |
| 8494 directive.element = importElement; | 8550 directive.element = importElement; |
| 8495 imports.add(importElement); | 8551 imports.add(importElement); |
| 8496 if (analysisContext.computeKindOf(importedSource) != | 8552 if (analysisContext.computeKindOf(importedSource) != |
| 8497 SourceKind.LIBRARY) { | 8553 SourceKind.LIBRARY) { |
| 8498 ErrorCode errorCode = (importElement.isDeferred | 8554 ErrorCode errorCode = (importElement.isDeferred |
| 8499 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY | 8555 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY |
| 8500 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); | 8556 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); |
| 8501 _errorListener.onError(new AnalysisError(library.librarySource, | 8557 _errorListener.onError(new AnalysisError( |
| 8502 uriLiteral.offset, uriLiteral.length, errorCode, | 8558 library.librarySource, |
| 8559 uriLiteral.offset, |
| 8560 uriLiteral.length, |
| 8561 errorCode, |
| 8503 [uriLiteral.toSource()])); | 8562 [uriLiteral.toSource()])); |
| 8504 } | 8563 } |
| 8505 } | 8564 } |
| 8506 } | 8565 } |
| 8507 } else if (directive is ExportDirective) { | 8566 } else if (directive is ExportDirective) { |
| 8508 ExportDirective exportDirective = directive; | 8567 ExportDirective exportDirective = directive; |
| 8509 Source exportedSource = exportDirective.source; | 8568 Source exportedSource = exportDirective.source; |
| 8510 if (exportedSource != null && | 8569 if (exportedSource != null && |
| 8511 analysisContext.exists(exportedSource)) { | 8570 analysisContext.exists(exportedSource)) { |
| 8512 // The exported source will be null if the URI in the export | 8571 // The exported source will be null if the URI in the export |
| (...skipping 11 matching lines...) Expand all Loading... |
| 8524 exportElement.combinators = _buildCombinators(exportDirective); | 8583 exportElement.combinators = _buildCombinators(exportDirective); |
| 8525 LibraryElement exportedLibraryElement = | 8584 LibraryElement exportedLibraryElement = |
| 8526 exportedLibrary.libraryElement; | 8585 exportedLibrary.libraryElement; |
| 8527 if (exportedLibraryElement != null) { | 8586 if (exportedLibraryElement != null) { |
| 8528 exportElement.exportedLibrary = exportedLibraryElement; | 8587 exportElement.exportedLibrary = exportedLibraryElement; |
| 8529 } | 8588 } |
| 8530 directive.element = exportElement; | 8589 directive.element = exportElement; |
| 8531 exports.add(exportElement); | 8590 exports.add(exportElement); |
| 8532 if (analysisContext.computeKindOf(exportedSource) != | 8591 if (analysisContext.computeKindOf(exportedSource) != |
| 8533 SourceKind.LIBRARY) { | 8592 SourceKind.LIBRARY) { |
| 8534 _errorListener.onError(new AnalysisError(library.librarySource, | 8593 _errorListener.onError(new AnalysisError( |
| 8535 uriLiteral.offset, uriLiteral.length, | 8594 library.librarySource, |
| 8595 uriLiteral.offset, |
| 8596 uriLiteral.length, |
| 8536 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, | 8597 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, |
| 8537 [uriLiteral.toSource()])); | 8598 [uriLiteral.toSource()])); |
| 8538 } | 8599 } |
| 8539 } | 8600 } |
| 8540 } | 8601 } |
| 8541 } | 8602 } |
| 8542 } | 8603 } |
| 8543 Source librarySource = library.librarySource; | 8604 Source librarySource = library.librarySource; |
| 8544 if (!library.explicitlyImportsCore && | 8605 if (!library.explicitlyImportsCore && |
| 8545 _coreLibrarySource != librarySource) { | 8606 _coreLibrarySource != librarySource) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8619 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 8680 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 8620 */ | 8681 */ |
| 8621 void _buildTypeHierarchies() { | 8682 void _buildTypeHierarchies() { |
| 8622 PerformanceStatistics.resolve.makeCurrentWhile(() { | 8683 PerformanceStatistics.resolve.makeCurrentWhile(() { |
| 8623 for (ResolvableLibrary library in _librariesInCycle) { | 8684 for (ResolvableLibrary library in _librariesInCycle) { |
| 8624 for (ResolvableCompilationUnit unit | 8685 for (ResolvableCompilationUnit unit |
| 8625 in library.resolvableCompilationUnits) { | 8686 in library.resolvableCompilationUnits) { |
| 8626 Source source = unit.source; | 8687 Source source = unit.source; |
| 8627 CompilationUnit ast = unit.compilationUnit; | 8688 CompilationUnit ast = unit.compilationUnit; |
| 8628 TypeResolverVisitor visitor = new TypeResolverVisitor( | 8689 TypeResolverVisitor visitor = new TypeResolverVisitor( |
| 8629 library.libraryElement, source, _typeProvider, | 8690 library.libraryElement, |
| 8691 source, |
| 8692 _typeProvider, |
| 8630 library.libraryScope.errorListener, | 8693 library.libraryScope.errorListener, |
| 8631 nameScope: library.libraryScope); | 8694 nameScope: library.libraryScope); |
| 8632 ast.accept(visitor); | 8695 ast.accept(visitor); |
| 8633 } | 8696 } |
| 8634 } | 8697 } |
| 8635 }); | 8698 }); |
| 8636 } | 8699 } |
| 8637 | 8700 |
| 8638 /** | 8701 /** |
| 8639 * Return an array containing the lexical identifiers associated with the node
s in the given list. | 8702 * Return an array containing the lexical identifiers associated with the node
s in the given list. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 8669 computer.computeValues(); | 8732 computer.computeValues(); |
| 8670 // As a temporary workaround for issue 21572, run ConstantVerifier now. | 8733 // As a temporary workaround for issue 21572, run ConstantVerifier now. |
| 8671 // TODO(paulberry): remove this workaround once issue 21572 is fixed. | 8734 // TODO(paulberry): remove this workaround once issue 21572 is fixed. |
| 8672 for (ResolvableLibrary library in _librariesInCycle) { | 8735 for (ResolvableLibrary library in _librariesInCycle) { |
| 8673 for (ResolvableCompilationUnit unit | 8736 for (ResolvableCompilationUnit unit |
| 8674 in library.resolvableCompilationUnits) { | 8737 in library.resolvableCompilationUnits) { |
| 8675 CompilationUnit ast = unit.compilationUnit; | 8738 CompilationUnit ast = unit.compilationUnit; |
| 8676 ErrorReporter errorReporter = | 8739 ErrorReporter errorReporter = |
| 8677 new ErrorReporter(_errorListener, unit.source); | 8740 new ErrorReporter(_errorListener, unit.source); |
| 8678 ConstantVerifier constantVerifier = new ConstantVerifier( | 8741 ConstantVerifier constantVerifier = new ConstantVerifier( |
| 8679 errorReporter, library.libraryElement, _typeProvider, | 8742 errorReporter, |
| 8743 library.libraryElement, |
| 8744 _typeProvider, |
| 8680 analysisContext.declaredVariables); | 8745 analysisContext.declaredVariables); |
| 8681 ast.accept(constantVerifier); | 8746 ast.accept(constantVerifier); |
| 8682 } | 8747 } |
| 8683 } | 8748 } |
| 8684 }); | 8749 }); |
| 8685 } | 8750 } |
| 8686 | 8751 |
| 8687 /** | 8752 /** |
| 8688 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 8753 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 8689 * | 8754 * |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8807 if (existing is PrefixElement) { | 8872 if (existing is PrefixElement) { |
| 8808 // TODO(scheglov) consider providing actual 'nameOffset' from the | 8873 // TODO(scheglov) consider providing actual 'nameOffset' from the |
| 8809 // synthetic accessor | 8874 // synthetic accessor |
| 8810 int offset = duplicate.nameOffset; | 8875 int offset = duplicate.nameOffset; |
| 8811 if (duplicate is PropertyAccessorElement) { | 8876 if (duplicate is PropertyAccessorElement) { |
| 8812 PropertyAccessorElement accessor = duplicate; | 8877 PropertyAccessorElement accessor = duplicate; |
| 8813 if (accessor.isSynthetic) { | 8878 if (accessor.isSynthetic) { |
| 8814 offset = accessor.variable.nameOffset; | 8879 offset = accessor.variable.nameOffset; |
| 8815 } | 8880 } |
| 8816 } | 8881 } |
| 8817 return new AnalysisError(duplicate.source, offset, | 8882 return new AnalysisError( |
| 8883 duplicate.source, |
| 8884 offset, |
| 8818 duplicate.displayName.length, | 8885 duplicate.displayName.length, |
| 8819 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, | 8886 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, |
| 8820 [existing.displayName]); | 8887 [existing.displayName]); |
| 8821 } | 8888 } |
| 8822 return super.getErrorForDuplicate(existing, duplicate); | 8889 return super.getErrorForDuplicate(existing, duplicate); |
| 8823 } | 8890 } |
| 8824 | 8891 |
| 8825 /** | 8892 /** |
| 8826 * Add to this scope all of the public top-level names that are defined in the
given compilation | 8893 * Add to this scope all of the public top-level names that are defined in the
given compilation |
| 8827 * unit. | 8894 * unit. |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9289 // | 9356 // |
| 9290 // The exported library will be null if the URI does not reference a | 9357 // The exported library will be null if the URI does not reference a |
| 9291 // valid library. | 9358 // valid library. |
| 9292 // | 9359 // |
| 9293 HashMap<String, Element> exportedNames = | 9360 HashMap<String, Element> exportedNames = |
| 9294 _createExportMapping(exportedLibrary, visitedElements); | 9361 _createExportMapping(exportedLibrary, visitedElements); |
| 9295 exportedNames = _applyCombinators(exportedNames, element.combinators); | 9362 exportedNames = _applyCombinators(exportedNames, element.combinators); |
| 9296 definedNames.addAll(exportedNames); | 9363 definedNames.addAll(exportedNames); |
| 9297 } | 9364 } |
| 9298 } | 9365 } |
| 9299 _addAllFromNamespace(definedNames, | 9366 _addAllFromNamespace( |
| 9367 definedNames, |
| 9300 (library.context as InternalAnalysisContext) | 9368 (library.context as InternalAnalysisContext) |
| 9301 .getPublicNamespace(library)); | 9369 .getPublicNamespace(library)); |
| 9302 return definedNames; | 9370 return definedNames; |
| 9303 } finally { | 9371 } finally { |
| 9304 visitedElements.remove(library); | 9372 visitedElements.remove(library); |
| 9305 } | 9373 } |
| 9306 } | 9374 } |
| 9307 | 9375 |
| 9308 /** | 9376 /** |
| 9309 * Hide all of the given names by removing them from the given collection of d
efined names. | 9377 * Hide all of the given names by removing them from the given collection of d
efined names. |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10013 * first be visited. If `null` or unspecified, a new [LibraryScope] will be | 10081 * first be visited. If `null` or unspecified, a new [LibraryScope] will be |
| 10014 * created based on [definingLibrary] and [typeProvider]. | 10082 * created based on [definingLibrary] and [typeProvider]. |
| 10015 * [inheritanceManager] is used to perform inheritance lookups. If `null` or | 10083 * [inheritanceManager] is used to perform inheritance lookups. If `null` or |
| 10016 * unspecified, a new [InheritanceManager] will be created based on | 10084 * unspecified, a new [InheritanceManager] will be created based on |
| 10017 * [definingLibrary]. | 10085 * [definingLibrary]. |
| 10018 * [typeAnalyzerFactory] is used to create the type analyzer. If `null` or | 10086 * [typeAnalyzerFactory] is used to create the type analyzer. If `null` or |
| 10019 * unspecified, a type analyzer of type [StaticTypeAnalyzer] will be created. | 10087 * unspecified, a type analyzer of type [StaticTypeAnalyzer] will be created. |
| 10020 */ | 10088 */ |
| 10021 ResolverVisitor(LibraryElement definingLibrary, Source source, | 10089 ResolverVisitor(LibraryElement definingLibrary, Source source, |
| 10022 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 10090 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 10023 {Scope nameScope, InheritanceManager inheritanceManager, | 10091 {Scope nameScope, |
| 10092 InheritanceManager inheritanceManager, |
| 10024 StaticTypeAnalyzerFactory typeAnalyzerFactory}) | 10093 StaticTypeAnalyzerFactory typeAnalyzerFactory}) |
| 10025 : super(definingLibrary, source, typeProvider, errorListener, | 10094 : super(definingLibrary, source, typeProvider, errorListener, |
| 10026 nameScope: nameScope) { | 10095 nameScope: nameScope) { |
| 10027 if (inheritanceManager == null) { | 10096 if (inheritanceManager == null) { |
| 10028 this._inheritanceManager = new InheritanceManager(definingLibrary); | 10097 this._inheritanceManager = new InheritanceManager(definingLibrary); |
| 10029 } else { | 10098 } else { |
| 10030 this._inheritanceManager = inheritanceManager; | 10099 this._inheritanceManager = inheritanceManager; |
| 10031 } | 10100 } |
| 10032 this.elementResolver = new ElementResolver(this); | 10101 this.elementResolver = new ElementResolver(this); |
| 10033 if (typeAnalyzerFactory == null) { | 10102 if (typeAnalyzerFactory == null) { |
| 10034 this.typeAnalyzer = new StaticTypeAnalyzer(this); | 10103 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 10035 } else { | 10104 } else { |
| 10036 this.typeAnalyzer = typeAnalyzerFactory(this); | 10105 this.typeAnalyzer = typeAnalyzerFactory(this); |
| 10037 } | 10106 } |
| 10038 } | 10107 } |
| 10039 | 10108 |
| 10040 /** | 10109 /** |
| 10041 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 10110 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 10042 * | 10111 * |
| 10043 * @param library the library containing the compilation unit being resolved | 10112 * @param library the library containing the compilation unit being resolved |
| 10044 * @param source the source representing the compilation unit being visited | 10113 * @param source the source representing the compilation unit being visited |
| 10045 * @param typeProvider the object used to access the types from the core libra
ry | 10114 * @param typeProvider the object used to access the types from the core libra
ry |
| 10046 * | 10115 * |
| 10047 * Deprecated. Please use unnamed constructor instead. | 10116 * Deprecated. Please use unnamed constructor instead. |
| 10048 */ | 10117 */ |
| 10049 @deprecated | 10118 @deprecated |
| 10050 ResolverVisitor.con1( | 10119 ResolverVisitor.con1( |
| 10051 Library library, Source source, TypeProvider typeProvider, | 10120 Library library, Source source, TypeProvider typeProvider, |
| 10052 {StaticTypeAnalyzerFactory typeAnalyzerFactory}) | 10121 {StaticTypeAnalyzerFactory typeAnalyzerFactory}) |
| 10053 : this( | 10122 : this( |
| 10054 library.libraryElement, source, typeProvider, library.errorListener, | 10123 library.libraryElement, source, typeProvider, library.errorListener, |
| 10055 nameScope: library.libraryScope, | 10124 nameScope: library.libraryScope, |
| 10056 inheritanceManager: library.inheritanceManager, | 10125 inheritanceManager: library.inheritanceManager, |
| 10057 typeAnalyzerFactory: typeAnalyzerFactory); | 10126 typeAnalyzerFactory: typeAnalyzerFactory); |
| 10058 | 10127 |
| 10059 /** | 10128 /** |
| 10060 * Return the element representing the function containing the current node, o
r `null` if | 10129 * Return the element representing the function containing the current node, o
r `null` if |
| 10061 * the current node is not contained in a function. | 10130 * the current node is not contained in a function. |
| 10062 * | 10131 * |
| 10063 * @return the element representing the function containing the current node | 10132 * @return the element representing the function containing the current node |
| 10064 */ | 10133 */ |
| 10065 ExecutableElement get enclosingFunction => _enclosingFunction; | 10134 ExecutableElement get enclosingFunction => _enclosingFunction; |
| 10066 | 10135 |
| 10067 /** | 10136 /** |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10703 SimpleIdentifier identifier = node.identifier; | 10772 SimpleIdentifier identifier = node.identifier; |
| 10704 safelyVisit(loopVariable); | 10773 safelyVisit(loopVariable); |
| 10705 safelyVisit(identifier); | 10774 safelyVisit(identifier); |
| 10706 Statement body = node.body; | 10775 Statement body = node.body; |
| 10707 if (body != null) { | 10776 if (body != null) { |
| 10708 _overrideManager.enterScope(); | 10777 _overrideManager.enterScope(); |
| 10709 try { | 10778 try { |
| 10710 if (loopVariable != null && iterable != null) { | 10779 if (loopVariable != null && iterable != null) { |
| 10711 LocalVariableElement loopElement = loopVariable.element; | 10780 LocalVariableElement loopElement = loopVariable.element; |
| 10712 if (loopElement != null) { | 10781 if (loopElement != null) { |
| 10713 DartType iteratorElementType = _getIteratorElementType(iterable); | 10782 DartType propagatedType = null; |
| 10714 overrideVariable(loopElement, iteratorElementType, true); | 10783 if (node.awaitKeyword == null) { |
| 10715 _recordPropagatedType(loopVariable.identifier, iteratorElementType); | 10784 propagatedType = _getIteratorElementType(iterable); |
| 10785 } else { |
| 10786 propagatedType = _getStreamElementType(iterable); |
| 10787 } |
| 10788 if (propagatedType != null) { |
| 10789 overrideVariable(loopElement, propagatedType, true); |
| 10790 _recordPropagatedType(loopVariable.identifier, propagatedType); |
| 10791 } |
| 10716 } | 10792 } |
| 10717 } else if (identifier != null && iterable != null) { | 10793 } else if (identifier != null && iterable != null) { |
| 10718 Element identifierElement = identifier.staticElement; | 10794 Element identifierElement = identifier.staticElement; |
| 10719 if (identifierElement is VariableElement) { | 10795 if (identifierElement is VariableElement) { |
| 10720 DartType iteratorElementType = _getIteratorElementType(iterable); | 10796 DartType iteratorElementType = _getIteratorElementType(iterable); |
| 10721 overrideVariable(identifierElement, iteratorElementType, true); | 10797 overrideVariable(identifierElement, iteratorElementType, true); |
| 10722 _recordPropagatedType(identifier, iteratorElementType); | 10798 _recordPropagatedType(identifier, iteratorElementType); |
| 10723 } | 10799 } |
| 10724 } | 10800 } |
| 10725 visitStatementInScope(body); | 10801 visitStatementInScope(body); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11087 */ | 11163 */ |
| 11088 void _clearTypePromotionsIfPotentiallyMutatedIn(AstNode target) { | 11164 void _clearTypePromotionsIfPotentiallyMutatedIn(AstNode target) { |
| 11089 for (Element element in _promoteManager.promotedElements) { | 11165 for (Element element in _promoteManager.promotedElements) { |
| 11090 if (_isVariablePotentiallyMutatedIn(element, target)) { | 11166 if (_isVariablePotentiallyMutatedIn(element, target)) { |
| 11091 _promoteManager.setType(element, null); | 11167 _promoteManager.setType(element, null); |
| 11092 } | 11168 } |
| 11093 } | 11169 } |
| 11094 } | 11170 } |
| 11095 | 11171 |
| 11096 /** | 11172 /** |
| 11097 * The given expression is the expression used to compute the iterator for a f
or-each statement. | 11173 * The given expression is the expression used to compute the iterator for a |
| 11098 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return | 11174 * for-each statement. Attempt to compute the type of objects that will be |
| 11099 * that type. Return `null` if the type could not be determined. | 11175 * assigned to the loop variable and return that type. Return `null` if the |
| 11100 * | 11176 * type could not be determined. The [iteratorExpression] is the expression |
| 11101 * @param iterator the iterator for a for-each statement | 11177 * that will return the Iterable being iterated over. |
| 11102 * @return the type of objects that will be assigned to the loop variable | |
| 11103 */ | 11178 */ |
| 11104 DartType _getIteratorElementType(Expression iteratorExpression) { | 11179 DartType _getIteratorElementType(Expression iteratorExpression) { |
| 11105 DartType expressionType = iteratorExpression.bestType; | 11180 DartType expressionType = iteratorExpression.bestType; |
| 11106 if (expressionType is InterfaceType) { | 11181 if (expressionType is InterfaceType) { |
| 11107 InterfaceType interfaceType = expressionType; | 11182 InterfaceType interfaceType = expressionType; |
| 11108 FunctionType iteratorFunction = | 11183 FunctionType iteratorFunction = |
| 11109 _inheritanceManager.lookupMemberType(interfaceType, "iterator"); | 11184 _inheritanceManager.lookupMemberType(interfaceType, "iterator"); |
| 11110 if (iteratorFunction == null) { | 11185 if (iteratorFunction == null) { |
| 11111 // TODO(brianwilkerson) Should we report this error? | 11186 // TODO(brianwilkerson) Should we report this error? |
| 11112 return null; | 11187 return null; |
| 11113 } | 11188 } |
| 11114 DartType iteratorType = iteratorFunction.returnType; | 11189 DartType iteratorType = iteratorFunction.returnType; |
| 11115 if (iteratorType is InterfaceType) { | 11190 if (iteratorType is InterfaceType) { |
| 11116 InterfaceType iteratorInterfaceType = iteratorType; | 11191 InterfaceType iteratorInterfaceType = iteratorType; |
| 11117 FunctionType currentFunction = _inheritanceManager.lookupMemberType( | 11192 FunctionType currentFunction = _inheritanceManager.lookupMemberType( |
| 11118 iteratorInterfaceType, "current"); | 11193 iteratorInterfaceType, "current"); |
| 11119 if (currentFunction == null) { | 11194 if (currentFunction == null) { |
| 11120 // TODO(brianwilkerson) Should we report this error? | 11195 // TODO(brianwilkerson) Should we report this error? |
| 11121 return null; | 11196 return null; |
| 11122 } | 11197 } |
| 11123 return currentFunction.returnType; | 11198 return currentFunction.returnType; |
| 11124 } | 11199 } |
| 11125 } | 11200 } |
| 11126 return null; | 11201 return null; |
| 11127 } | 11202 } |
| 11128 | 11203 |
| 11129 /** | 11204 /** |
| 11205 * The given expression is the expression used to compute the stream for an |
| 11206 * asyncronous for-each statement. Attempt to compute the type of objects that |
| 11207 * will be assigned to the loop variable and return that type. Return `null` |
| 11208 * if the type could not be determined. The [streamExpression] is the |
| 11209 * expression that will return the stream being iterated over. |
| 11210 */ |
| 11211 DartType _getStreamElementType(Expression streamExpression) { |
| 11212 DartType streamType = streamExpression.bestType; |
| 11213 if (streamType is InterfaceType) { |
| 11214 FunctionType listenFunction = |
| 11215 _inheritanceManager.lookupMemberType(streamType, "listen"); |
| 11216 if (listenFunction == null) { |
| 11217 return null; |
| 11218 } |
| 11219 List<ParameterElement> listenParameters = listenFunction.parameters; |
| 11220 if (listenParameters == null || listenParameters.length < 1) { |
| 11221 return null; |
| 11222 } |
| 11223 DartType onDataType = listenParameters[0].type; |
| 11224 if (onDataType is FunctionType) { |
| 11225 List<ParameterElement> onDataParameters = onDataType.parameters; |
| 11226 if (onDataParameters == null || onDataParameters.length < 1) { |
| 11227 return null; |
| 11228 } |
| 11229 DartType eventType = onDataParameters[0].type; |
| 11230 if (eventType.element == streamType.typeParameters[0]) { |
| 11231 return streamType.typeArguments[0]; |
| 11232 } |
| 11233 } |
| 11234 } |
| 11235 return null; |
| 11236 } |
| 11237 |
| 11238 /** |
| 11130 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters
types and its | 11239 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters
types and its |
| 11131 * required type is [FunctionType], then infer parameters types from [Function
Type]. | 11240 * required type is [FunctionType], then infer parameters types from [Function
Type]. |
| 11132 */ | 11241 */ |
| 11133 void _inferFunctionExpressionParametersTypes( | 11242 void _inferFunctionExpressionParametersTypes( |
| 11134 Expression mayBeClosure, DartType mayByFunctionType) { | 11243 Expression mayBeClosure, DartType mayByFunctionType) { |
| 11135 // prepare closure | 11244 // prepare closure |
| 11136 if (mayBeClosure is! FunctionExpression) { | 11245 if (mayBeClosure is! FunctionExpression) { |
| 11137 return; | 11246 return; |
| 11138 } | 11247 } |
| 11139 FunctionExpression closure = mayBeClosure as FunctionExpression; | 11248 FunctionExpression closure = mayBeClosure as FunctionExpression; |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11528 * @param existing the first element to be declared with the conflicting name | 11637 * @param existing the first element to be declared with the conflicting name |
| 11529 * @param duplicate another element declared with the conflicting name | 11638 * @param duplicate another element declared with the conflicting name |
| 11530 * @return the error code used to report duplicate names within a scope | 11639 * @return the error code used to report duplicate names within a scope |
| 11531 */ | 11640 */ |
| 11532 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 11641 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
| 11533 // TODO(brianwilkerson) Customize the error message based on the types of | 11642 // TODO(brianwilkerson) Customize the error message based on the types of |
| 11534 // elements that share the same name. | 11643 // elements that share the same name. |
| 11535 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being | 11644 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being |
| 11536 // generated. | 11645 // generated. |
| 11537 Source source = duplicate.source; | 11646 Source source = duplicate.source; |
| 11538 return new AnalysisError(source, duplicate.nameOffset, | 11647 return new AnalysisError( |
| 11539 duplicate.displayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, | 11648 source, |
| 11649 duplicate.nameOffset, |
| 11650 duplicate.displayName.length, |
| 11651 CompileTimeErrorCode.DUPLICATE_DEFINITION, |
| 11540 [existing.displayName]); | 11652 [existing.displayName]); |
| 11541 } | 11653 } |
| 11542 | 11654 |
| 11543 /** | 11655 /** |
| 11544 * Return the source that contains the given identifier, or the source associa
ted with this scope | 11656 * Return the source that contains the given identifier, or the source associa
ted with this scope |
| 11545 * if the source containing the identifier could not be determined. | 11657 * if the source containing the identifier could not be determined. |
| 11546 * | 11658 * |
| 11547 * @param identifier the identifier whose source is to be returned | 11659 * @param identifier the identifier whose source is to be returned |
| 11548 * @return the source that contains the given identifier | 11660 * @return the source that contains the given identifier |
| 11549 */ | 11661 */ |
| (...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13223 InterfaceType get iterableType => _iterableType; | 13335 InterfaceType get iterableType => _iterableType; |
| 13224 | 13336 |
| 13225 @override | 13337 @override |
| 13226 InterfaceType get listType => _listType; | 13338 InterfaceType get listType => _listType; |
| 13227 | 13339 |
| 13228 @override | 13340 @override |
| 13229 InterfaceType get mapType => _mapType; | 13341 InterfaceType get mapType => _mapType; |
| 13230 | 13342 |
| 13231 @override | 13343 @override |
| 13232 List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[ | 13344 List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[ |
| 13233 nullType, | 13345 nullType, |
| 13234 numType, | 13346 numType, |
| 13235 intType, | 13347 intType, |
| 13236 doubleType, | 13348 doubleType, |
| 13237 boolType, | 13349 boolType, |
| 13238 stringType | 13350 stringType |
| 13239 ]; | 13351 ]; |
| 13240 | 13352 |
| 13241 @override | 13353 @override |
| 13242 DartObjectImpl get nullObject { | 13354 DartObjectImpl get nullObject { |
| 13243 if (_nullObject == null) { | 13355 if (_nullObject == null) { |
| 13244 _nullObject = new DartObjectImpl(nullType, NullState.NULL_STATE); | 13356 _nullObject = new DartObjectImpl(nullType, NullState.NULL_STATE); |
| 13245 } | 13357 } |
| 13246 return _nullObject; | 13358 return _nullObject; |
| 13247 } | 13359 } |
| 13248 | 13360 |
| 13249 @override | 13361 @override |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13360 * [errorListener] is the error listener that will be informed of any errors | 13472 * [errorListener] is the error listener that will be informed of any errors |
| 13361 * that are found during resolution. | 13473 * that are found during resolution. |
| 13362 * [nameScope] is the scope used to resolve identifiers in the node that will | 13474 * [nameScope] is the scope used to resolve identifiers in the node that will |
| 13363 * first be visited. If `null` or unspecified, a new [LibraryScope] will be | 13475 * first be visited. If `null` or unspecified, a new [LibraryScope] will be |
| 13364 * created based on [definingLibrary] and [typeProvider]. | 13476 * created based on [definingLibrary] and [typeProvider]. |
| 13365 */ | 13477 */ |
| 13366 TypeResolverVisitor(LibraryElement definingLibrary, Source source, | 13478 TypeResolverVisitor(LibraryElement definingLibrary, Source source, |
| 13367 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 13479 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 13368 {Scope nameScope}) | 13480 {Scope nameScope}) |
| 13369 : super(definingLibrary, source, typeProvider, errorListener, | 13481 : super(definingLibrary, source, typeProvider, errorListener, |
| 13370 nameScope: nameScope) { | 13482 nameScope: nameScope) { |
| 13371 _dynamicType = typeProvider.dynamicType; | 13483 _dynamicType = typeProvider.dynamicType; |
| 13372 _undefinedType = typeProvider.undefinedType; | 13484 _undefinedType = typeProvider.undefinedType; |
| 13373 } | 13485 } |
| 13374 | 13486 |
| 13375 @override | 13487 @override |
| 13376 Object visitAnnotation(Annotation node) { | 13488 Object visitAnnotation(Annotation node) { |
| 13377 // | 13489 // |
| 13378 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" | 13490 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" |
| 13379 // resolves to the proxy annotation in dart.core, then create create the | 13491 // resolves to the proxy annotation in dart.core, then create create the |
| 13380 // ElementAnnotationImpl and set it as the metadata on the enclosing class. | 13492 // ElementAnnotationImpl and set it as the metadata on the enclosing class. |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13756 if (name.name == null) { | 13868 if (name.name == null) { |
| 13757 PrefixedIdentifier prefixedIdentifier = | 13869 PrefixedIdentifier prefixedIdentifier = |
| 13758 typeName as PrefixedIdentifier; | 13870 typeName as PrefixedIdentifier; |
| 13759 SimpleIdentifier prefix = prefixedIdentifier.prefix; | 13871 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 13760 element = nameScope.lookup(prefix, definingLibrary); | 13872 element = nameScope.lookup(prefix, definingLibrary); |
| 13761 if (element is PrefixElement) { | 13873 if (element is PrefixElement) { |
| 13762 if (parent.parent is InstanceCreationExpression && | 13874 if (parent.parent is InstanceCreationExpression && |
| 13763 (parent.parent as InstanceCreationExpression).isConst) { | 13875 (parent.parent as InstanceCreationExpression).isConst) { |
| 13764 // If, if this is a const expression, then generate a | 13876 // If, if this is a const expression, then generate a |
| 13765 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. | 13877 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. |
| 13766 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, | 13878 reportErrorForNode( |
| 13879 CompileTimeErrorCode.CONST_WITH_NON_TYPE, |
| 13767 prefixedIdentifier.identifier, | 13880 prefixedIdentifier.identifier, |
| 13768 [prefixedIdentifier.identifier.name]); | 13881 [prefixedIdentifier.identifier.name]); |
| 13769 } else { | 13882 } else { |
| 13770 // Else, if this expression is a new expression, report a | 13883 // Else, if this expression is a new expression, report a |
| 13771 // NEW_WITH_NON_TYPE warning. | 13884 // NEW_WITH_NON_TYPE warning. |
| 13772 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, | 13885 reportErrorForNode( |
| 13886 StaticWarningCode.NEW_WITH_NON_TYPE, |
| 13773 prefixedIdentifier.identifier, | 13887 prefixedIdentifier.identifier, |
| 13774 [prefixedIdentifier.identifier.name]); | 13888 [prefixedIdentifier.identifier.name]); |
| 13775 } | 13889 } |
| 13776 _setElement(prefix, element); | 13890 _setElement(prefix, element); |
| 13777 return null; | 13891 return null; |
| 13778 } else if (element != null) { | 13892 } else if (element != null) { |
| 13779 // | 13893 // |
| 13780 // Rewrite the constructor name. The parser, when it sees a | 13894 // Rewrite the constructor name. The parser, when it sees a |
| 13781 // constructor named "a.b", cannot tell whether "a" is a prefix and | 13895 // constructor named "a.b", cannot tell whether "a" is a prefix and |
| 13782 // "b" is a class name, or whether "a" is a class name and "b" is a | 13896 // "b" is a class name, or whether "a" is a class name and "b" is a |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13940 if (argumentCount == parameterCount) { | 14054 if (argumentCount == parameterCount) { |
| 13941 for (int i = 0; i < parameterCount; i++) { | 14055 for (int i = 0; i < parameterCount; i++) { |
| 13942 TypeName argumentTypeName = arguments[i]; | 14056 TypeName argumentTypeName = arguments[i]; |
| 13943 DartType argumentType = _getType(argumentTypeName); | 14057 DartType argumentType = _getType(argumentTypeName); |
| 13944 if (argumentType == null) { | 14058 if (argumentType == null) { |
| 13945 argumentType = _dynamicType; | 14059 argumentType = _dynamicType; |
| 13946 } | 14060 } |
| 13947 typeArguments[i] = argumentType; | 14061 typeArguments[i] = argumentType; |
| 13948 } | 14062 } |
| 13949 } else { | 14063 } else { |
| 13950 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, [ | 14064 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, |
| 13951 typeName.name, | 14065 [typeName.name, parameterCount, argumentCount]); |
| 13952 parameterCount, | |
| 13953 argumentCount | |
| 13954 ]); | |
| 13955 for (int i = 0; i < parameterCount; i++) { | 14066 for (int i = 0; i < parameterCount; i++) { |
| 13956 typeArguments[i] = _dynamicType; | 14067 typeArguments[i] = _dynamicType; |
| 13957 } | 14068 } |
| 13958 } | 14069 } |
| 13959 if (type is InterfaceTypeImpl) { | 14070 if (type is InterfaceTypeImpl) { |
| 13960 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; | 14071 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; |
| 13961 type = interfaceType.substitute4(typeArguments); | 14072 type = interfaceType.substitute4(typeArguments); |
| 13962 } else if (type is FunctionTypeImpl) { | 14073 } else if (type is FunctionTypeImpl) { |
| 13963 FunctionTypeImpl functionType = type as FunctionTypeImpl; | 14074 FunctionTypeImpl functionType = type as FunctionTypeImpl; |
| 13964 type = functionType.substitute3(typeArguments); | 14075 type = functionType.substitute3(typeArguments); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14308 * given class element. | 14419 * given class element. |
| 14309 * | 14420 * |
| 14310 * @param classElement the class element with which the mixin and interface ty
pes are to be | 14421 * @param classElement the class element with which the mixin and interface ty
pes are to be |
| 14311 * associated | 14422 * associated |
| 14312 * @param withClause the with clause to be resolved | 14423 * @param withClause the with clause to be resolved |
| 14313 * @param implementsClause the implements clause to be resolved | 14424 * @param implementsClause the implements clause to be resolved |
| 14314 */ | 14425 */ |
| 14315 void _resolve(ClassElementImpl classElement, WithClause withClause, | 14426 void _resolve(ClassElementImpl classElement, WithClause withClause, |
| 14316 ImplementsClause implementsClause) { | 14427 ImplementsClause implementsClause) { |
| 14317 if (withClause != null) { | 14428 if (withClause != null) { |
| 14318 List<InterfaceType> mixinTypes = _resolveTypes(withClause.mixinTypes, | 14429 List<InterfaceType> mixinTypes = _resolveTypes( |
| 14430 withClause.mixinTypes, |
| 14319 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, | 14431 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, |
| 14320 CompileTimeErrorCode.MIXIN_OF_ENUM, | 14432 CompileTimeErrorCode.MIXIN_OF_ENUM, |
| 14321 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); | 14433 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); |
| 14322 if (classElement != null) { | 14434 if (classElement != null) { |
| 14323 classElement.mixins = mixinTypes; | 14435 classElement.mixins = mixinTypes; |
| 14324 classElement.withClauseRange = | 14436 classElement.withClauseRange = |
| 14325 new SourceRange(withClause.offset, withClause.length); | 14437 new SourceRange(withClause.offset, withClause.length); |
| 14326 } | 14438 } |
| 14327 } | 14439 } |
| 14328 if (implementsClause != null) { | 14440 if (implementsClause != null) { |
| 14329 NodeList<TypeName> interfaces = implementsClause.interfaces; | 14441 NodeList<TypeName> interfaces = implementsClause.interfaces; |
| 14330 List<InterfaceType> interfaceTypes = _resolveTypes(interfaces, | 14442 List<InterfaceType> interfaceTypes = _resolveTypes( |
| 14443 interfaces, |
| 14331 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, | 14444 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, |
| 14332 CompileTimeErrorCode.IMPLEMENTS_ENUM, | 14445 CompileTimeErrorCode.IMPLEMENTS_ENUM, |
| 14333 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); | 14446 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); |
| 14334 if (classElement != null) { | 14447 if (classElement != null) { |
| 14335 classElement.interfaces = interfaceTypes; | 14448 classElement.interfaces = interfaceTypes; |
| 14336 } | 14449 } |
| 14337 // TODO(brianwilkerson) Move the following checks to ErrorVerifier. | 14450 // TODO(brianwilkerson) Move the following checks to ErrorVerifier. |
| 14338 int count = interfaces.length; | 14451 int count = interfaces.length; |
| 14339 List<bool> detectedRepeatOnIndex = new List<bool>.filled(count, false); | 14452 List<bool> detectedRepeatOnIndex = new List<bool>.filled(count, false); |
| 14340 for (int i = 0; i < detectedRepeatOnIndex.length; i++) { | 14453 for (int i = 0; i < detectedRepeatOnIndex.length; i++) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14395 /** | 14508 /** |
| 14396 * Resolve the types in the given list of type names. | 14509 * Resolve the types in the given list of type names. |
| 14397 * | 14510 * |
| 14398 * @param typeNames the type names to be resolved | 14511 * @param typeNames the type names to be resolved |
| 14399 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 14512 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 14400 * a type | 14513 * a type |
| 14401 * @param enumTypeError the error to produce if the type name is defined to be
an enum | 14514 * @param enumTypeError the error to produce if the type name is defined to be
an enum |
| 14402 * @param dynamicTypeError the error to produce if the type name is "dynamic" | 14515 * @param dynamicTypeError the error to produce if the type name is "dynamic" |
| 14403 * @return an array containing all of the types that were resolved. | 14516 * @return an array containing all of the types that were resolved. |
| 14404 */ | 14517 */ |
| 14405 List<InterfaceType> _resolveTypes(NodeList<TypeName> typeNames, | 14518 List<InterfaceType> _resolveTypes( |
| 14406 ErrorCode nonTypeError, ErrorCode enumTypeError, | 14519 NodeList<TypeName> typeNames, |
| 14520 ErrorCode nonTypeError, |
| 14521 ErrorCode enumTypeError, |
| 14407 ErrorCode dynamicTypeError) { | 14522 ErrorCode dynamicTypeError) { |
| 14408 List<InterfaceType> types = new List<InterfaceType>(); | 14523 List<InterfaceType> types = new List<InterfaceType>(); |
| 14409 for (TypeName typeName in typeNames) { | 14524 for (TypeName typeName in typeNames) { |
| 14410 InterfaceType type = | 14525 InterfaceType type = |
| 14411 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); | 14526 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); |
| 14412 if (type != null) { | 14527 if (type != null) { |
| 14413 types.add(type); | 14528 types.add(type); |
| 14414 } | 14529 } |
| 14415 } | 14530 } |
| 14416 return types; | 14531 return types; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14628 final UsedLocalElements _usedElements; | 14743 final UsedLocalElements _usedElements; |
| 14629 | 14744 |
| 14630 /** | 14745 /** |
| 14631 * Create a new instance of the [UnusedLocalElementsVerifier]. | 14746 * Create a new instance of the [UnusedLocalElementsVerifier]. |
| 14632 */ | 14747 */ |
| 14633 UnusedLocalElementsVerifier(this._errorListener, this._usedElements); | 14748 UnusedLocalElementsVerifier(this._errorListener, this._usedElements); |
| 14634 | 14749 |
| 14635 @override | 14750 @override |
| 14636 visitClassElement(ClassElement element) { | 14751 visitClassElement(ClassElement element) { |
| 14637 if (!_isUsedElement(element)) { | 14752 if (!_isUsedElement(element)) { |
| 14638 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ | 14753 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, |
| 14639 element.kind.displayName, | 14754 [element.kind.displayName, element.displayName]); |
| 14640 element.displayName | |
| 14641 ]); | |
| 14642 } | 14755 } |
| 14643 super.visitClassElement(element); | 14756 super.visitClassElement(element); |
| 14644 } | 14757 } |
| 14645 | 14758 |
| 14646 @override | 14759 @override |
| 14647 visitFieldElement(FieldElement element) { | 14760 visitFieldElement(FieldElement element) { |
| 14648 if (!_isReadMember(element)) { | 14761 if (!_isReadMember(element)) { |
| 14649 _reportErrorForElement( | 14762 _reportErrorForElement( |
| 14650 HintCode.UNUSED_FIELD, element, [element.displayName]); | 14763 HintCode.UNUSED_FIELD, element, [element.displayName]); |
| 14651 } | 14764 } |
| 14652 super.visitFieldElement(element); | 14765 super.visitFieldElement(element); |
| 14653 } | 14766 } |
| 14654 | 14767 |
| 14655 @override | 14768 @override |
| 14656 visitFunctionElement(FunctionElement element) { | 14769 visitFunctionElement(FunctionElement element) { |
| 14657 if (!_isUsedElement(element)) { | 14770 if (!_isUsedElement(element)) { |
| 14658 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ | 14771 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, |
| 14659 element.kind.displayName, | 14772 [element.kind.displayName, element.displayName]); |
| 14660 element.displayName | |
| 14661 ]); | |
| 14662 } | 14773 } |
| 14663 super.visitFunctionElement(element); | 14774 super.visitFunctionElement(element); |
| 14664 } | 14775 } |
| 14665 | 14776 |
| 14666 @override | 14777 @override |
| 14667 visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 14778 visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 14668 if (!_isUsedElement(element)) { | 14779 if (!_isUsedElement(element)) { |
| 14669 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ | 14780 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, |
| 14670 element.kind.displayName, | 14781 [element.kind.displayName, element.displayName]); |
| 14671 element.displayName | |
| 14672 ]); | |
| 14673 } | 14782 } |
| 14674 super.visitFunctionTypeAliasElement(element); | 14783 super.visitFunctionTypeAliasElement(element); |
| 14675 } | 14784 } |
| 14676 | 14785 |
| 14677 @override | 14786 @override |
| 14678 visitLocalVariableElement(LocalVariableElement element) { | 14787 visitLocalVariableElement(LocalVariableElement element) { |
| 14679 if (!_isUsedElement(element) && !_isNamedUnderscore(element)) { | 14788 if (!_isUsedElement(element) && !_isNamedUnderscore(element)) { |
| 14680 HintCode errorCode; | 14789 HintCode errorCode; |
| 14681 if (_usedElements.isCatchException(element)) { | 14790 if (_usedElements.isCatchException(element)) { |
| 14682 errorCode = HintCode.UNUSED_CATCH_CLAUSE; | 14791 errorCode = HintCode.UNUSED_CATCH_CLAUSE; |
| 14683 } else if (_usedElements.isCatchStackTrace(element)) { | 14792 } else if (_usedElements.isCatchStackTrace(element)) { |
| 14684 errorCode = HintCode.UNUSED_CATCH_STACK; | 14793 errorCode = HintCode.UNUSED_CATCH_STACK; |
| 14685 } else { | 14794 } else { |
| 14686 errorCode = HintCode.UNUSED_LOCAL_VARIABLE; | 14795 errorCode = HintCode.UNUSED_LOCAL_VARIABLE; |
| 14687 } | 14796 } |
| 14688 _reportErrorForElement(errorCode, element, [element.displayName]); | 14797 _reportErrorForElement(errorCode, element, [element.displayName]); |
| 14689 } | 14798 } |
| 14690 } | 14799 } |
| 14691 | 14800 |
| 14692 @override | 14801 @override |
| 14693 visitMethodElement(MethodElement element) { | 14802 visitMethodElement(MethodElement element) { |
| 14694 if (!_isUsedMember(element)) { | 14803 if (!_isUsedMember(element)) { |
| 14695 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ | 14804 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, |
| 14696 element.kind.displayName, | 14805 [element.kind.displayName, element.displayName]); |
| 14697 element.displayName | |
| 14698 ]); | |
| 14699 } | 14806 } |
| 14700 super.visitMethodElement(element); | 14807 super.visitMethodElement(element); |
| 14701 } | 14808 } |
| 14702 | 14809 |
| 14703 @override | 14810 @override |
| 14704 visitPropertyAccessorElement(PropertyAccessorElement element) { | 14811 visitPropertyAccessorElement(PropertyAccessorElement element) { |
| 14705 if (!_isUsedMember(element)) { | 14812 if (!_isUsedMember(element)) { |
| 14706 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ | 14813 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, |
| 14707 element.kind.displayName, | 14814 [element.kind.displayName, element.displayName]); |
| 14708 element.displayName | |
| 14709 ]); | |
| 14710 } | 14815 } |
| 14711 super.visitPropertyAccessorElement(element); | 14816 super.visitPropertyAccessorElement(element); |
| 14712 } | 14817 } |
| 14713 | 14818 |
| 14714 bool _isNamedUnderscore(LocalVariableElement element) { | 14819 bool _isNamedUnderscore(LocalVariableElement element) { |
| 14715 String name = element.name; | 14820 String name = element.name; |
| 14716 if (name != null) { | 14821 if (name != null) { |
| 14717 for (int index = name.length - 1; index >= 0; --index) { | 14822 for (int index = name.length - 1; index >= 0; --index) { |
| 14718 if (name.codeUnitAt(index) != 0x5F) { | 14823 if (name.codeUnitAt(index) != 0x5F) { |
| 14719 // 0x5F => '_' | 14824 // 0x5F => '_' |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14759 } | 14864 } |
| 14760 if (_usedElements.members.contains(element.displayName)) { | 14865 if (_usedElements.members.contains(element.displayName)) { |
| 14761 return true; | 14866 return true; |
| 14762 } | 14867 } |
| 14763 return _usedElements.elements.contains(element); | 14868 return _usedElements.elements.contains(element); |
| 14764 } | 14869 } |
| 14765 | 14870 |
| 14766 void _reportErrorForElement( | 14871 void _reportErrorForElement( |
| 14767 ErrorCode errorCode, Element element, List<Object> arguments) { | 14872 ErrorCode errorCode, Element element, List<Object> arguments) { |
| 14768 if (element != null) { | 14873 if (element != null) { |
| 14769 _errorListener.onError(new AnalysisError(element.source, | 14874 _errorListener.onError(new AnalysisError( |
| 14770 element.nameOffset, element.displayName.length, errorCode, | 14875 element.source, |
| 14876 element.nameOffset, |
| 14877 element.displayName.length, |
| 14878 errorCode, |
| 14771 arguments)); | 14879 arguments)); |
| 14772 } | 14880 } |
| 14773 } | 14881 } |
| 14774 } | 14882 } |
| 14775 | 14883 |
| 14776 /** | 14884 /** |
| 14777 * A container with information about used imports prefixes and used imported | 14885 * A container with information about used imports prefixes and used imported |
| 14778 * elements. | 14886 * elements. |
| 14779 */ | 14887 */ |
| 14780 class UsedImportedElements { | 14888 class UsedImportedElements { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14888 * [errorListener] is the error listener that will be informed of any errors | 14996 * [errorListener] is the error listener that will be informed of any errors |
| 14889 * that are found during resolution. | 14997 * that are found during resolution. |
| 14890 * [nameScope] is the scope used to resolve identifiers in the node that will | 14998 * [nameScope] is the scope used to resolve identifiers in the node that will |
| 14891 * first be visited. If `null` or unspecified, a new [LibraryScope] will be | 14999 * first be visited. If `null` or unspecified, a new [LibraryScope] will be |
| 14892 * created based on [definingLibrary] and [typeProvider]. | 15000 * created based on [definingLibrary] and [typeProvider]. |
| 14893 */ | 15001 */ |
| 14894 VariableResolverVisitor(LibraryElement definingLibrary, Source source, | 15002 VariableResolverVisitor(LibraryElement definingLibrary, Source source, |
| 14895 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 15003 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 14896 {Scope nameScope}) | 15004 {Scope nameScope}) |
| 14897 : super(definingLibrary, source, typeProvider, errorListener, | 15005 : super(definingLibrary, source, typeProvider, errorListener, |
| 14898 nameScope: nameScope); | 15006 nameScope: nameScope); |
| 14899 | 15007 |
| 14900 /** | 15008 /** |
| 14901 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 15009 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 14902 * | 15010 * |
| 14903 * @param library the library containing the compilation unit being resolved | 15011 * @param library the library containing the compilation unit being resolved |
| 14904 * @param source the source representing the compilation unit being visited | 15012 * @param source the source representing the compilation unit being visited |
| 14905 * @param typeProvider the object used to access the types from the core libra
ry | 15013 * @param typeProvider the object used to access the types from the core libra
ry |
| 14906 * | 15014 * |
| 14907 * Deprecated. Please use unnamed constructor instead. | 15015 * Deprecated. Please use unnamed constructor instead. |
| 14908 */ | 15016 */ |
| 14909 @deprecated | 15017 @deprecated |
| 14910 VariableResolverVisitor.con1( | 15018 VariableResolverVisitor.con1( |
| 14911 Library library, Source source, TypeProvider typeProvider) | 15019 Library library, Source source, TypeProvider typeProvider) |
| 14912 : this( | 15020 : this( |
| 14913 library.libraryElement, source, typeProvider, library.errorListener, | 15021 library.libraryElement, source, typeProvider, library.errorListener, |
| 14914 nameScope: library.libraryScope); | 15022 nameScope: library.libraryScope); |
| 14915 | 15023 |
| 14916 @override | 15024 @override |
| 14917 Object visitExportDirective(ExportDirective node) => null; | 15025 Object visitExportDirective(ExportDirective node) => null; |
| 14918 | 15026 |
| 14919 @override | 15027 @override |
| 14920 Object visitFunctionDeclaration(FunctionDeclaration node) { | 15028 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 14921 ExecutableElement outerFunction = _enclosingFunction; | 15029 ExecutableElement outerFunction = _enclosingFunction; |
| 14922 try { | 15030 try { |
| 14923 _enclosingFunction = node.element; | 15031 _enclosingFunction = node.element; |
| 14924 return super.visitFunctionDeclaration(node); | 15032 return super.visitFunctionDeclaration(node); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15013 } | 15121 } |
| 15014 return null; | 15122 return null; |
| 15015 } | 15123 } |
| 15016 } | 15124 } |
| 15017 | 15125 |
| 15018 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor { | 15126 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor { |
| 15019 final ConstantVerifier verifier; | 15127 final ConstantVerifier verifier; |
| 15020 | 15128 |
| 15021 List<ParameterElement> parameterElements; | 15129 List<ParameterElement> parameterElements; |
| 15022 | 15130 |
| 15023 _ConstantVerifier_validateInitializerExpression(TypeProvider typeProvider, | 15131 _ConstantVerifier_validateInitializerExpression( |
| 15024 ErrorReporter errorReporter, this.verifier, this.parameterElements, | 15132 TypeProvider typeProvider, |
| 15133 ErrorReporter errorReporter, |
| 15134 this.verifier, |
| 15135 this.parameterElements, |
| 15025 DeclaredVariables declaredVariables) | 15136 DeclaredVariables declaredVariables) |
| 15026 : super(new ConstantEvaluationEngine(typeProvider, declaredVariables), | 15137 : super(new ConstantEvaluationEngine(typeProvider, declaredVariables), |
| 15027 errorReporter); | 15138 errorReporter); |
| 15028 | 15139 |
| 15029 @override | 15140 @override |
| 15030 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { | 15141 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { |
| 15031 Element element = node.staticElement; | 15142 Element element = node.staticElement; |
| 15032 for (ParameterElement parameterElement in parameterElements) { | 15143 for (ParameterElement parameterElement in parameterElements) { |
| 15033 if (identical(parameterElement, element) && parameterElement != null) { | 15144 if (identical(parameterElement, element) && parameterElement != null) { |
| 15034 DartType type = parameterElement.type; | 15145 DartType type = parameterElement.type; |
| 15035 if (type != null) { | 15146 if (type != null) { |
| 15036 if (type.isDynamic) { | 15147 if (type.isDynamic) { |
| 15037 return new DartObjectImpl( | 15148 return new DartObjectImpl( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15174 nonFields.add(node); | 15285 nonFields.add(node); |
| 15175 return null; | 15286 return null; |
| 15176 } | 15287 } |
| 15177 | 15288 |
| 15178 @override | 15289 @override |
| 15179 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15290 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15180 | 15291 |
| 15181 @override | 15292 @override |
| 15182 Object visitWithClause(WithClause node) => null; | 15293 Object visitWithClause(WithClause node) => null; |
| 15183 } | 15294 } |
| OLD | NEW |