| 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/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * The list will be empty if there were no errors, but will not be `null`. | 30 * The list will be empty if there were no errors, but will not be `null`. |
| 31 * | 31 * |
| 32 * The result is only available for targets representing a Dart library. | 32 * The result is only available for targets representing a Dart library. |
| 33 */ | 33 */ |
| 34 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS = | 34 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS = |
| 35 new ResultDescriptor<List<AnalysisError>>( | 35 new ResultDescriptor<List<AnalysisError>>( |
| 36 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS, | 36 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS, |
| 37 contributesTo: DART_ERRORS); | 37 contributesTo: DART_ERRORS); |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * The errors produced while builing a library element. | 40 * The errors produced while building a library element. |
| 41 * | 41 * |
| 42 * The list will be empty if there were no errors, but will not be `null`. | 42 * The list will be empty if there were no errors, but will not be `null`. |
| 43 * | 43 * |
| 44 * The result is only available for targets representing a Dart library. | 44 * The result is only available for targets representing a Dart library. |
| 45 */ | 45 */ |
| 46 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = | 46 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = |
| 47 new ResultDescriptor<List<AnalysisError>>( | 47 new ResultDescriptor<List<AnalysisError>>( |
| 48 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, | 48 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, |
| 49 contributesTo: DART_ERRORS); | 49 contributesTo: DART_ERRORS); |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * The errors produced while building function type aliases. |
| 53 * |
| 54 * The list will be empty if there were no errors, but will not be `null`. |
| 55 * |
| 56 * The result is only available for targets representing a Dart library. |
| 57 */ |
| 58 final ResultDescriptor<List<AnalysisError>> BUILD_FUNCTION_TYPE_ALIASES_ERRORS = |
| 59 new ResultDescriptor<List<AnalysisError>>( |
| 60 'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS, |
| 61 contributesTo: DART_ERRORS); |
| 62 |
| 63 /** |
| 52 * The export [Namespace] of a library. | 64 * The export [Namespace] of a library. |
| 53 * | 65 * |
| 54 * The result is only available for targets representing a Dart library. | 66 * The result is only available for targets representing a Dart library. |
| 55 */ | 67 */ |
| 56 final ResultDescriptor<Namespace> EXPORT_NAMESPACE = | 68 final ResultDescriptor<Namespace> EXPORT_NAMESPACE = |
| 57 new ResultDescriptor<Namespace>('EXPORT_NAMESPACE', null); | 69 new ResultDescriptor<Namespace>('EXPORT_NAMESPACE', null); |
| 58 | 70 |
| 59 /** | 71 /** |
| 60 * The sources representing the export closure of a library. | 72 * The sources representing the export closure of a library. |
| 61 * | 73 * |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 * The partially resolved [CompilationUnit] associated with a unit. | 143 * The partially resolved [CompilationUnit] associated with a unit. |
| 132 * | 144 * |
| 133 * All the enum member elements are built. | 145 * All the enum member elements are built. |
| 134 * | 146 * |
| 135 * The result is only available for targets representing a unit. | 147 * The result is only available for targets representing a unit. |
| 136 */ | 148 */ |
| 137 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = | 149 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = |
| 138 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null); | 150 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null); |
| 139 | 151 |
| 140 /** | 152 /** |
| 153 * The partially resolved [CompilationUnit] associated with a unit. |
| 154 * |
| 155 * All the function type aliases are resolved. |
| 156 * |
| 157 * The result is only available for targets representing a unit. |
| 158 */ |
| 159 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 = |
| 160 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null); |
| 161 |
| 162 /** |
| 141 * The [TypeProvider] of the context. | 163 * The [TypeProvider] of the context. |
| 142 */ | 164 */ |
| 143 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = | 165 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = |
| 144 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); | 166 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); |
| 145 | 167 |
| 146 /** | 168 /** |
| 147 * A task that builds a compilation unit element for a single compilation unit. | 169 * A task that builds a compilation unit element for a single compilation unit. |
| 148 */ | 170 */ |
| 149 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { | 171 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { |
| 150 /** | 172 /** |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 Set<LibraryElement> libraries, LibraryElement library) { | 698 Set<LibraryElement> libraries, LibraryElement library) { |
| 677 if (library != null && libraries.add(library)) { | 699 if (library != null && libraries.add(library)) { |
| 678 for (ExportElement exportElement in library.exports) { | 700 for (ExportElement exportElement in library.exports) { |
| 679 _buildExportClosure(libraries, exportElement.exportedLibrary); | 701 _buildExportClosure(libraries, exportElement.exportedLibrary); |
| 680 } | 702 } |
| 681 } | 703 } |
| 682 } | 704 } |
| 683 } | 705 } |
| 684 | 706 |
| 685 /** | 707 /** |
| 708 * A task that builds [RESOLVED_UNIT5] for a library. |
| 709 */ |
| 710 class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask { |
| 711 /** |
| 712 * The name of the [TYPE_PROVIDER] input. |
| 713 */ |
| 714 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
| 715 |
| 716 /** |
| 717 * The [EXPORT_NAMESPACE]s of imported libraries input. |
| 718 */ |
| 719 static const String IMPORTS_EXPORT_NAMESPACE_INPUT = |
| 720 'IMPORTS_EXPORT_NAMESPACE_INPUT'; |
| 721 |
| 722 /** |
| 723 * The name of the [RESOLVED_UNIT3] input. |
| 724 */ |
| 725 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 726 |
| 727 /** |
| 728 * The task descriptor describing this kind of task. |
| 729 */ |
| 730 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 731 'BuildFunctionTypeAliasesTask', createTask, buildInputs, |
| 732 <ResultDescriptor>[BUILD_FUNCTION_TYPE_ALIASES_ERRORS, RESOLVED_UNIT5]); |
| 733 |
| 734 BuildFunctionTypeAliasesTask( |
| 735 InternalAnalysisContext context, AnalysisTarget target) |
| 736 : super(context, target); |
| 737 |
| 738 @override |
| 739 TaskDescriptor get descriptor => DESCRIPTOR; |
| 740 |
| 741 @override |
| 742 void internalPerform() { |
| 743 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 744 // |
| 745 // Prepare inputs. |
| 746 // |
| 747 Source source = getRequiredSource(); |
| 748 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
| 749 Map<Source, Namespace> exportNamespaces = |
| 750 getRequiredInput(IMPORTS_EXPORT_NAMESPACE_INPUT); |
| 751 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 752 // |
| 753 // Build scopes. |
| 754 // |
| 755 LibraryElement libraryElement = unit.element.library; |
| 756 Scope importScope = new LibraryImportScopeNew( |
| 757 libraryElement, exportNamespaces, errorListener); |
| 758 LibraryScope libraryScope = |
| 759 new LibraryScope(libraryElement, importScope, errorListener); |
| 760 // |
| 761 // Resolve FunctionTypeAlias declarations. |
| 762 // |
| 763 TypeResolverVisitor visitor = new TypeResolverVisitor.con2( |
| 764 libraryElement, libraryScope, source, typeProvider, errorListener); |
| 765 for (CompilationUnitMember member in unit.declarations) { |
| 766 if (member is FunctionTypeAlias) { |
| 767 member.accept(visitor); |
| 768 } |
| 769 } |
| 770 // |
| 771 // Record outputs. |
| 772 // |
| 773 outputs[BUILD_FUNCTION_TYPE_ALIASES_ERRORS] = errorListener.errors; |
| 774 outputs[RESOLVED_UNIT5] = unit; |
| 775 } |
| 776 |
| 777 /** |
| 778 * Return a map from the names of the inputs of this kind of task to the task |
| 779 * input descriptors describing those inputs for a task with the |
| 780 * given [target]. |
| 781 */ |
| 782 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 783 return <String, TaskInput>{ |
| 784 TYPE_PROVIDER_INPUT: |
| 785 TYPE_PROVIDER.inputFor(AnalysisContextTarget.request), |
| 786 IMPORTS_EXPORT_NAMESPACE_INPUT: new ListToMapTaskInput<Source, Namespace>( |
| 787 IMPORTED_LIBRARIES.inputFor(target.library), |
| 788 (Source importSource) => EXPORT_NAMESPACE.inputFor(importSource)), |
| 789 UNIT_INPUT: RESOLVED_UNIT4.inputFor(target.unit) |
| 790 }; |
| 791 } |
| 792 |
| 793 /** |
| 794 * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in |
| 795 * the given [context]. |
| 796 */ |
| 797 static BuildFunctionTypeAliasesTask createTask( |
| 798 AnalysisContext context, AnalysisTarget target) { |
| 799 return new BuildFunctionTypeAliasesTask(context, target); |
| 800 } |
| 801 } |
| 802 |
| 803 /** |
| 686 * A task that builds a library element for a Dart library. | 804 * A task that builds a library element for a Dart library. |
| 687 */ | 805 */ |
| 688 class BuildLibraryElementTask extends SourceBasedAnalysisTask { | 806 class BuildLibraryElementTask extends SourceBasedAnalysisTask { |
| 689 /** | 807 /** |
| 690 * The name of the input whose value is the defining [RESOLVED_UNIT1]. | 808 * The name of the input whose value is the defining [RESOLVED_UNIT1]. |
| 691 */ | 809 */ |
| 692 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME = | 810 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME = |
| 693 'DEFINING_RESOLVER_UNIT1_INPUT_NAME'; | 811 'DEFINING_RESOLVER_UNIT1_INPUT_NAME'; |
| 694 | 812 |
| 695 /** | 813 /** |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 element = definedNames[setterName]; | 1284 element = definedNames[setterName]; |
| 1167 if (element != null) { | 1285 if (element != null) { |
| 1168 newNames[setterName] = element; | 1286 newNames[setterName] = element; |
| 1169 } | 1287 } |
| 1170 } | 1288 } |
| 1171 return newNames; | 1289 return newNames; |
| 1172 } | 1290 } |
| 1173 } | 1291 } |
| 1174 | 1292 |
| 1175 /** | 1293 /** |
| 1294 * The scope containing all of the names available from imported libraries. |
| 1295 */ |
| 1296 class LibraryImportScopeNew extends LibraryImportScope { |
| 1297 final Map<Source, Namespace> exportNamespaces; |
| 1298 |
| 1299 LibraryImportScopeNew(LibraryElement definingLibrary, this.exportNamespaces, |
| 1300 AnalysisErrorListener errorListener) |
| 1301 : super(definingLibrary, errorListener); |
| 1302 |
| 1303 /** |
| 1304 * Create the import [Namespace] of the given [LibraryElement]. |
| 1305 */ |
| 1306 Namespace buildImportElementNamespace(ImportElement element) { |
| 1307 LibraryElement importedLibrary = element.importedLibrary; |
| 1308 // Check that the URI references a valid library. |
| 1309 if (importedLibrary == null) { |
| 1310 return Namespace.EMPTY; |
| 1311 } |
| 1312 // Prepare exported names. |
| 1313 Source importedSource = importedLibrary.source; |
| 1314 Namespace exportNamespace = exportNamespaces[importedSource]; |
| 1315 HashMap<String, Element> definedNames = exportNamespace.definedNames; |
| 1316 // Apply the combinators and prefix. |
| 1317 definedNames = ExportNamespaceBuilder._applyCombinators( |
| 1318 definedNames, element.combinators); |
| 1319 definedNames = _applyPrefix(definedNames, element.prefix); |
| 1320 return new Namespace(definedNames); |
| 1321 } |
| 1322 |
| 1323 @override |
| 1324 void createImportedNamespaces() { |
| 1325 for (ImportElement import in definingLibrary.imports) { |
| 1326 Namespace namespace = buildImportElementNamespace(import); |
| 1327 importedNamespaces.add(namespace); |
| 1328 } |
| 1329 } |
| 1330 |
| 1331 /** |
| 1332 * Apply the given [prefixElement] to all of the names in [definedNames]. |
| 1333 */ |
| 1334 static HashMap<String, Element> _applyPrefix( |
| 1335 HashMap<String, Element> definedNames, PrefixElement prefixElement) { |
| 1336 if (prefixElement != null) { |
| 1337 String prefix = prefixElement.name; |
| 1338 HashMap<String, Element> newNames = new HashMap<String, Element>(); |
| 1339 definedNames.forEach((String name, Element element) { |
| 1340 newNames['$prefix.$name'] = element; |
| 1341 }); |
| 1342 return newNames; |
| 1343 } else { |
| 1344 return definedNames; |
| 1345 } |
| 1346 } |
| 1347 } |
| 1348 |
| 1349 /** |
| 1176 * A pair of a library [Source] and a unit [Source] in this library. | 1350 * A pair of a library [Source] and a unit [Source] in this library. |
| 1177 */ | 1351 */ |
| 1178 class LibraryUnitTarget implements AnalysisTarget { | 1352 class LibraryUnitTarget implements AnalysisTarget { |
| 1179 final Source library; | 1353 final Source library; |
| 1180 final Source unit; | 1354 final Source unit; |
| 1355 |
| 1181 LibraryUnitTarget(this.library, this.unit); | 1356 LibraryUnitTarget(this.library, this.unit); |
| 1182 | 1357 |
| 1183 @override | 1358 @override |
| 1184 int get hashCode { | 1359 int get hashCode { |
| 1185 return JenkinsSmiHash.combine(library.hashCode, unit.hashCode); | 1360 return JenkinsSmiHash.combine(library.hashCode, unit.hashCode); |
| 1186 } | 1361 } |
| 1187 | 1362 |
| 1188 @override | 1363 @override |
| 1189 Source get source => unit; | 1364 Source get source => unit; |
| 1190 | 1365 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 } | 1630 } |
| 1456 | 1631 |
| 1457 /** | 1632 /** |
| 1458 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1633 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1459 */ | 1634 */ |
| 1460 static ScanDartTask createTask( | 1635 static ScanDartTask createTask( |
| 1461 AnalysisContext context, AnalysisTarget target) { | 1636 AnalysisContext context, AnalysisTarget target) { |
| 1462 return new ScanDartTask(context, target); | 1637 return new ScanDartTask(context, target); |
| 1463 } | 1638 } |
| 1464 } | 1639 } |
| OLD | NEW |