| 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 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 * The list will be empty if there were no errors, but will not be `null`. | 88 * The list will be empty if there were no errors, but will not be `null`. |
| 89 * | 89 * |
| 90 * The result is only available for targets representing a [ClassElement]. | 90 * The result is only available for targets representing a [ClassElement]. |
| 91 */ | 91 */ |
| 92 final ResultDescriptor<List<AnalysisError>> CONSTRUCTORS_ERRORS = | 92 final ResultDescriptor<List<AnalysisError>> CONSTRUCTORS_ERRORS = |
| 93 new ResultDescriptor<List<AnalysisError>>( | 93 new ResultDescriptor<List<AnalysisError>>( |
| 94 'CONSTRUCTORS_ERRORS', AnalysisError.NO_ERRORS); | 94 'CONSTRUCTORS_ERRORS', AnalysisError.NO_ERRORS); |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * The sources representing the export closure of a library. | 97 * The sources representing the export closure of a library. |
| 98 * The [Source]s include only library sources, not their units. |
| 98 * | 99 * |
| 99 * The result is only available for targets representing a Dart library. | 100 * The result is only available for targets representing a Dart library. |
| 100 */ | 101 */ |
| 101 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = | 102 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = |
| 102 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); | 103 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); |
| 103 | 104 |
| 104 /** | 105 /** |
| 105 * The errors produced while generating hints a compilation unit. | 106 * The errors produced while generating hints a compilation unit. |
| 106 * | 107 * |
| 107 * The list will be empty if there were no errors, but will not be `null`. | 108 * The list will be empty if there were no errors, but will not be `null`. |
| 108 * | 109 * |
| 109 * The result is only available for targets representing a Dart compilation unit
. | 110 * The result is only available for targets representing a Dart compilation unit
. |
| 110 */ | 111 */ |
| 111 final ResultDescriptor<List<AnalysisError>> HINTS = | 112 final ResultDescriptor<List<AnalysisError>> HINTS = |
| 112 new ResultDescriptor<List<AnalysisError>>( | 113 new ResultDescriptor<List<AnalysisError>>( |
| 113 'HINT_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | 114 'HINT_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 114 | 115 |
| 115 /** | 116 /** |
| 117 * The sources representing the import closure of a library. |
| 118 * The [Source]s include only library sources, not their units. |
| 119 * |
| 120 * The result is only available for targets representing a Dart library. |
| 121 */ |
| 122 final ListResultDescriptor<Source> IMPORT_SOURCE_CLOSURE = |
| 123 new ListResultDescriptor<Source>('IMPORT_SOURCE_CLOSURE', null); |
| 124 |
| 125 /** |
| 116 * The partial [LibraryElement] associated with a library. | 126 * The partial [LibraryElement] associated with a library. |
| 117 * | 127 * |
| 118 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each | 128 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each |
| 119 * other. Directives 'library', 'part' and 'part of' are resolved. | 129 * other. Directives 'library', 'part' and 'part of' are resolved. |
| 120 * | 130 * |
| 121 * The result is only available for targets representing a Dart library. | 131 * The result is only available for targets representing a Dart library. |
| 122 */ | 132 */ |
| 123 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = | 133 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = |
| 124 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); | 134 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); |
| 125 | 135 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 * Create a [BuildExportNamespaceTask] based on the given [target] in | 968 * Create a [BuildExportNamespaceTask] based on the given [target] in |
| 959 * the given [context]. | 969 * the given [context]. |
| 960 */ | 970 */ |
| 961 static BuildExportNamespaceTask createTask( | 971 static BuildExportNamespaceTask createTask( |
| 962 AnalysisContext context, AnalysisTarget target) { | 972 AnalysisContext context, AnalysisTarget target) { |
| 963 return new BuildExportNamespaceTask(context, target); | 973 return new BuildExportNamespaceTask(context, target); |
| 964 } | 974 } |
| 965 } | 975 } |
| 966 | 976 |
| 967 /** | 977 /** |
| 968 * A task that builds [EXPORT_SOURCE_CLOSURE] of a library. | |
| 969 */ | |
| 970 class BuildExportSourceClosureTask extends SourceBasedAnalysisTask { | |
| 971 /** | |
| 972 * The name of the input for [LIBRARY_ELEMENT3] of a library. | |
| 973 */ | |
| 974 static const String LIBRARY2_ELEMENT_INPUT = 'LIBRARY2_ELEMENT_INPUT'; | |
| 975 | |
| 976 /** | |
| 977 * The task descriptor describing this kind of task. | |
| 978 */ | |
| 979 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
| 980 'BuildExportSourceClosureTask', createTask, buildInputs, | |
| 981 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]); | |
| 982 | |
| 983 BuildExportSourceClosureTask( | |
| 984 InternalAnalysisContext context, AnalysisTarget target) | |
| 985 : super(context, target); | |
| 986 | |
| 987 @override | |
| 988 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 989 | |
| 990 @override | |
| 991 void internalPerform() { | |
| 992 LibraryElement library = getRequiredInput(LIBRARY2_ELEMENT_INPUT); | |
| 993 // | |
| 994 // Compute export closure. | |
| 995 // | |
| 996 Set<LibraryElement> libraries = new Set<LibraryElement>(); | |
| 997 _buildExportClosure(libraries, library); | |
| 998 List<Source> sources = libraries.map((lib) => lib.source).toList(); | |
| 999 // | |
| 1000 // Record outputs. | |
| 1001 // | |
| 1002 outputs[EXPORT_SOURCE_CLOSURE] = sources; | |
| 1003 } | |
| 1004 | |
| 1005 /** | |
| 1006 * Return a map from the names of the inputs of this kind of task to the task | |
| 1007 * input descriptors describing those inputs for a task with the | |
| 1008 * given library [libSource]. | |
| 1009 */ | |
| 1010 static Map<String, TaskInput> buildInputs(Source libSource) { | |
| 1011 return <String, TaskInput>{ | |
| 1012 LIBRARY2_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(libSource) | |
| 1013 }; | |
| 1014 } | |
| 1015 | |
| 1016 /** | |
| 1017 * Create a [BuildExportSourceClosureTask] based on the given [target] in | |
| 1018 * the given [context]. | |
| 1019 */ | |
| 1020 static BuildExportSourceClosureTask createTask( | |
| 1021 AnalysisContext context, AnalysisTarget target) { | |
| 1022 return new BuildExportSourceClosureTask(context, target); | |
| 1023 } | |
| 1024 | |
| 1025 /** | |
| 1026 * Create a set representing the export closure of the given [library]. | |
| 1027 */ | |
| 1028 static void _buildExportClosure( | |
| 1029 Set<LibraryElement> libraries, LibraryElement library) { | |
| 1030 if (library != null && libraries.add(library)) { | |
| 1031 for (ExportElement exportElement in library.exports) { | |
| 1032 _buildExportClosure(libraries, exportElement.exportedLibrary); | |
| 1033 } | |
| 1034 } | |
| 1035 } | |
| 1036 } | |
| 1037 | |
| 1038 /** | |
| 1039 * A task that builds [RESOLVED_UNIT3] for a unit. | 978 * A task that builds [RESOLVED_UNIT3] for a unit. |
| 1040 */ | 979 */ |
| 1041 class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask { | 980 class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask { |
| 1042 /** | 981 /** |
| 1043 * The name of the [TYPE_PROVIDER] input. | 982 * The name of the [TYPE_PROVIDER] input. |
| 1044 */ | 983 */ |
| 1045 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 984 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
| 1046 | 985 |
| 1047 /** | 986 /** |
| 1048 * The name of the [LIBRARY_ELEMENT4] input. | 987 * The name of the [LIBRARY_ELEMENT4] input. |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 * Create a [BuildPublicNamespaceTask] based on the given [target] in | 1429 * Create a [BuildPublicNamespaceTask] based on the given [target] in |
| 1491 * the given [context]. | 1430 * the given [context]. |
| 1492 */ | 1431 */ |
| 1493 static BuildPublicNamespaceTask createTask( | 1432 static BuildPublicNamespaceTask createTask( |
| 1494 AnalysisContext context, AnalysisTarget target) { | 1433 AnalysisContext context, AnalysisTarget target) { |
| 1495 return new BuildPublicNamespaceTask(context, target); | 1434 return new BuildPublicNamespaceTask(context, target); |
| 1496 } | 1435 } |
| 1497 } | 1436 } |
| 1498 | 1437 |
| 1499 /** | 1438 /** |
| 1439 * A task that builds [IMPORT_SOURCE_CLOSURE] and [EXPORT_SOURCE_CLOSURE] of |
| 1440 * a library. |
| 1441 */ |
| 1442 class BuildSourceClosuresTask extends SourceBasedAnalysisTask { |
| 1443 /** |
| 1444 * The name of the import closure. |
| 1445 */ |
| 1446 static const String IMPORT_CLOSURE_INPUT = 'IMPORT_CLOSURE_INPUT'; |
| 1447 |
| 1448 /** |
| 1449 * The name of the export closure. |
| 1450 */ |
| 1451 static const String EXPORT_CLOSURE_INPUT = 'EXPORT_CLOSURE_INPUT'; |
| 1452 |
| 1453 /** |
| 1454 * The task descriptor describing this kind of task. |
| 1455 */ |
| 1456 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1457 'BuildExportSourceClosureTask', createTask, buildInputs, |
| 1458 <ResultDescriptor>[IMPORT_SOURCE_CLOSURE, EXPORT_SOURCE_CLOSURE]); |
| 1459 |
| 1460 BuildSourceClosuresTask( |
| 1461 InternalAnalysisContext context, AnalysisTarget target) |
| 1462 : super(context, target); |
| 1463 |
| 1464 @override |
| 1465 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1466 |
| 1467 @override |
| 1468 void internalPerform() { |
| 1469 List<Source> importClosure = getRequiredInput(IMPORT_CLOSURE_INPUT); |
| 1470 List<Source> exportClosure = getRequiredInput(EXPORT_CLOSURE_INPUT); |
| 1471 // |
| 1472 // Record outputs. |
| 1473 // |
| 1474 outputs[IMPORT_SOURCE_CLOSURE] = importClosure; |
| 1475 outputs[EXPORT_SOURCE_CLOSURE] = exportClosure; |
| 1476 } |
| 1477 |
| 1478 /** |
| 1479 * Return a map from the names of the inputs of this kind of task to the task |
| 1480 * input descriptors describing those inputs for a task with the |
| 1481 * given library [libSource]. |
| 1482 */ |
| 1483 static Map<String, TaskInput> buildInputs(Source libSource) { |
| 1484 return <String, TaskInput>{ |
| 1485 IMPORT_CLOSURE_INPUT: new _ImportSourceClosureTaskInput(libSource), |
| 1486 EXPORT_CLOSURE_INPUT: new _ExportSourceClosureTaskInput(libSource) |
| 1487 }; |
| 1488 } |
| 1489 |
| 1490 /** |
| 1491 * Create a [BuildSourceClosuresTask] based on the given [target] in |
| 1492 * the given [context]. |
| 1493 */ |
| 1494 static BuildSourceClosuresTask createTask( |
| 1495 AnalysisContext context, AnalysisTarget target) { |
| 1496 return new BuildSourceClosuresTask(context, target); |
| 1497 } |
| 1498 } |
| 1499 |
| 1500 /** |
| 1500 * A task that builds [TYPE_PROVIDER] for a context. | 1501 * A task that builds [TYPE_PROVIDER] for a context. |
| 1501 */ | 1502 */ |
| 1502 class BuildTypeProviderTask extends SourceBasedAnalysisTask { | 1503 class BuildTypeProviderTask extends SourceBasedAnalysisTask { |
| 1503 /** | 1504 /** |
| 1504 * The [PUBLIC_NAMESPACE] input of the `dart:core` library. | 1505 * The [PUBLIC_NAMESPACE] input of the `dart:core` library. |
| 1505 */ | 1506 */ |
| 1506 static const String CORE_INPUT = 'CORE_INPUT'; | 1507 static const String CORE_INPUT = 'CORE_INPUT'; |
| 1507 | 1508 |
| 1508 /** | 1509 /** |
| 1509 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. | 1510 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 | 2363 |
| 2363 /** | 2364 /** |
| 2364 * Create a [VerifyUnitTask] based on the given [target] in | 2365 * Create a [VerifyUnitTask] based on the given [target] in |
| 2365 * the given [context]. | 2366 * the given [context]. |
| 2366 */ | 2367 */ |
| 2367 static VerifyUnitTask createTask( | 2368 static VerifyUnitTask createTask( |
| 2368 AnalysisContext context, AnalysisTarget target) { | 2369 AnalysisContext context, AnalysisTarget target) { |
| 2369 return new VerifyUnitTask(context, target); | 2370 return new VerifyUnitTask(context, target); |
| 2370 } | 2371 } |
| 2371 } | 2372 } |
| 2373 |
| 2374 /** |
| 2375 * A [TaskInput] whose value is a list of library sources exported directly |
| 2376 * or indirectly by the target [Source]. |
| 2377 */ |
| 2378 class _ExportSourceClosureTaskInput implements TaskInput<List<Source>> { |
| 2379 final Source target; |
| 2380 |
| 2381 _ExportSourceClosureTaskInput(this.target); |
| 2382 |
| 2383 @override |
| 2384 TaskInputBuilder<List<Source>> createBuilder() => |
| 2385 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.EXPORT); |
| 2386 } |
| 2387 |
| 2388 /** |
| 2389 * A [TaskInput] whose value is a list of library sources imported directly |
| 2390 * or indirectly by the target [Source]. |
| 2391 */ |
| 2392 class _ImportSourceClosureTaskInput implements TaskInput<List<Source>> { |
| 2393 final Source target; |
| 2394 |
| 2395 _ImportSourceClosureTaskInput(this.target); |
| 2396 |
| 2397 @override |
| 2398 TaskInputBuilder<List<Source>> createBuilder() => |
| 2399 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.IMPORT); |
| 2400 } |
| 2401 |
| 2402 /** |
| 2403 * The kind of the source closure to build. |
| 2404 */ |
| 2405 enum _SourceClosureKind { IMPORT, EXPORT } |
| 2406 |
| 2407 /** |
| 2408 * A [TaskInputBuilder] to build values for [_ImportSourceClosureTaskInput]. |
| 2409 */ |
| 2410 class _SourceClosureTaskInputBuilder implements TaskInputBuilder<List<Source>> { |
| 2411 final _SourceClosureKind kind; |
| 2412 final Set<LibraryElement> _libraries = new HashSet<LibraryElement>(); |
| 2413 final Set<Source> _newSources = new HashSet<Source>(); |
| 2414 |
| 2415 Source currentTarget; |
| 2416 |
| 2417 _SourceClosureTaskInputBuilder(Source librarySource, this.kind) { |
| 2418 _newSources.add(librarySource); |
| 2419 } |
| 2420 |
| 2421 @override |
| 2422 ResultDescriptor get currentResult => LIBRARY_ELEMENT2; |
| 2423 |
| 2424 @override |
| 2425 void set currentValue(LibraryElement library) { |
| 2426 if (_libraries.add(library)) { |
| 2427 if (kind == _SourceClosureKind.IMPORT) { |
| 2428 for (ImportElement importElement in library.imports) { |
| 2429 Source importedSource = importElement.importedLibrary.source; |
| 2430 _newSources.add(importedSource); |
| 2431 } |
| 2432 } else { |
| 2433 for (ExportElement exportElement in library.exports) { |
| 2434 Source importedSource = exportElement.exportedLibrary.source; |
| 2435 _newSources.add(importedSource); |
| 2436 } |
| 2437 } |
| 2438 } |
| 2439 } |
| 2440 |
| 2441 @override |
| 2442 List<Source> get inputValue { |
| 2443 return _libraries.map((LibraryElement library) => library.source).toList(); |
| 2444 } |
| 2445 |
| 2446 @override |
| 2447 bool moveNext() { |
| 2448 if (_newSources.isEmpty) { |
| 2449 return false; |
| 2450 } |
| 2451 currentTarget = _newSources.first; |
| 2452 _newSources.remove(currentTarget); |
| 2453 return true; |
| 2454 } |
| 2455 } |
| OLD | NEW |