| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); | 77 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes | 80 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes |
| 81 * constants defined at top level, statically inside classes, and local to | 81 * constants defined at top level, statically inside classes, and local to |
| 82 * functions, as well as constant constructors, annotations, and default values | 82 * functions, as well as constant constructors, annotations, and default values |
| 83 * of parameters. | 83 * of parameters. |
| 84 * | 84 * |
| 85 * The result is only available for [LibrarySpecificUnit]s. | 85 * The result is only available for [LibrarySpecificUnit]s. |
| 86 */ | 86 */ |
| 87 final ListResultDescriptor< | 87 final ListResultDescriptor<ConstantEvaluationTarget> |
| 88 ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS = | 88 COMPILATION_UNIT_CONSTANTS = |
| 89 new ListResultDescriptor<ConstantEvaluationTarget>( | 89 new ListResultDescriptor<ConstantEvaluationTarget>( |
| 90 'COMPILATION_UNIT_CONSTANTS', null, | 90 'COMPILATION_UNIT_CONSTANTS', null, |
| 91 cachingPolicy: ELEMENT_CACHING_POLICY); | 91 cachingPolicy: ELEMENT_CACHING_POLICY); |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * The element model associated with a single compilation unit. | 94 * The element model associated with a single compilation unit. |
| 95 * | 95 * |
| 96 * The result is only available for [LibrarySpecificUnit]s. | 96 * The result is only available for [LibrarySpecificUnit]s. |
| 97 */ | 97 */ |
| 98 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT = | 98 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 new ListResultDescriptor<AnalysisError>( | 152 new ListResultDescriptor<AnalysisError>( |
| 153 'HINT_ERRORS', AnalysisError.NO_ERRORS); | 153 'HINT_ERRORS', AnalysisError.NO_ERRORS); |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * A list of the [VariableElement]s whose type should be inferred that another | 156 * A list of the [VariableElement]s whose type should be inferred that another |
| 157 * inferable static variable (the target) depends on. | 157 * inferable static variable (the target) depends on. |
| 158 * | 158 * |
| 159 * The result is only available for [VariableElement]s, and only when strong | 159 * The result is only available for [VariableElement]s, and only when strong |
| 160 * mode is enabled. | 160 * mode is enabled. |
| 161 */ | 161 */ |
| 162 final ListResultDescriptor< | 162 final ListResultDescriptor<VariableElement> |
| 163 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = | 163 INFERABLE_STATIC_VARIABLE_DEPENDENCIES = |
| 164 new ListResultDescriptor<VariableElement>( | 164 new ListResultDescriptor<VariableElement>( |
| 165 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); | 165 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); |
| 166 | 166 |
| 167 /** | 167 /** |
| 168 * A list of the [VariableElement]s defined in a unit whose type should be | 168 * A list of the [VariableElement]s defined in a unit whose type should be |
| 169 * inferred. This includes variables defined at the library level as well as | 169 * inferred. This includes variables defined at the library level as well as |
| 170 * static members inside classes. | 170 * static members inside classes. |
| 171 * | 171 * |
| 172 * The result is only available for [LibrarySpecificUnit]s, and only when strong | 172 * The result is only available for [LibrarySpecificUnit]s, and only when strong |
| 173 * mode is enabled. | 173 * mode is enabled. |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 source, unit, librarySpecificUnit.library); | 762 source, unit, librarySpecificUnit.library); |
| 763 } else { | 763 } else { |
| 764 new DeclarationResolver().resolve(unit, element); | 764 new DeclarationResolver().resolve(unit, element); |
| 765 } | 765 } |
| 766 // | 766 // |
| 767 // Prepare constants. | 767 // Prepare constants. |
| 768 // | 768 // |
| 769 ConstantFinder constantFinder = | 769 ConstantFinder constantFinder = |
| 770 new ConstantFinder(context, source, librarySpecificUnit.library); | 770 new ConstantFinder(context, source, librarySpecificUnit.library); |
| 771 unit.accept(constantFinder); | 771 unit.accept(constantFinder); |
| 772 List<ConstantEvaluationTarget> constants = new List< | 772 List<ConstantEvaluationTarget> constants = |
| 773 ConstantEvaluationTarget>.from(constantFinder.constantsToCompute); | 773 new List<ConstantEvaluationTarget>.from( |
| 774 constantFinder.constantsToCompute); |
| 774 // | 775 // |
| 775 // Record outputs. | 776 // Record outputs. |
| 776 // | 777 // |
| 777 outputs[COMPILATION_UNIT_CONSTANTS] = constants; | 778 outputs[COMPILATION_UNIT_CONSTANTS] = constants; |
| 778 outputs[COMPILATION_UNIT_ELEMENT] = element; | 779 outputs[COMPILATION_UNIT_ELEMENT] = element; |
| 779 outputs[RESOLVED_UNIT1] = unit; | 780 outputs[RESOLVED_UNIT1] = unit; |
| 780 } | 781 } |
| 781 | 782 |
| 782 /** | 783 /** |
| 783 * Return a map from the names of the inputs of this kind of task to the task | 784 * Return a map from the names of the inputs of this kind of task to the task |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 new ImportElementImpl(directive.offset); | 901 new ImportElementImpl(directive.offset); |
| 901 StringLiteral uriLiteral = importDirective.uri; | 902 StringLiteral uriLiteral = importDirective.uri; |
| 902 if (uriLiteral != null) { | 903 if (uriLiteral != null) { |
| 903 importElement.uriOffset = uriLiteral.offset; | 904 importElement.uriOffset = uriLiteral.offset; |
| 904 importElement.uriEnd = uriLiteral.end; | 905 importElement.uriEnd = uriLiteral.end; |
| 905 } | 906 } |
| 906 importElement.uri = uriContent; | 907 importElement.uri = uriContent; |
| 907 importElement.deferred = importDirective.deferredKeyword != null; | 908 importElement.deferred = importDirective.deferredKeyword != null; |
| 908 importElement.combinators = _buildCombinators(importDirective); | 909 importElement.combinators = _buildCombinators(importDirective); |
| 909 importElement.importedLibrary = importedLibrary; | 910 importElement.importedLibrary = importedLibrary; |
| 910 _setDocRange(importElement, importDirective); | 911 _setDoc(importElement, importDirective); |
| 911 SimpleIdentifier prefixNode = directive.prefix; | 912 SimpleIdentifier prefixNode = directive.prefix; |
| 912 if (prefixNode != null) { | 913 if (prefixNode != null) { |
| 913 importElement.prefixOffset = prefixNode.offset; | 914 importElement.prefixOffset = prefixNode.offset; |
| 914 String prefixName = prefixNode.name; | 915 String prefixName = prefixNode.name; |
| 915 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; | 916 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; |
| 916 if (prefix == null) { | 917 if (prefix == null) { |
| 917 prefix = new PrefixElementImpl.forNode(prefixNode); | 918 prefix = new PrefixElementImpl.forNode(prefixNode); |
| 918 nameToPrefixMap[prefixName] = prefix; | 919 nameToPrefixMap[prefixName] = prefix; |
| 919 } | 920 } |
| 920 importElement.prefix = prefix; | 921 importElement.prefix = prefix; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 942 ExportElementImpl exportElement = | 943 ExportElementImpl exportElement = |
| 943 new ExportElementImpl(directive.offset); | 944 new ExportElementImpl(directive.offset); |
| 944 StringLiteral uriLiteral = exportDirective.uri; | 945 StringLiteral uriLiteral = exportDirective.uri; |
| 945 if (uriLiteral != null) { | 946 if (uriLiteral != null) { |
| 946 exportElement.uriOffset = uriLiteral.offset; | 947 exportElement.uriOffset = uriLiteral.offset; |
| 947 exportElement.uriEnd = uriLiteral.end; | 948 exportElement.uriEnd = uriLiteral.end; |
| 948 } | 949 } |
| 949 exportElement.uri = exportDirective.uriContent; | 950 exportElement.uri = exportDirective.uriContent; |
| 950 exportElement.combinators = _buildCombinators(exportDirective); | 951 exportElement.combinators = _buildCombinators(exportDirective); |
| 951 exportElement.exportedLibrary = exportedLibrary; | 952 exportElement.exportedLibrary = exportedLibrary; |
| 952 _setDocRange(exportElement, exportDirective); | 953 _setDoc(exportElement, exportDirective); |
| 953 directive.element = exportElement; | 954 directive.element = exportElement; |
| 954 exports.add(exportElement); | 955 exports.add(exportElement); |
| 955 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { | 956 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { |
| 956 errors.add(new AnalysisError( | 957 errors.add(new AnalysisError( |
| 957 exportedSource, | 958 exportedSource, |
| 958 uriLiteral.offset, | 959 uriLiteral.offset, |
| 959 uriLiteral.length, | 960 uriLiteral.length, |
| 960 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, | 961 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, |
| 961 [uriLiteral.toSource()])); | 962 [uriLiteral.toSource()])); |
| 962 } | 963 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 983 // for details on library cycle invalidation. | 984 // for details on library cycle invalidation. |
| 984 libraryElement.invalidateLibraryCycles(); | 985 libraryElement.invalidateLibraryCycles(); |
| 985 // | 986 // |
| 986 // Record outputs. | 987 // Record outputs. |
| 987 // | 988 // |
| 988 outputs[LIBRARY_ELEMENT2] = libraryElement; | 989 outputs[LIBRARY_ELEMENT2] = libraryElement; |
| 989 outputs[BUILD_DIRECTIVES_ERRORS] = errors; | 990 outputs[BUILD_DIRECTIVES_ERRORS] = errors; |
| 990 } | 991 } |
| 991 | 992 |
| 992 /** | 993 /** |
| 993 * If the given [node] has a documentation comment, remember its range | 994 * If the given [node] has a documentation comment, remember its content |
| 994 * into the given [element]. | 995 * and range into the given [element]. |
| 995 */ | 996 */ |
| 996 void _setDocRange(ElementImpl element, AnnotatedNode node) { | 997 void _setDoc(ElementImpl element, AnnotatedNode node) { |
| 997 Comment comment = node.documentationComment; | 998 Comment comment = node.documentationComment; |
| 998 if (comment != null && comment.isDocumentation) { | 999 if (comment != null && comment.isDocumentation) { |
| 1000 element.documentationComment = |
| 1001 comment.tokens.map((Token t) => t.lexeme).join('\n'); |
| 999 element.setDocRange(comment.offset, comment.length); | 1002 element.setDocRange(comment.offset, comment.length); |
| 1000 } | 1003 } |
| 1001 } | 1004 } |
| 1002 | 1005 |
| 1003 /** | 1006 /** |
| 1004 * Return a map from the names of the inputs of this kind of task to the task | 1007 * Return a map from the names of the inputs of this kind of task to the task |
| 1005 * input descriptors describing those inputs for a task with the | 1008 * input descriptors describing those inputs for a task with the |
| 1006 * given library [libSource]. | 1009 * given library [libSource]. |
| 1007 */ | 1010 */ |
| 1008 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1011 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 libraryElement.definingCompilationUnit = definingCompilationUnitElement; | 1362 libraryElement.definingCompilationUnit = definingCompilationUnitElement; |
| 1360 libraryElement.entryPoint = entryPoint; | 1363 libraryElement.entryPoint = entryPoint; |
| 1361 libraryElement.parts = sourcedCompilationUnits; | 1364 libraryElement.parts = sourcedCompilationUnits; |
| 1362 for (Directive directive in directivesToResolve) { | 1365 for (Directive directive in directivesToResolve) { |
| 1363 directive.element = libraryElement; | 1366 directive.element = libraryElement; |
| 1364 } | 1367 } |
| 1365 if (sourcedCompilationUnits.isNotEmpty) { | 1368 if (sourcedCompilationUnits.isNotEmpty) { |
| 1366 _patchTopLevelAccessors(libraryElement); | 1369 _patchTopLevelAccessors(libraryElement); |
| 1367 } | 1370 } |
| 1368 if (libraryDirective != null) { | 1371 if (libraryDirective != null) { |
| 1369 _setDocRange(libraryElement, libraryDirective); | 1372 _setDoc(libraryElement, libraryDirective); |
| 1370 } | 1373 } |
| 1371 // | 1374 // |
| 1372 // Record outputs. | 1375 // Record outputs. |
| 1373 // | 1376 // |
| 1374 outputs[BUILD_LIBRARY_ERRORS] = errors; | 1377 outputs[BUILD_LIBRARY_ERRORS] = errors; |
| 1375 outputs[LIBRARY_ELEMENT1] = libraryElement; | 1378 outputs[LIBRARY_ELEMENT1] = libraryElement; |
| 1376 outputs[IS_LAUNCHABLE] = entryPoint != null; | 1379 outputs[IS_LAUNCHABLE] = entryPoint != null; |
| 1377 } | 1380 } |
| 1378 | 1381 |
| 1379 /** | 1382 /** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 TopLevelVariableElementImpl setterVariable = setter.variable; | 1450 TopLevelVariableElementImpl setterVariable = setter.variable; |
| 1448 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; | 1451 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement; |
| 1449 setterUnit.replaceTopLevelVariable(setterVariable, variable); | 1452 setterUnit.replaceTopLevelVariable(setterVariable, variable); |
| 1450 variable.setter = setter; | 1453 variable.setter = setter; |
| 1451 (setter as PropertyAccessorElementImpl).variable = variable; | 1454 (setter as PropertyAccessorElementImpl).variable = variable; |
| 1452 } | 1455 } |
| 1453 } | 1456 } |
| 1454 } | 1457 } |
| 1455 | 1458 |
| 1456 /** | 1459 /** |
| 1457 * If the given [node] has a documentation comment, remember its range | 1460 * If the given [node] has a documentation comment, remember its content |
| 1458 * into the given [element]. | 1461 * and range into the given [element]. |
| 1459 */ | 1462 */ |
| 1460 void _setDocRange(ElementImpl element, AnnotatedNode node) { | 1463 void _setDoc(ElementImpl element, AnnotatedNode node) { |
| 1461 Comment comment = node.documentationComment; | 1464 Comment comment = node.documentationComment; |
| 1462 if (comment != null && comment.isDocumentation) { | 1465 if (comment != null && comment.isDocumentation) { |
| 1466 element.documentationComment = |
| 1467 comment.tokens.map((Token t) => t.lexeme).join('\n'); |
| 1463 element.setDocRange(comment.offset, comment.length); | 1468 element.setDocRange(comment.offset, comment.length); |
| 1464 } | 1469 } |
| 1465 } | 1470 } |
| 1466 | 1471 |
| 1467 /** | 1472 /** |
| 1468 * Return a map from the names of the inputs of this kind of task to the task | 1473 * Return a map from the names of the inputs of this kind of task to the task |
| 1469 * input descriptors describing those inputs for a task with the given | 1474 * input descriptors describing those inputs for a task with the given |
| 1470 * [libSource]. | 1475 * [libSource]. |
| 1471 */ | 1476 */ |
| 1472 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1477 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 // | 1886 // |
| 1882 // Record outputs. | 1887 // Record outputs. |
| 1883 // | 1888 // |
| 1884 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES] = gatherer.results.toList(); | 1889 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES] = gatherer.results.toList(); |
| 1885 } | 1890 } |
| 1886 | 1891 |
| 1887 /** | 1892 /** |
| 1888 * Return `true` if the given [variable] is a static variable whose type | 1893 * Return `true` if the given [variable] is a static variable whose type |
| 1889 * should be inferred. | 1894 * should be inferred. |
| 1890 */ | 1895 */ |
| 1891 bool _isInferableStatic(VariableElement variable) => variable.isStatic && | 1896 bool _isInferableStatic(VariableElement variable) => |
| 1897 variable.isStatic && |
| 1892 variable.hasImplicitType && | 1898 variable.hasImplicitType && |
| 1893 variable.initializer != null; | 1899 variable.initializer != null; |
| 1894 | 1900 |
| 1895 /** | 1901 /** |
| 1896 * Return a map from the names of the inputs of this kind of task to the task | 1902 * Return a map from the names of the inputs of this kind of task to the task |
| 1897 * input descriptors describing those inputs for a task with the | 1903 * input descriptors describing those inputs for a task with the |
| 1898 * given [target]. | 1904 * given [target]. |
| 1899 */ | 1905 */ |
| 1900 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1906 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 1901 if (target is VariableElement) { | 1907 if (target is VariableElement) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2066 // | 2072 // |
| 2067 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES] = gatherer.results.toList(); | 2073 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES] = gatherer.results.toList(); |
| 2068 } | 2074 } |
| 2069 | 2075 |
| 2070 /** | 2076 /** |
| 2071 * Return `true` if the given [variable] is a variable whose type can be | 2077 * Return `true` if the given [variable] is a variable whose type can be |
| 2072 * propagated. | 2078 * propagated. |
| 2073 */ | 2079 */ |
| 2074 bool _isPropagable(VariableElement variable) => | 2080 bool _isPropagable(VariableElement variable) => |
| 2075 variable is PropertyInducingElement && | 2081 variable is PropertyInducingElement && |
| 2076 (variable.isConst || variable.isFinal) && | 2082 (variable.isConst || variable.isFinal) && |
| 2077 variable.hasImplicitType && | 2083 variable.hasImplicitType && |
| 2078 variable.initializer != null; | 2084 variable.initializer != null; |
| 2079 | 2085 |
| 2080 /** | 2086 /** |
| 2081 * Return a map from the names of the inputs of this kind of task to the task | 2087 * Return a map from the names of the inputs of this kind of task to the task |
| 2082 * input descriptors describing those inputs for a task with the | 2088 * input descriptors describing those inputs for a task with the |
| 2083 * given [target]. | 2089 * given [target]. |
| 2084 */ | 2090 */ |
| 2085 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2091 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 2086 if (target is VariableElement) { | 2092 if (target is VariableElement) { |
| 2087 CompilationUnitElementImpl unit = target | 2093 CompilationUnitElementImpl unit = target |
| 2088 .getAncestor((Element element) => element is CompilationUnitElement); | 2094 .getAncestor((Element element) => element is CompilationUnitElement); |
| (...skipping 3242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5331 | 5337 |
| 5332 @override | 5338 @override |
| 5333 bool moveNext() { | 5339 bool moveNext() { |
| 5334 if (_newSources.isEmpty) { | 5340 if (_newSources.isEmpty) { |
| 5335 return false; | 5341 return false; |
| 5336 } | 5342 } |
| 5337 currentTarget = _newSources.removeLast(); | 5343 currentTarget = _newSources.removeLast(); |
| 5338 return true; | 5344 return true; |
| 5339 } | 5345 } |
| 5340 } | 5346 } |
| OLD | NEW |