| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 */ | 1053 */ |
| 1054 class BuildLibraryElementUtils { | 1054 class BuildLibraryElementUtils { |
| 1055 /** | 1055 /** |
| 1056 * Look through all of the compilation units defined for the given [library], | 1056 * Look through all of the compilation units defined for the given [library], |
| 1057 * looking for getters and setters that are defined in different compilation | 1057 * looking for getters and setters that are defined in different compilation |
| 1058 * units but that have the same names. If any are found, make sure that they | 1058 * units but that have the same names. If any are found, make sure that they |
| 1059 * have the same variable element. | 1059 * have the same variable element. |
| 1060 */ | 1060 */ |
| 1061 static void patchTopLevelAccessors(LibraryElementImpl library) { | 1061 static void patchTopLevelAccessors(LibraryElementImpl library) { |
| 1062 // Without parts getters/setters already share the same variable element. | 1062 // Without parts getters/setters already share the same variable element. |
| 1063 if (library.parts.isEmpty) { | 1063 List<CompilationUnitElement> parts = library.parts; |
| 1064 if (parts.isEmpty) { |
| 1064 return; | 1065 return; |
| 1065 } | 1066 } |
| 1066 // Collect getters and setters. | 1067 // Collect getters and setters. |
| 1067 HashMap<String, PropertyAccessorElement> getters = | 1068 HashMap<String, PropertyAccessorElement> getters = |
| 1068 new HashMap<String, PropertyAccessorElement>(); | 1069 new HashMap<String, PropertyAccessorElement>(); |
| 1069 List<PropertyAccessorElement> setters = <PropertyAccessorElement>[]; | 1070 List<PropertyAccessorElement> setters = <PropertyAccessorElement>[]; |
| 1070 _collectAccessors(getters, setters, library.definingCompilationUnit); | 1071 _collectAccessors(getters, setters, library.definingCompilationUnit); |
| 1071 for (CompilationUnitElement unit in library.parts) { | 1072 int partLength = parts.length; |
| 1073 for (int i = 0; i < partLength; i++) { |
| 1074 CompilationUnitElement unit = parts[i]; |
| 1072 _collectAccessors(getters, setters, unit); | 1075 _collectAccessors(getters, setters, unit); |
| 1073 } | 1076 } |
| 1074 // Move every setter to the corresponding getter's variable (if exists). | 1077 // Move every setter to the corresponding getter's variable (if exists). |
| 1075 for (PropertyAccessorElement setter in setters) { | 1078 int setterLength = setters.length; |
| 1079 for (int j = 0; j < setterLength; j++) { |
| 1080 PropertyAccessorElement setter = setters[j]; |
| 1076 PropertyAccessorElement getter = getters[setter.displayName]; | 1081 PropertyAccessorElement getter = getters[setter.displayName]; |
| 1077 if (getter != null) { | 1082 if (getter != null) { |
| 1078 TopLevelVariableElementImpl variable = getter.variable; | 1083 TopLevelVariableElementImpl variable = getter.variable; |
| 1079 TopLevelVariableElementImpl setterVariable = setter.variable; | 1084 TopLevelVariableElementImpl setterVariable = setter.variable; |
| 1080 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; | 1085 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; |
| 1081 setterUnit.replaceTopLevelVariable(setterVariable, variable); | 1086 setterUnit.replaceTopLevelVariable(setterVariable, variable); |
| 1082 variable.setter = setter; | 1087 variable.setter = setter; |
| 1083 (setter as PropertyAccessorElementImpl).variable = variable; | 1088 (setter as PropertyAccessorElementImpl).variable = variable; |
| 1084 } | 1089 } |
| 1085 } | 1090 } |
| 1086 } | 1091 } |
| 1087 | 1092 |
| 1088 /** | 1093 /** |
| 1089 * Add all of the non-synthetic [getters] and [setters] defined in the given | 1094 * Add all of the non-synthetic [getters] and [setters] defined in the given |
| 1090 * [unit] that have no corresponding accessor to one of the given collections. | 1095 * [unit] that have no corresponding accessor to one of the given collections. |
| 1091 */ | 1096 */ |
| 1092 static void _collectAccessors(Map<String, PropertyAccessorElement> getters, | 1097 static void _collectAccessors(Map<String, PropertyAccessorElement> getters, |
| 1093 List<PropertyAccessorElement> setters, CompilationUnitElement unit) { | 1098 List<PropertyAccessorElement> setters, CompilationUnitElement unit) { |
| 1094 for (PropertyAccessorElement accessor in unit.accessors) { | 1099 List<PropertyAccessorElement> accessors = unit.accessors; |
| 1100 int length = accessors.length; |
| 1101 for (int i = 0; i < length; i++) { |
| 1102 PropertyAccessorElement accessor = accessors[i]; |
| 1095 if (accessor.isGetter) { | 1103 if (accessor.isGetter) { |
| 1096 if (!accessor.isSynthetic && accessor.correspondingSetter == null) { | 1104 if (!accessor.isSynthetic && accessor.correspondingSetter == null) { |
| 1097 getters[accessor.displayName] = accessor; | 1105 getters[accessor.displayName] = accessor; |
| 1098 } | 1106 } |
| 1099 } else { | 1107 } else { |
| 1100 if (!accessor.isSynthetic && accessor.correspondingGetter == null) { | 1108 if (!accessor.isSynthetic && accessor.correspondingGetter == null) { |
| 1101 setters.add(accessor); | 1109 setters.add(accessor); |
| 1102 } | 1110 } |
| 1103 } | 1111 } |
| 1104 } | 1112 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 invalidKeys.add(key); | 1317 invalidKeys.add(key); |
| 1310 } else { | 1318 } else { |
| 1311 keys.add(result); | 1319 keys.add(result); |
| 1312 } | 1320 } |
| 1313 } else { | 1321 } else { |
| 1314 reportEqualKeys = false; | 1322 reportEqualKeys = false; |
| 1315 } | 1323 } |
| 1316 } | 1324 } |
| 1317 } | 1325 } |
| 1318 if (reportEqualKeys) { | 1326 if (reportEqualKeys) { |
| 1319 for (Expression key in invalidKeys) { | 1327 int length = invalidKeys.length; |
| 1328 for (int i = 0; i < length; i++) { |
| 1320 _errorReporter.reportErrorForNode( | 1329 _errorReporter.reportErrorForNode( |
| 1321 StaticWarningCode.EQUAL_KEYS_IN_MAP, key); | 1330 StaticWarningCode.EQUAL_KEYS_IN_MAP, invalidKeys[i]); |
| 1322 } | 1331 } |
| 1323 } | 1332 } |
| 1324 return null; | 1333 return null; |
| 1325 } | 1334 } |
| 1326 | 1335 |
| 1327 @override | 1336 @override |
| 1328 Object visitMethodDeclaration(MethodDeclaration node) { | 1337 Object visitMethodDeclaration(MethodDeclaration node) { |
| 1329 super.visitMethodDeclaration(node); | 1338 super.visitMethodDeclaration(node); |
| 1330 _validateDefaultValues(node.parameters); | 1339 _validateDefaultValues(node.parameters); |
| 1331 return null; | 1340 return null; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 } | 1472 } |
| 1464 | 1473 |
| 1465 /** | 1474 /** |
| 1466 * Report any errors in the given list. Except for special cases, use the give
n error code rather | 1475 * Report any errors in the given list. Except for special cases, use the give
n error code rather |
| 1467 * than the one reported in the error. | 1476 * than the one reported in the error. |
| 1468 * | 1477 * |
| 1469 * @param errors the errors that need to be reported | 1478 * @param errors the errors that need to be reported |
| 1470 * @param errorCode the error code to be used | 1479 * @param errorCode the error code to be used |
| 1471 */ | 1480 */ |
| 1472 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) { | 1481 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) { |
| 1473 for (AnalysisError data in errors) { | 1482 int length = errors.length; |
| 1483 for (int i = 0; i < length; i++) { |
| 1484 AnalysisError data = errors[i]; |
| 1474 ErrorCode dataErrorCode = data.errorCode; | 1485 ErrorCode dataErrorCode = data.errorCode; |
| 1475 if (identical(dataErrorCode, | 1486 if (identical(dataErrorCode, |
| 1476 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || | 1487 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION) || |
| 1477 identical( | 1488 identical( |
| 1478 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || | 1489 dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || |
| 1479 identical(dataErrorCode, | 1490 identical(dataErrorCode, |
| 1480 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || | 1491 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING) || |
| 1481 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || | 1492 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || |
| 1482 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || | 1493 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || |
| 1483 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || | 1494 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 // this catch clause is not the last in the try statement | 1984 // this catch clause is not the last in the try statement |
| 1974 CatchClause nextCatchClause = catchClauses[i + 1]; | 1985 CatchClause nextCatchClause = catchClauses[i + 1]; |
| 1975 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 1986 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 1976 int offset = nextCatchClause.offset; | 1987 int offset = nextCatchClause.offset; |
| 1977 int length = lastCatchClause.end - offset; | 1988 int length = lastCatchClause.end - offset; |
| 1978 _errorReporter.reportErrorForOffset( | 1989 _errorReporter.reportErrorForOffset( |
| 1979 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length); | 1990 HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length); |
| 1980 return null; | 1991 return null; |
| 1981 } | 1992 } |
| 1982 } | 1993 } |
| 1983 for (DartType type in visitedTypes) { | 1994 int length = visitedTypes.length; |
| 1995 for (int j = 0; j < length; j++) { |
| 1996 DartType type = visitedTypes[j]; |
| 1984 if (_typeSystem.isSubtypeOf(currentType, type)) { | 1997 if (_typeSystem.isSubtypeOf(currentType, type)) { |
| 1985 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 1998 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
| 1986 int offset = catchClause.offset; | 1999 int offset = catchClause.offset; |
| 1987 int length = lastCatchClause.end - offset; | 2000 int length = lastCatchClause.end - offset; |
| 1988 _errorReporter.reportErrorForOffset( | 2001 _errorReporter.reportErrorForOffset( |
| 1989 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, | 2002 HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, |
| 1990 offset, | 2003 offset, |
| 1991 length, | 2004 length, |
| 1992 [currentType.displayName, type.displayName]); | 2005 [currentType.displayName, type.displayName]); |
| 1993 return null; | 2006 return null; |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 | 2690 |
| 2678 /** | 2691 /** |
| 2679 * Return the element in the given list of [elements] that was created for the | 2692 * Return the element in the given list of [elements] that was created for the |
| 2680 * declaration with the given [name] at the given [offset]. Throw an | 2693 * declaration with the given [name] at the given [offset]. Throw an |
| 2681 * [ElementMismatchException] if an element corresponding to the identifier | 2694 * [ElementMismatchException] if an element corresponding to the identifier |
| 2682 * cannot be found unless [required] is `false`, in which case return `null`. | 2695 * cannot be found unless [required] is `false`, in which case return `null`. |
| 2683 */ | 2696 */ |
| 2684 Element _findWithNameAndOffset( | 2697 Element _findWithNameAndOffset( |
| 2685 List<Element> elements, AstNode node, String name, int offset, | 2698 List<Element> elements, AstNode node, String name, int offset, |
| 2686 {bool required: true}) { | 2699 {bool required: true}) { |
| 2687 for (Element element in elements) { | 2700 int length = elements.length; |
| 2701 for (int i = 0; i < length; i++) { |
| 2702 Element element = elements[i]; |
| 2688 if (element.nameOffset == offset && element.name == name) { | 2703 if (element.nameOffset == offset && element.name == name) { |
| 2689 return element; | 2704 return element; |
| 2690 } | 2705 } |
| 2691 } | 2706 } |
| 2692 if (!required) { | 2707 if (!required) { |
| 2693 return null; | 2708 return null; |
| 2694 } | 2709 } |
| 2695 for (Element element in elements) { | 2710 for (int i = 0; i < length; i++) { |
| 2711 Element element = elements[i]; |
| 2696 if (element.name == name) { | 2712 if (element.name == name) { |
| 2697 _mismatch( | 2713 _mismatch( |
| 2698 'Found element with name "$name" at ${element.nameOffset}, ' | 2714 'Found element with name "$name" at ${element.nameOffset}, ' |
| 2699 'but expected offset of $offset', | 2715 'but expected offset of $offset', |
| 2700 node); | 2716 node); |
| 2701 } | 2717 } |
| 2702 if (element.nameOffset == offset) { | 2718 if (element.nameOffset == offset) { |
| 2703 _mismatch( | 2719 _mismatch( |
| 2704 'Found element with name "${element.name}" at $offset, ' | 2720 'Found element with name "${element.name}" at $offset, ' |
| 2705 'but expected element with name "$name"', | 2721 'but expected element with name "$name"', |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2846 /** | 2862 /** |
| 2847 * Return the export element from the given list of [exports] whose library | 2863 * Return the export element from the given list of [exports] whose library |
| 2848 * has the given [source]. Throw an [ElementMismatchException] if an element | 2864 * has the given [source]. Throw an [ElementMismatchException] if an element |
| 2849 * corresponding to the identifier cannot be found. | 2865 * corresponding to the identifier cannot be found. |
| 2850 */ | 2866 */ |
| 2851 ExportElement _findExport( | 2867 ExportElement _findExport( |
| 2852 ExportDirective node, List<ExportElement> exports, Source source) { | 2868 ExportDirective node, List<ExportElement> exports, Source source) { |
| 2853 if (source == null) { | 2869 if (source == null) { |
| 2854 return null; | 2870 return null; |
| 2855 } | 2871 } |
| 2856 for (ExportElement export in exports) { | 2872 int length = exports.length; |
| 2873 for (int i = 0; i < length; i++) { |
| 2874 ExportElement export = exports[i]; |
| 2857 if (export.exportedLibrary.source == source) { | 2875 if (export.exportedLibrary.source == source) { |
| 2858 // Must have the same offset. | 2876 // Must have the same offset. |
| 2859 if (export.nameOffset != node.offset) { | 2877 if (export.nameOffset != node.offset) { |
| 2860 continue; | 2878 continue; |
| 2861 } | 2879 } |
| 2862 // In general we should also match combinators. | 2880 // In general we should also match combinators. |
| 2863 // But currently we invalidate element model on any directive change. | 2881 // But currently we invalidate element model on any directive change. |
| 2864 // So, either the combinators are the same, or we build new elements. | 2882 // So, either the combinators are the same, or we build new elements. |
| 2865 return export; | 2883 return export; |
| 2866 } | 2884 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2877 * has the given [source]. Throw an [ElementMismatchException] if an element | 2895 * has the given [source]. Throw an [ElementMismatchException] if an element |
| 2878 * corresponding to the [source] cannot be found. | 2896 * corresponding to the [source] cannot be found. |
| 2879 */ | 2897 */ |
| 2880 ImportElement _findImport( | 2898 ImportElement _findImport( |
| 2881 ImportDirective node, List<ImportElement> imports, Source source) { | 2899 ImportDirective node, List<ImportElement> imports, Source source) { |
| 2882 if (source == null) { | 2900 if (source == null) { |
| 2883 return null; | 2901 return null; |
| 2884 } | 2902 } |
| 2885 SimpleIdentifier prefix = node.prefix; | 2903 SimpleIdentifier prefix = node.prefix; |
| 2886 bool foundSource = false; | 2904 bool foundSource = false; |
| 2887 for (ImportElement element in imports) { | 2905 int length = imports.length; |
| 2906 for (int i = 0; i < length; i++) { |
| 2907 ImportElement element = imports[i]; |
| 2888 if (element.importedLibrary.source == source) { | 2908 if (element.importedLibrary.source == source) { |
| 2889 foundSource = true; | 2909 foundSource = true; |
| 2890 // Must have the same offset. | 2910 // Must have the same offset. |
| 2891 if (element.nameOffset != node.offset) { | 2911 if (element.nameOffset != node.offset) { |
| 2892 continue; | 2912 continue; |
| 2893 } | 2913 } |
| 2894 // Must have the same prefix. | 2914 // Must have the same prefix. |
| 2895 if (element.prefix?.displayName != prefix?.name) { | 2915 if (element.prefix?.displayName != prefix?.name) { |
| 2896 continue; | 2916 continue; |
| 2897 } | 2917 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3173 if (_typeParameters == null) { | 3193 if (_typeParameters == null) { |
| 3174 _typeParameters = new List<TypeParameterElement>(); | 3194 _typeParameters = new List<TypeParameterElement>(); |
| 3175 } | 3195 } |
| 3176 _typeParameters.add(element); | 3196 _typeParameters.add(element); |
| 3177 } | 3197 } |
| 3178 | 3198 |
| 3179 FieldElement getField(String fieldName) { | 3199 FieldElement getField(String fieldName) { |
| 3180 if (_fields == null) { | 3200 if (_fields == null) { |
| 3181 return null; | 3201 return null; |
| 3182 } | 3202 } |
| 3183 for (FieldElement field in _fields) { | 3203 int length = _fields.length; |
| 3204 for (int i = 0; i < length; i++) { |
| 3205 FieldElement field = _fields[i]; |
| 3184 if (field.name == fieldName) { | 3206 if (field.name == fieldName) { |
| 3185 return field; | 3207 return field; |
| 3186 } | 3208 } |
| 3187 } | 3209 } |
| 3188 return null; | 3210 return null; |
| 3189 } | 3211 } |
| 3190 | 3212 |
| 3191 TopLevelVariableElement getTopLevelVariable(String variableName) { | 3213 TopLevelVariableElement getTopLevelVariable(String variableName) { |
| 3192 if (_topLevelVariables == null) { | 3214 if (_topLevelVariables == null) { |
| 3193 return null; | 3215 return null; |
| 3194 } | 3216 } |
| 3195 for (TopLevelVariableElement variable in _topLevelVariables) { | 3217 int length = _topLevelVariables.length; |
| 3218 for (int i = 0; i < length; i++) { |
| 3219 TopLevelVariableElement variable = _topLevelVariables[i]; |
| 3196 if (variable.name == variableName) { | 3220 if (variable.name == variableName) { |
| 3197 return variable; | 3221 return variable; |
| 3198 } | 3222 } |
| 3199 } | 3223 } |
| 3200 return null; | 3224 return null; |
| 3201 } | 3225 } |
| 3202 | 3226 |
| 3203 void validate() { | 3227 void validate() { |
| 3204 StringBuffer buffer = new StringBuffer(); | 3228 StringBuffer buffer = new StringBuffer(); |
| 3205 if (_accessors != null) { | 3229 if (_accessors != null) { |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3973 directive.metadata.accept(this); | 3997 directive.metadata.accept(this); |
| 3974 } | 3998 } |
| 3975 | 3999 |
| 3976 void _visitIdentifier(SimpleIdentifier identifier, Element element) { | 4000 void _visitIdentifier(SimpleIdentifier identifier, Element element) { |
| 3977 if (element == null) { | 4001 if (element == null) { |
| 3978 return; | 4002 return; |
| 3979 } | 4003 } |
| 3980 // If the element is multiply defined then call this method recursively for | 4004 // If the element is multiply defined then call this method recursively for |
| 3981 // each of the conflicting elements. | 4005 // each of the conflicting elements. |
| 3982 if (element is MultiplyDefinedElement) { | 4006 if (element is MultiplyDefinedElement) { |
| 3983 for (Element elt in element.conflictingElements) { | 4007 List<Element> conflictingElements = element.conflictingElements; |
| 4008 int length = conflictingElements.length; |
| 4009 for (int i = 0; i < length; i++) { |
| 4010 Element elt = conflictingElements[i]; |
| 3984 _visitIdentifier(identifier, elt); | 4011 _visitIdentifier(identifier, elt); |
| 3985 } | 4012 } |
| 3986 return; | 4013 return; |
| 3987 } | 4014 } |
| 3988 | 4015 |
| 3989 // Record `importPrefix.identifier` into 'prefixMap'. | 4016 // Record `importPrefix.identifier` into 'prefixMap'. |
| 3990 if (_recordPrefixMap(identifier, element)) { | 4017 if (_recordPrefixMap(identifier, element)) { |
| 3991 return; | 4018 return; |
| 3992 } | 4019 } |
| 3993 | 4020 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4199 _library = _compilationUnits[0].element.library; | 4226 _library = _compilationUnits[0].element.library; |
| 4200 _usedImportedElementsVisitor = | 4227 _usedImportedElementsVisitor = |
| 4201 new GatherUsedImportedElementsVisitor(_library); | 4228 new GatherUsedImportedElementsVisitor(_library); |
| 4202 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; | 4229 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; |
| 4203 _manager = new InheritanceManager(_library); | 4230 _manager = new InheritanceManager(_library); |
| 4204 _usedLocalElementsVisitor = new GatherUsedLocalElementsVisitor(_library); | 4231 _usedLocalElementsVisitor = new GatherUsedLocalElementsVisitor(_library); |
| 4205 } | 4232 } |
| 4206 | 4233 |
| 4207 void generateForLibrary() { | 4234 void generateForLibrary() { |
| 4208 PerformanceStatistics.hints.makeCurrentWhile(() { | 4235 PerformanceStatistics.hints.makeCurrentWhile(() { |
| 4209 for (CompilationUnit unit in _compilationUnits) { | 4236 int length = _compilationUnits.length; |
| 4237 for (int i = 0; i < length; i++) { |
| 4238 CompilationUnit unit = _compilationUnits[i]; |
| 4210 CompilationUnitElement element = unit.element; | 4239 CompilationUnitElement element = unit.element; |
| 4211 if (element != null) { | 4240 if (element != null) { |
| 4212 _generateForCompilationUnit(unit, element.source); | 4241 _generateForCompilationUnit(unit, element.source); |
| 4213 } | 4242 } |
| 4214 } | 4243 } |
| 4215 CompilationUnit definingUnit = _compilationUnits[0]; | 4244 CompilationUnit definingUnit = _compilationUnits[0]; |
| 4216 ErrorReporter definingUnitErrorReporter = | 4245 ErrorReporter definingUnitErrorReporter = |
| 4217 new ErrorReporter(_errorListener, definingUnit.element.source); | 4246 new ErrorReporter(_errorListener, definingUnit.element.source); |
| 4218 { | 4247 { |
| 4219 ImportsVerifier importsVerifier = new ImportsVerifier(); | 4248 ImportsVerifier importsVerifier = new ImportsVerifier(); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4400 | 4429 |
| 4401 /** | 4430 /** |
| 4402 * Any time after the defining compilation unit has been visited by this visit
or, this method can | 4431 * Any time after the defining compilation unit has been visited by this visit
or, this method can |
| 4403 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp
ort directives | 4432 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp
ort directives |
| 4404 * in the [duplicateImports] list. | 4433 * in the [duplicateImports] list. |
| 4405 * | 4434 * |
| 4406 * @param errorReporter the error reporter to report the set of [HintCode.DUPL
ICATE_IMPORT] | 4435 * @param errorReporter the error reporter to report the set of [HintCode.DUPL
ICATE_IMPORT] |
| 4407 * hints to | 4436 * hints to |
| 4408 */ | 4437 */ |
| 4409 void generateDuplicateImportHints(ErrorReporter errorReporter) { | 4438 void generateDuplicateImportHints(ErrorReporter errorReporter) { |
| 4410 for (ImportDirective duplicateImport in _duplicateImports) { | 4439 int length = _duplicateImports.length; |
| 4440 for (int i = 0; i < length; i++) { |
| 4411 errorReporter.reportErrorForNode( | 4441 errorReporter.reportErrorForNode( |
| 4412 HintCode.DUPLICATE_IMPORT, duplicateImport.uri); | 4442 HintCode.DUPLICATE_IMPORT, _duplicateImports[i].uri); |
| 4413 } | 4443 } |
| 4414 } | 4444 } |
| 4415 | 4445 |
| 4416 /** | 4446 /** |
| 4417 * Report an [HintCode.UNUSED_IMPORT] hint for each unused import. | 4447 * Report an [HintCode.UNUSED_IMPORT] hint for each unused import. |
| 4418 * | 4448 * |
| 4419 * Only call this method after all of the compilation units have been visited
by this visitor. | 4449 * Only call this method after all of the compilation units have been visited
by this visitor. |
| 4420 * | 4450 * |
| 4421 * @param errorReporter the error reporter used to report the set of [HintCode
.UNUSED_IMPORT] | 4451 * @param errorReporter the error reporter used to report the set of [HintCode
.UNUSED_IMPORT] |
| 4422 * hints | 4452 * hints |
| 4423 */ | 4453 */ |
| 4424 void generateUnusedImportHints(ErrorReporter errorReporter) { | 4454 void generateUnusedImportHints(ErrorReporter errorReporter) { |
| 4425 for (ImportDirective unusedImport in _unusedImports) { | 4455 int length = _unusedImports.length; |
| 4456 for (int i = 0; i < length; i++) { |
| 4457 ImportDirective unusedImport = _unusedImports[i]; |
| 4426 // Check that the import isn't dart:core | 4458 // Check that the import isn't dart:core |
| 4427 ImportElement importElement = unusedImport.element; | 4459 ImportElement importElement = unusedImport.element; |
| 4428 if (importElement != null) { | 4460 if (importElement != null) { |
| 4429 LibraryElement libraryElement = importElement.importedLibrary; | 4461 LibraryElement libraryElement = importElement.importedLibrary; |
| 4430 if (libraryElement != null && libraryElement.isDartCore) { | 4462 if (libraryElement != null && libraryElement.isDartCore) { |
| 4431 continue; | 4463 continue; |
| 4432 } | 4464 } |
| 4433 } | 4465 } |
| 4434 errorReporter.reportErrorForNode( | 4466 errorReporter.reportErrorForNode( |
| 4435 HintCode.UNUSED_IMPORT, unusedImport.uri); | 4467 HintCode.UNUSED_IMPORT, unusedImport.uri); |
| 4436 } | 4468 } |
| 4437 } | 4469 } |
| 4438 | 4470 |
| 4439 /** | 4471 /** |
| 4440 * Report an [HintCode.UNUSED_SHOWN_NAME] hint for each unused shown name. | 4472 * Report an [HintCode.UNUSED_SHOWN_NAME] hint for each unused shown name. |
| 4441 * | 4473 * |
| 4442 * Only call this method after all of the compilation units have been visited
by this visitor. | 4474 * Only call this method after all of the compilation units have been visited
by this visitor. |
| 4443 * | 4475 * |
| 4444 * @param errorReporter the error reporter used to report the set of [HintCode
.UNUSED_SHOWN_NAME] | 4476 * @param errorReporter the error reporter used to report the set of [HintCode
.UNUSED_SHOWN_NAME] |
| 4445 * hints | 4477 * hints |
| 4446 */ | 4478 */ |
| 4447 void generateUnusedShownNameHints(ErrorReporter reporter) { | 4479 void generateUnusedShownNameHints(ErrorReporter reporter) { |
| 4448 _unusedShownNamesMap.forEach( | 4480 _unusedShownNamesMap.forEach( |
| 4449 (ImportDirective importDirective, List<SimpleIdentifier> identifiers) { | 4481 (ImportDirective importDirective, List<SimpleIdentifier> identifiers) { |
| 4450 if (_unusedImports.contains(importDirective)) { | 4482 if (_unusedImports.contains(importDirective)) { |
| 4451 // This import is actually wholly unused, not just one or more shown nam
es from it. | 4483 // This import is actually wholly unused, not just one or more shown nam
es from it. |
| 4452 // This is then an "unused import", rather than unused shown names. | 4484 // This is then an "unused import", rather than unused shown names. |
| 4453 return; | 4485 return; |
| 4454 } | 4486 } |
| 4455 for (Identifier identifier in identifiers) { | 4487 int length = identifiers.length; |
| 4488 for (int i = 0; i < length; i++) { |
| 4489 Identifier identifier = identifiers[i]; |
| 4456 reporter.reportErrorForNode( | 4490 reporter.reportErrorForNode( |
| 4457 HintCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]); | 4491 HintCode.UNUSED_SHOWN_NAME, identifier, [identifier.name]); |
| 4458 } | 4492 } |
| 4459 }); | 4493 }); |
| 4460 } | 4494 } |
| 4461 | 4495 |
| 4462 /** | 4496 /** |
| 4463 * Remove elements from [_unusedImports] using the given [usedElements]. | 4497 * Remove elements from [_unusedImports] using the given [usedElements]. |
| 4464 */ | 4498 */ |
| 4465 void removeUsedElements(UsedImportedElements usedElements) { | 4499 void removeUsedElements(UsedImportedElements usedElements) { |
| 4466 // Stop if all the imports and shown names are known to be used. | 4500 // Stop if all the imports and shown names are known to be used. |
| 4467 if (_unusedImports.isEmpty && _unusedShownNamesMap.isEmpty) { | 4501 if (_unusedImports.isEmpty && _unusedShownNamesMap.isEmpty) { |
| 4468 return; | 4502 return; |
| 4469 } | 4503 } |
| 4470 // Process import prefixes. | 4504 // Process import prefixes. |
| 4471 usedElements.prefixMap | 4505 usedElements.prefixMap |
| 4472 .forEach((PrefixElement prefix, List<Element> elements) { | 4506 .forEach((PrefixElement prefix, List<Element> elements) { |
| 4473 List<ImportDirective> importDirectives = _prefixElementMap[prefix]; | 4507 List<ImportDirective> importDirectives = _prefixElementMap[prefix]; |
| 4474 if (importDirectives != null) { | 4508 if (importDirectives != null) { |
| 4475 for (ImportDirective importDirective in importDirectives) { | 4509 int importLength = importDirectives.length; |
| 4510 for (int i = 0; i < importLength; i++) { |
| 4511 ImportDirective importDirective = importDirectives[i]; |
| 4476 _unusedImports.remove(importDirective); | 4512 _unusedImports.remove(importDirective); |
| 4477 for (Element element in elements) { | 4513 int elementLength = elements.length; |
| 4514 for (int j = 0; j < elementLength; j++) { |
| 4515 Element element = elements[j]; |
| 4478 _removeFromUnusedShownNamesMap(element, importDirective); | 4516 _removeFromUnusedShownNamesMap(element, importDirective); |
| 4479 } | 4517 } |
| 4480 } | 4518 } |
| 4481 } | 4519 } |
| 4482 }); | 4520 }); |
| 4483 // Process top-level elements. | 4521 // Process top-level elements. |
| 4484 for (Element element in usedElements.elements) { | 4522 for (Element element in usedElements.elements) { |
| 4485 // Stop if all the imports and shown names are known to be used. | 4523 // Stop if all the imports and shown names are known to be used. |
| 4486 if (_unusedImports.isEmpty && _unusedShownNamesMap.isEmpty) { | 4524 if (_unusedImports.isEmpty && _unusedShownNamesMap.isEmpty) { |
| 4487 return; | 4525 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4515 } | 4553 } |
| 4516 | 4554 |
| 4517 /** | 4555 /** |
| 4518 * Recursively add any exported library elements into the [libraryMap]. | 4556 * Recursively add any exported library elements into the [libraryMap]. |
| 4519 */ | 4557 */ |
| 4520 void _addAdditionalLibrariesForExports(LibraryElement library, | 4558 void _addAdditionalLibrariesForExports(LibraryElement library, |
| 4521 ImportDirective importDirective, Set<LibraryElement> visitedLibraries) { | 4559 ImportDirective importDirective, Set<LibraryElement> visitedLibraries) { |
| 4522 if (!visitedLibraries.add(library)) { | 4560 if (!visitedLibraries.add(library)) { |
| 4523 return; | 4561 return; |
| 4524 } | 4562 } |
| 4525 for (ExportElement exportElt in library.exports) { | 4563 List<ExportElement> exports = library.exports; |
| 4564 int length = exports.length; |
| 4565 for (int i = 0; i < length; i++) { |
| 4566 ExportElement exportElt = exports[i]; |
| 4526 LibraryElement exportedLibrary = exportElt.exportedLibrary; | 4567 LibraryElement exportedLibrary = exportElt.exportedLibrary; |
| 4527 _putIntoLibraryMap(exportedLibrary, importDirective); | 4568 _putIntoLibraryMap(exportedLibrary, importDirective); |
| 4528 _addAdditionalLibrariesForExports( | 4569 _addAdditionalLibrariesForExports( |
| 4529 exportedLibrary, importDirective, visitedLibraries); | 4570 exportedLibrary, importDirective, visitedLibraries); |
| 4530 } | 4571 } |
| 4531 } | 4572 } |
| 4532 | 4573 |
| 4533 /** | 4574 /** |
| 4534 * Add every shown name from [importDirective] into [_unusedShownNamesMap]. | 4575 * Add every shown name from [importDirective] into [_unusedShownNamesMap]. |
| 4535 */ | 4576 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4590 | 4631 |
| 4591 /** | 4632 /** |
| 4592 * Remove [element] from the list of names shown by [importDirective]. | 4633 * Remove [element] from the list of names shown by [importDirective]. |
| 4593 */ | 4634 */ |
| 4594 void _removeFromUnusedShownNamesMap( | 4635 void _removeFromUnusedShownNamesMap( |
| 4595 Element element, ImportDirective importDirective) { | 4636 Element element, ImportDirective importDirective) { |
| 4596 List<SimpleIdentifier> identifiers = _unusedShownNamesMap[importDirective]; | 4637 List<SimpleIdentifier> identifiers = _unusedShownNamesMap[importDirective]; |
| 4597 if (identifiers == null) { | 4638 if (identifiers == null) { |
| 4598 return; | 4639 return; |
| 4599 } | 4640 } |
| 4600 for (Identifier identifier in identifiers) { | 4641 int length = identifiers.length; |
| 4642 for (int i = 0; i < length; i++) { |
| 4643 Identifier identifier = identifiers[i]; |
| 4601 if (element is PropertyAccessorElement) { | 4644 if (element is PropertyAccessorElement) { |
| 4602 // If the getter or setter of a variable is used, then the variable (the | 4645 // If the getter or setter of a variable is used, then the variable (the |
| 4603 // shown name) is used. | 4646 // shown name) is used. |
| 4604 if (identifier.staticElement == element.variable) { | 4647 if (identifier.staticElement == element.variable) { |
| 4605 identifiers.remove(identifier); | 4648 identifiers.remove(identifier); |
| 4606 break; | 4649 break; |
| 4607 } | 4650 } |
| 4608 } else { | 4651 } else { |
| 4609 if (identifier.staticElement == element) { | 4652 if (identifier.staticElement == element) { |
| 4610 identifiers.remove(identifier); | 4653 identifiers.remove(identifier); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4814 visited = new HashSet<Element>(); | 4857 visited = new HashSet<Element>(); |
| 4815 } | 4858 } |
| 4816 if (element == null || !visited.add(element)) { | 4859 if (element == null || !visited.add(element)) { |
| 4817 return false; | 4860 return false; |
| 4818 } | 4861 } |
| 4819 try { | 4862 try { |
| 4820 if (match(t1.superclass, visited)) { | 4863 if (match(t1.superclass, visited)) { |
| 4821 return true; | 4864 return true; |
| 4822 } | 4865 } |
| 4823 | 4866 |
| 4824 for (final parent in t1.mixins) { | 4867 List<InterfaceType> mixins = t1.mixins; |
| 4825 if (match(parent, visited)) { | 4868 int mixinLength = mixins.length; |
| 4869 for (int i = 0; i < mixinLength; i++) { |
| 4870 if (match(mixins[i], visited)) { |
| 4826 return true; | 4871 return true; |
| 4827 } | 4872 } |
| 4828 } | 4873 } |
| 4829 | 4874 |
| 4830 for (final parent in t1.interfaces) { | 4875 List<InterfaceType> interfaces = t1.interfaces; |
| 4831 if (match(parent, visited)) { | 4876 int interfaceLength = interfaces.length; |
| 4877 for (int j = 0; j < interfaceLength; j++) { |
| 4878 if (match(interfaces[j], visited)) { |
| 4832 return true; | 4879 return true; |
| 4833 } | 4880 } |
| 4834 } | 4881 } |
| 4835 } finally { | 4882 } finally { |
| 4836 visited.remove(element); | 4883 visited.remove(element); |
| 4837 } | 4884 } |
| 4838 return false; | 4885 return false; |
| 4839 } | 4886 } |
| 4840 | 4887 |
| 4841 // We have that t1 = T1<dynamic, ..., dynamic>. | 4888 // We have that t1 = T1<dynamic, ..., dynamic>. |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5158 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 5205 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 5159 _addPropagableVariables(node.variables.variables); | 5206 _addPropagableVariables(node.variables.variables); |
| 5160 _addStaticVariables(node.variables.variables); | 5207 _addStaticVariables(node.variables.variables); |
| 5161 return super.visitTopLevelVariableDeclaration(node); | 5208 return super.visitTopLevelVariableDeclaration(node); |
| 5162 } | 5209 } |
| 5163 | 5210 |
| 5164 /** | 5211 /** |
| 5165 * Add all of the [variables] with initializers to [propagableVariables]. | 5212 * Add all of the [variables] with initializers to [propagableVariables]. |
| 5166 */ | 5213 */ |
| 5167 void _addPropagableVariables(List<VariableDeclaration> variables) { | 5214 void _addPropagableVariables(List<VariableDeclaration> variables) { |
| 5168 for (VariableDeclaration variable in variables) { | 5215 int length = variables.length; |
| 5216 for (int i = 0; i < length; i++) { |
| 5217 VariableDeclaration variable = variables[i]; |
| 5169 if (variable.name.name.isNotEmpty && variable.initializer != null) { | 5218 if (variable.name.name.isNotEmpty && variable.initializer != null) { |
| 5170 VariableElement element = variable.element; | 5219 VariableElement element = variable.element; |
| 5171 if (element.isConst || element.isFinal) { | 5220 if (element.isConst || element.isFinal) { |
| 5172 propagableVariables.add(element); | 5221 propagableVariables.add(element); |
| 5173 } | 5222 } |
| 5174 } | 5223 } |
| 5175 } | 5224 } |
| 5176 } | 5225 } |
| 5177 | 5226 |
| 5178 /** | 5227 /** |
| 5179 * Add all of the [variables] with initializers to the list of variables whose | 5228 * Add all of the [variables] with initializers to the list of variables whose |
| 5180 * type can be inferred. Technically, we only infer the types of variables | 5229 * type can be inferred. Technically, we only infer the types of variables |
| 5181 * that do not have a static type, but all variables with initializers | 5230 * that do not have a static type, but all variables with initializers |
| 5182 * potentially need to be re-resolved after inference because they might | 5231 * potentially need to be re-resolved after inference because they might |
| 5183 * refer to a field whose type was inferred. | 5232 * refer to a field whose type was inferred. |
| 5184 */ | 5233 */ |
| 5185 void _addStaticVariables(List<VariableDeclaration> variables) { | 5234 void _addStaticVariables(List<VariableDeclaration> variables) { |
| 5186 for (VariableDeclaration variable in variables) { | 5235 int length = variables.length; |
| 5236 for (int i = 0; i < length; i++) { |
| 5237 VariableDeclaration variable = variables[i]; |
| 5187 if (variable.name.name.isNotEmpty && variable.initializer != null) { | 5238 if (variable.name.name.isNotEmpty && variable.initializer != null) { |
| 5188 staticVariables.add(variable.element); | 5239 staticVariables.add(variable.element); |
| 5189 } | 5240 } |
| 5190 } | 5241 } |
| 5191 } | 5242 } |
| 5192 | 5243 |
| 5193 /** | 5244 /** |
| 5194 * Return `true` if the given function body should be skipped because it is | 5245 * Return `true` if the given function body should be skipped because it is |
| 5195 * the body of a top-level function, method or constructor. | 5246 * the body of a top-level function, method or constructor. |
| 5196 */ | 5247 */ |
| (...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7388 List<ParameterElement> parameters, | 7439 List<ParameterElement> parameters, |
| 7389 void onError(ErrorCode errorCode, AstNode node, [List<Object> arguments]), | 7440 void onError(ErrorCode errorCode, AstNode node, [List<Object> arguments]), |
| 7390 {bool reportAsError: false}) { | 7441 {bool reportAsError: false}) { |
| 7391 if (parameters.isEmpty && argumentList.arguments.isEmpty) { | 7442 if (parameters.isEmpty && argumentList.arguments.isEmpty) { |
| 7392 return const <ParameterElement>[]; | 7443 return const <ParameterElement>[]; |
| 7393 } | 7444 } |
| 7394 int requiredParameterCount = 0; | 7445 int requiredParameterCount = 0; |
| 7395 int unnamedParameterCount = 0; | 7446 int unnamedParameterCount = 0; |
| 7396 List<ParameterElement> unnamedParameters = new List<ParameterElement>(); | 7447 List<ParameterElement> unnamedParameters = new List<ParameterElement>(); |
| 7397 HashMap<String, ParameterElement> namedParameters = null; | 7448 HashMap<String, ParameterElement> namedParameters = null; |
| 7398 for (ParameterElement parameter in parameters) { | 7449 int length = parameters.length; |
| 7450 for (int i = 0; i < length; i++) { |
| 7451 ParameterElement parameter = parameters[i]; |
| 7399 ParameterKind kind = parameter.parameterKind; | 7452 ParameterKind kind = parameter.parameterKind; |
| 7400 if (kind == ParameterKind.REQUIRED) { | 7453 if (kind == ParameterKind.REQUIRED) { |
| 7401 unnamedParameters.add(parameter); | 7454 unnamedParameters.add(parameter); |
| 7402 unnamedParameterCount++; | 7455 unnamedParameterCount++; |
| 7403 requiredParameterCount++; | 7456 requiredParameterCount++; |
| 7404 } else if (kind == ParameterKind.POSITIONAL) { | 7457 } else if (kind == ParameterKind.POSITIONAL) { |
| 7405 unnamedParameters.add(parameter); | 7458 unnamedParameters.add(parameter); |
| 7406 unnamedParameterCount++; | 7459 unnamedParameterCount++; |
| 7407 } else { | 7460 } else { |
| 7408 namedParameters ??= new HashMap<String, ParameterElement>(); | 7461 namedParameters ??= new HashMap<String, ParameterElement>(); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7935 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 7988 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 7936 Scope outerScope = nameScope; | 7989 Scope outerScope = nameScope; |
| 7937 try { | 7990 try { |
| 7938 ParameterElement parameterElement = node.element; | 7991 ParameterElement parameterElement = node.element; |
| 7939 if (parameterElement == null) { | 7992 if (parameterElement == null) { |
| 7940 AnalysisEngine.instance.logger.logInformation( | 7993 AnalysisEngine.instance.logger.logInformation( |
| 7941 "Missing element for function typed formal parameter ${node.identifi
er.name} in ${definingLibrary.source.fullName}", | 7994 "Missing element for function typed formal parameter ${node.identifi
er.name} in ${definingLibrary.source.fullName}", |
| 7942 new CaughtException(new AnalysisException(), null)); | 7995 new CaughtException(new AnalysisException(), null)); |
| 7943 } else { | 7996 } else { |
| 7944 nameScope = new EnclosedScope(nameScope); | 7997 nameScope = new EnclosedScope(nameScope); |
| 7945 for (TypeParameterElement typeParameter | 7998 List<TypeParameterElement> typeParameters = |
| 7946 in parameterElement.typeParameters) { | 7999 parameterElement.typeParameters; |
| 7947 nameScope.define(typeParameter); | 8000 int length = typeParameters.length; |
| 8001 for (int i = 0; i < length; i++) { |
| 8002 nameScope.define(typeParameters[i]); |
| 7948 } | 8003 } |
| 7949 } | 8004 } |
| 7950 super.visitFunctionTypedFormalParameter(node); | 8005 super.visitFunctionTypedFormalParameter(node); |
| 7951 } finally { | 8006 } finally { |
| 7952 nameScope = outerScope; | 8007 nameScope = outerScope; |
| 7953 } | 8008 } |
| 7954 return null; | 8009 return null; |
| 7955 } | 8010 } |
| 7956 | 8011 |
| 7957 @override | 8012 @override |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8183 */ | 8238 */ |
| 8184 void _computeSubtypesInClass(ClassElement classElement) { | 8239 void _computeSubtypesInClass(ClassElement classElement) { |
| 8185 InterfaceType supertypeType = classElement.supertype; | 8240 InterfaceType supertypeType = classElement.supertype; |
| 8186 if (supertypeType != null) { | 8241 if (supertypeType != null) { |
| 8187 ClassElement supertypeElement = supertypeType.element; | 8242 ClassElement supertypeElement = supertypeType.element; |
| 8188 if (supertypeElement != null) { | 8243 if (supertypeElement != null) { |
| 8189 _putInSubtypeMap(supertypeElement, classElement); | 8244 _putInSubtypeMap(supertypeElement, classElement); |
| 8190 } | 8245 } |
| 8191 } | 8246 } |
| 8192 List<InterfaceType> interfaceTypes = classElement.interfaces; | 8247 List<InterfaceType> interfaceTypes = classElement.interfaces; |
| 8193 for (InterfaceType interfaceType in interfaceTypes) { | 8248 int interfaceLength = interfaceTypes.length; |
| 8249 for (int i = 0; i < interfaceLength; i++) { |
| 8250 InterfaceType interfaceType = interfaceTypes[i]; |
| 8194 ClassElement interfaceElement = interfaceType.element; | 8251 ClassElement interfaceElement = interfaceType.element; |
| 8195 if (interfaceElement != null) { | 8252 if (interfaceElement != null) { |
| 8196 _putInSubtypeMap(interfaceElement, classElement); | 8253 _putInSubtypeMap(interfaceElement, classElement); |
| 8197 } | 8254 } |
| 8198 } | 8255 } |
| 8199 List<InterfaceType> mixinTypes = classElement.mixins; | 8256 List<InterfaceType> mixinTypes = classElement.mixins; |
| 8200 for (InterfaceType mixinType in mixinTypes) { | 8257 int mixinLength = mixinTypes.length; |
| 8258 for (int i = 0; i < mixinLength; i++) { |
| 8259 InterfaceType mixinType = mixinTypes[i]; |
| 8201 ClassElement mixinElement = mixinType.element; | 8260 ClassElement mixinElement = mixinType.element; |
| 8202 if (mixinElement != null) { | 8261 if (mixinElement != null) { |
| 8203 _putInSubtypeMap(mixinElement, classElement); | 8262 _putInSubtypeMap(mixinElement, classElement); |
| 8204 } | 8263 } |
| 8205 } | 8264 } |
| 8206 } | 8265 } |
| 8207 | 8266 |
| 8208 /** | 8267 /** |
| 8209 * Given some [CompilationUnitElement], this method calls | 8268 * Given some [CompilationUnitElement], this method calls |
| 8210 * [computeAllSubtypes] on all of the [ClassElement]s in the | 8269 * [computeAllSubtypes] on all of the [ClassElement]s in the |
| 8211 * compilation unit. | 8270 * compilation unit. |
| 8212 * | 8271 * |
| 8213 * @param unitElement the compilation unit element | 8272 * @param unitElement the compilation unit element |
| 8214 */ | 8273 */ |
| 8215 void _computeSubtypesInCompilationUnit(CompilationUnitElement unitElement) { | 8274 void _computeSubtypesInCompilationUnit(CompilationUnitElement unitElement) { |
| 8216 List<ClassElement> classElements = unitElement.types; | 8275 List<ClassElement> classElements = unitElement.types; |
| 8217 for (ClassElement classElement in classElements) { | 8276 int length = classElements.length; |
| 8277 for (int i = 0; i < length; i++) { |
| 8278 ClassElement classElement = classElements[i]; |
| 8218 _computeSubtypesInClass(classElement); | 8279 _computeSubtypesInClass(classElement); |
| 8219 } | 8280 } |
| 8220 } | 8281 } |
| 8221 | 8282 |
| 8222 /** | 8283 /** |
| 8223 * Given some [LibraryElement], this method calls | 8284 * Given some [LibraryElement], this method calls |
| 8224 * [computeAllSubtypes] on all of the [ClassElement]s in the | 8285 * [computeAllSubtypes] on all of the [ClassElement]s in the |
| 8225 * compilation unit, and itself for all imported and exported libraries. All v
isited libraries are | 8286 * compilation unit, and itself for all imported and exported libraries. All v
isited libraries are |
| 8226 * added to the [visitedLibraries] set. | 8287 * added to the [visitedLibraries] set. |
| 8227 * | 8288 * |
| 8228 * @param libraryElement the library element | 8289 * @param libraryElement the library element |
| 8229 */ | 8290 */ |
| 8230 void _computeSubtypesInLibrary(LibraryElement libraryElement) { | 8291 void _computeSubtypesInLibrary(LibraryElement libraryElement) { |
| 8231 if (libraryElement == null || _visitedLibraries.contains(libraryElement)) { | 8292 if (libraryElement == null || _visitedLibraries.contains(libraryElement)) { |
| 8232 return; | 8293 return; |
| 8233 } | 8294 } |
| 8234 _visitedLibraries.add(libraryElement); | 8295 _visitedLibraries.add(libraryElement); |
| 8235 _computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit); | 8296 _computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit); |
| 8236 List<CompilationUnitElement> parts = libraryElement.parts; | 8297 List<CompilationUnitElement> parts = libraryElement.parts; |
| 8237 for (CompilationUnitElement part in parts) { | 8298 int partLength = parts.length; |
| 8299 for (int i = 0; i < partLength; i++) { |
| 8300 CompilationUnitElement part = parts[i]; |
| 8238 _computeSubtypesInCompilationUnit(part); | 8301 _computeSubtypesInCompilationUnit(part); |
| 8239 } | 8302 } |
| 8240 List<LibraryElement> imports = libraryElement.importedLibraries; | 8303 List<LibraryElement> imports = libraryElement.importedLibraries; |
| 8241 for (LibraryElement importElt in imports) { | 8304 int importLength = imports.length; |
| 8305 for (int i = 0; i < importLength; i++) { |
| 8306 LibraryElement importElt = imports[i]; |
| 8242 _computeSubtypesInLibrary(importElt.library); | 8307 _computeSubtypesInLibrary(importElt.library); |
| 8243 } | 8308 } |
| 8244 List<LibraryElement> exports = libraryElement.exportedLibraries; | 8309 List<LibraryElement> exports = libraryElement.exportedLibraries; |
| 8245 for (LibraryElement exportElt in exports) { | 8310 int exportLength = exports.length; |
| 8311 for (int i = 0; i < exportLength; i++) { |
| 8312 LibraryElement exportElt = exports[i]; |
| 8246 _computeSubtypesInLibrary(exportElt.library); | 8313 _computeSubtypesInLibrary(exportElt.library); |
| 8247 } | 8314 } |
| 8248 } | 8315 } |
| 8249 | 8316 |
| 8250 /** | 8317 /** |
| 8251 * Add some key/ value pair into the [subtypeMap] map. | 8318 * Add some key/ value pair into the [subtypeMap] map. |
| 8252 * | 8319 * |
| 8253 * @param supertypeElement the key for the [subtypeMap] map | 8320 * @param supertypeElement the key for the [subtypeMap] map |
| 8254 * @param subtypeElement the value for the [subtypeMap] map | 8321 * @param subtypeElement the value for the [subtypeMap] map |
| 8255 */ | 8322 */ |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8718 | 8785 |
| 8719 /** | 8786 /** |
| 8720 * Given the multiple elements to which a single name could potentially be res
olved, return the | 8787 * Given the multiple elements to which a single name could potentially be res
olved, return the |
| 8721 * single interface type that should be used, or `null` if there is no clear c
hoice. | 8788 * single interface type that should be used, or `null` if there is no clear c
hoice. |
| 8722 * | 8789 * |
| 8723 * @param elements the elements to which a single name could potentially be re
solved | 8790 * @param elements the elements to which a single name could potentially be re
solved |
| 8724 * @return the single interface type that should be used for the type name | 8791 * @return the single interface type that should be used for the type name |
| 8725 */ | 8792 */ |
| 8726 InterfaceType _getTypeWhenMultiplyDefined(List<Element> elements) { | 8793 InterfaceType _getTypeWhenMultiplyDefined(List<Element> elements) { |
| 8727 InterfaceType type = null; | 8794 InterfaceType type = null; |
| 8728 for (Element element in elements) { | 8795 int length = elements.length; |
| 8796 for (int i = 0; i < length; i++) { |
| 8797 Element element = elements[i]; |
| 8729 if (element is ClassElement) { | 8798 if (element is ClassElement) { |
| 8730 if (type != null) { | 8799 if (type != null) { |
| 8731 return null; | 8800 return null; |
| 8732 } | 8801 } |
| 8733 type = element.type; | 8802 type = element.type; |
| 8734 } | 8803 } |
| 8735 } | 8804 } |
| 8736 return type; | 8805 return type; |
| 8737 } | 8806 } |
| 8738 | 8807 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8940 } | 9009 } |
| 8941 | 9010 |
| 8942 /** | 9011 /** |
| 8943 * Update overrides assuming [perBranchOverrides] is the collection of | 9012 * Update overrides assuming [perBranchOverrides] is the collection of |
| 8944 * per-branch overrides for *all* branches flowing into a join point. | 9013 * per-branch overrides for *all* branches flowing into a join point. |
| 8945 * | 9014 * |
| 8946 * If a variable type in any of branches is not the same as its type before | 9015 * If a variable type in any of branches is not the same as its type before |
| 8947 * the branching, then its propagated type is reset to `null`. | 9016 * the branching, then its propagated type is reset to `null`. |
| 8948 */ | 9017 */ |
| 8949 void mergeOverrides(List<Map<VariableElement, DartType>> perBranchOverrides) { | 9018 void mergeOverrides(List<Map<VariableElement, DartType>> perBranchOverrides) { |
| 8950 for (Map<VariableElement, DartType> branch in perBranchOverrides) { | 9019 int length = perBranchOverrides.length; |
| 9020 for (int i = 0; i < length; i++) { |
| 9021 Map<VariableElement, DartType> branch = perBranchOverrides[i]; |
| 8951 branch.forEach((VariableElement variable, DartType branchType) { | 9022 branch.forEach((VariableElement variable, DartType branchType) { |
| 8952 DartType currentType = currentScope.getType(variable); | 9023 DartType currentType = currentScope.getType(variable); |
| 8953 if (currentType != branchType) { | 9024 if (currentType != branchType) { |
| 8954 currentScope.resetType(variable); | 9025 currentScope.resetType(variable); |
| 8955 } | 9026 } |
| 8956 }); | 9027 }); |
| 8957 } | 9028 } |
| 8958 } | 9029 } |
| 8959 | 9030 |
| 8960 /** | 9031 /** |
| (...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10562 /** | 10633 /** |
| 10563 * Names of resolved or unresolved class members that are read in the | 10634 * Names of resolved or unresolved class members that are read in the |
| 10564 * library. | 10635 * library. |
| 10565 */ | 10636 */ |
| 10566 final HashSet<String> readMembers = new HashSet<String>(); | 10637 final HashSet<String> readMembers = new HashSet<String>(); |
| 10567 | 10638 |
| 10568 UsedLocalElements(); | 10639 UsedLocalElements(); |
| 10569 | 10640 |
| 10570 factory UsedLocalElements.merge(List<UsedLocalElements> parts) { | 10641 factory UsedLocalElements.merge(List<UsedLocalElements> parts) { |
| 10571 UsedLocalElements result = new UsedLocalElements(); | 10642 UsedLocalElements result = new UsedLocalElements(); |
| 10572 for (UsedLocalElements part in parts) { | 10643 int length = parts.length; |
| 10644 for (int i = 0; i < length; i++) { |
| 10645 UsedLocalElements part = parts[i]; |
| 10573 result.elements.addAll(part.elements); | 10646 result.elements.addAll(part.elements); |
| 10574 result.catchExceptionElements.addAll(part.catchExceptionElements); | 10647 result.catchExceptionElements.addAll(part.catchExceptionElements); |
| 10575 result.catchStackTraceElements.addAll(part.catchStackTraceElements); | 10648 result.catchStackTraceElements.addAll(part.catchStackTraceElements); |
| 10576 result.members.addAll(part.members); | 10649 result.members.addAll(part.members); |
| 10577 result.readMembers.addAll(part.readMembers); | 10650 result.readMembers.addAll(part.readMembers); |
| 10578 } | 10651 } |
| 10579 return result; | 10652 return result; |
| 10580 } | 10653 } |
| 10581 | 10654 |
| 10582 void addCatchException(LocalVariableElement element) { | 10655 void addCatchException(LocalVariableElement element) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10801 {TypeSystem typeSystem}) | 10874 {TypeSystem typeSystem}) |
| 10802 : _typeSystem = typeSystem ?? new TypeSystemImpl(), | 10875 : _typeSystem = typeSystem ?? new TypeSystemImpl(), |
| 10803 super( | 10876 super( |
| 10804 new ConstantEvaluationEngine(typeProvider, declaredVariables, | 10877 new ConstantEvaluationEngine(typeProvider, declaredVariables, |
| 10805 typeSystem: typeSystem), | 10878 typeSystem: typeSystem), |
| 10806 errorReporter); | 10879 errorReporter); |
| 10807 | 10880 |
| 10808 @override | 10881 @override |
| 10809 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { | 10882 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { |
| 10810 Element element = node.staticElement; | 10883 Element element = node.staticElement; |
| 10811 for (ParameterElement parameterElement in parameterElements) { | 10884 int length = parameterElements.length; |
| 10885 for (int i = 0; i < length; i++) { |
| 10886 ParameterElement parameterElement = parameterElements[i]; |
| 10812 if (identical(parameterElement, element) && parameterElement != null) { | 10887 if (identical(parameterElement, element) && parameterElement != null) { |
| 10813 DartType type = parameterElement.type; | 10888 DartType type = parameterElement.type; |
| 10814 if (type != null) { | 10889 if (type != null) { |
| 10815 if (type.isDynamic) { | 10890 if (type.isDynamic) { |
| 10816 return new DartObjectImpl( | 10891 return new DartObjectImpl( |
| 10817 verifier._typeProvider.objectType, DynamicState.DYNAMIC_STATE); | 10892 verifier._typeProvider.objectType, DynamicState.DYNAMIC_STATE); |
| 10818 } else if (_typeSystem.isSubtypeOf(type, verifier._boolType)) { | 10893 } else if (_typeSystem.isSubtypeOf(type, verifier._boolType)) { |
| 10819 return new DartObjectImpl( | 10894 return new DartObjectImpl( |
| 10820 verifier._typeProvider.boolType, BoolState.UNKNOWN_VALUE); | 10895 verifier._typeProvider.boolType, BoolState.UNKNOWN_VALUE); |
| 10821 } else if (_typeSystem.isSubtypeOf( | 10896 } else if (_typeSystem.isSubtypeOf( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10896 return null; | 10971 return null; |
| 10897 } | 10972 } |
| 10898 if (identical(node.staticElement, variable)) { | 10973 if (identical(node.staticElement, variable)) { |
| 10899 if (node.inSetterContext()) { | 10974 if (node.inSetterContext()) { |
| 10900 result = true; | 10975 result = true; |
| 10901 } | 10976 } |
| 10902 } | 10977 } |
| 10903 return null; | 10978 return null; |
| 10904 } | 10979 } |
| 10905 } | 10980 } |
| OLD | NEW |