| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 new ResultDescriptor<List<AnalysisError>>( | 285 new ResultDescriptor<List<AnalysisError>>( |
| 286 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | 286 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * The [TypeProvider] of the context. | 289 * The [TypeProvider] of the context. |
| 290 */ | 290 */ |
| 291 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = | 291 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = |
| 292 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); | 292 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * The used [Element]s of a [LibraryUnitTarget]. |
| 296 */ |
| 297 final ResultDescriptor<UsedElements> USED_ELEMENTS = |
| 298 new ResultDescriptor<UsedElements>('USED_ELEMENTS', null); |
| 299 |
| 300 /** |
| 295 * The errors produced while verifying a compilation unit. | 301 * The errors produced while verifying a compilation unit. |
| 296 * | 302 * |
| 297 * The list will be empty if there were no errors, but will not be `null`. | 303 * The list will be empty if there were no errors, but will not be `null`. |
| 298 * | 304 * |
| 299 * The result is only available for targets representing a Dart compilation unit
. | 305 * The result is only available for targets representing a Dart compilation unit
. |
| 300 */ | 306 */ |
| 301 final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS = | 307 final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS = |
| 302 new ResultDescriptor<List<AnalysisError>>( | 308 new ResultDescriptor<List<AnalysisError>>( |
| 303 'VERIFY_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | 309 'VERIFY_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 304 | 310 |
| (...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 element = definedNames[setterName]; | 1663 element = definedNames[setterName]; |
| 1658 if (element != null) { | 1664 if (element != null) { |
| 1659 newNames[setterName] = element; | 1665 newNames[setterName] = element; |
| 1660 } | 1666 } |
| 1661 } | 1667 } |
| 1662 return newNames; | 1668 return newNames; |
| 1663 } | 1669 } |
| 1664 } | 1670 } |
| 1665 | 1671 |
| 1666 /** | 1672 /** |
| 1673 * A task that builds [USED_ELEMENTS] for a unit. |
| 1674 */ |
| 1675 class GatherUsedElementsTask extends SourceBasedAnalysisTask { |
| 1676 /** |
| 1677 * The name of the [RESOLVED_UNIT] input. |
| 1678 */ |
| 1679 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1680 |
| 1681 /** |
| 1682 * The task descriptor describing this kind of task. |
| 1683 */ |
| 1684 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1685 'GatherUsedElementsTask', createTask, buildInputs, |
| 1686 <ResultDescriptor>[USED_ELEMENTS]); |
| 1687 |
| 1688 GatherUsedElementsTask(InternalAnalysisContext context, AnalysisTarget target) |
| 1689 : super(context, target); |
| 1690 |
| 1691 @override |
| 1692 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1693 |
| 1694 @override |
| 1695 void internalPerform() { |
| 1696 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 1697 CompilationUnitElement unitElement = unit.element; |
| 1698 LibraryElement libraryElement = unitElement.library; |
| 1699 // |
| 1700 // Prepare visited elements. |
| 1701 // |
| 1702 GatherUsedElementsVisitor visitor = |
| 1703 new GatherUsedElementsVisitor(libraryElement); |
| 1704 unit.accept(visitor); |
| 1705 // |
| 1706 // Record outputs. |
| 1707 // |
| 1708 outputs[USED_ELEMENTS] = visitor.usedElements; |
| 1709 } |
| 1710 |
| 1711 /** |
| 1712 * Return a map from the names of the inputs of this kind of task to the task |
| 1713 * input descriptors describing those inputs for a task with the |
| 1714 * given [target]. |
| 1715 */ |
| 1716 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 1717 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; |
| 1718 } |
| 1719 |
| 1720 /** |
| 1721 * Create a [GatherUsedElementsTask] based on the given [target] in |
| 1722 * the given [context]. |
| 1723 */ |
| 1724 static GatherUsedElementsTask createTask( |
| 1725 AnalysisContext context, LibraryUnitTarget target) { |
| 1726 return new GatherUsedElementsTask(context, target); |
| 1727 } |
| 1728 } |
| 1729 |
| 1730 /** |
| 1667 * A task that generates [HINTS] for a unit. | 1731 * A task that generates [HINTS] for a unit. |
| 1668 */ | 1732 */ |
| 1669 class GenerateHintsTask extends SourceBasedAnalysisTask { | 1733 class GenerateHintsTask extends SourceBasedAnalysisTask { |
| 1670 /** | 1734 /** |
| 1671 * The name of the [RESOLVED_UNIT] input. | 1735 * The name of the [RESOLVED_UNIT] input. |
| 1672 */ | 1736 */ |
| 1673 static const String UNIT_INPUT = 'UNIT_INPUT'; | 1737 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1674 | 1738 |
| 1675 /** | 1739 /** |
| 1676 * The task descriptor describing this kind of task. | 1740 * The task descriptor describing this kind of task. |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2383 final Source target; | 2447 final Source target; |
| 2384 | 2448 |
| 2385 _ExportSourceClosureTaskInput(this.target); | 2449 _ExportSourceClosureTaskInput(this.target); |
| 2386 | 2450 |
| 2387 @override | 2451 @override |
| 2388 TaskInputBuilder<List<Source>> createBuilder() => | 2452 TaskInputBuilder<List<Source>> createBuilder() => |
| 2389 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.EXPORT); | 2453 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.EXPORT); |
| 2390 } | 2454 } |
| 2391 | 2455 |
| 2392 /** | 2456 /** |
| 2457 * The kind of the source closure to build. |
| 2458 */ |
| 2459 enum _SourceClosureKind { IMPORT, EXPORT } |
| 2460 |
| 2461 /** |
| 2393 * A [TaskInput] whose value is a list of library sources imported directly | 2462 * A [TaskInput] whose value is a list of library sources imported directly |
| 2394 * or indirectly by the target [Source]. | 2463 * or indirectly by the target [Source]. |
| 2395 */ | 2464 */ |
| 2396 class _ImportSourceClosureTaskInput implements TaskInput<List<Source>> { | 2465 class _ImportSourceClosureTaskInput implements TaskInput<List<Source>> { |
| 2397 final Source target; | 2466 final Source target; |
| 2398 | 2467 |
| 2399 _ImportSourceClosureTaskInput(this.target); | 2468 _ImportSourceClosureTaskInput(this.target); |
| 2400 | 2469 |
| 2401 @override | 2470 @override |
| 2402 TaskInputBuilder<List<Source>> createBuilder() => | 2471 TaskInputBuilder<List<Source>> createBuilder() => |
| 2403 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.IMPORT); | 2472 new _SourceClosureTaskInputBuilder(target, _SourceClosureKind.IMPORT); |
| 2404 } | 2473 } |
| 2405 | 2474 |
| 2406 /** | 2475 /** |
| 2407 * The kind of the source closure to build. | |
| 2408 */ | |
| 2409 enum _SourceClosureKind { IMPORT, EXPORT } | |
| 2410 | |
| 2411 /** | |
| 2412 * A [TaskInputBuilder] to build values for [_ImportSourceClosureTaskInput]. | 2476 * A [TaskInputBuilder] to build values for [_ImportSourceClosureTaskInput]. |
| 2413 */ | 2477 */ |
| 2414 class _SourceClosureTaskInputBuilder implements TaskInputBuilder<List<Source>> { | 2478 class _SourceClosureTaskInputBuilder implements TaskInputBuilder<List<Source>> { |
| 2415 final _SourceClosureKind kind; | 2479 final _SourceClosureKind kind; |
| 2416 final Set<LibraryElement> _libraries = new HashSet<LibraryElement>(); | 2480 final Set<LibraryElement> _libraries = new HashSet<LibraryElement>(); |
| 2417 final Set<Source> _newSources = new HashSet<Source>(); | 2481 final Set<Source> _newSources = new HashSet<Source>(); |
| 2418 | 2482 |
| 2419 Source currentTarget; | 2483 Source currentTarget; |
| 2420 | 2484 |
| 2421 _SourceClosureTaskInputBuilder(Source librarySource, this.kind) { | 2485 _SourceClosureTaskInputBuilder(Source librarySource, this.kind) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2450 @override | 2514 @override |
| 2451 bool moveNext() { | 2515 bool moveNext() { |
| 2452 if (_newSources.isEmpty) { | 2516 if (_newSources.isEmpty) { |
| 2453 return false; | 2517 return false; |
| 2454 } | 2518 } |
| 2455 currentTarget = _newSources.first; | 2519 currentTarget = _newSources.first; |
| 2456 _newSources.remove(currentTarget); | 2520 _newSources.remove(currentTarget); |
| 2457 return true; | 2521 return true; |
| 2458 } | 2522 } |
| 2459 } | 2523 } |
| OLD | NEW |