| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 * | 98 * |
| 99 * The result is only available for targets representing a Dart library. | 99 * The result is only available for targets representing a Dart library. |
| 100 */ | 100 */ |
| 101 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = | 101 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = |
| 102 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); | 102 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * The errors produced while generating hints a compilation unit. |
| 106 * |
| 107 * The list will be empty if there were no errors, but will not be `null`. |
| 108 * |
| 109 * The result is only available for targets representing a Dart compilation unit
. |
| 110 */ |
| 111 final ResultDescriptor<List<AnalysisError>> HINTS = |
| 112 new ResultDescriptor<List<AnalysisError>>( |
| 113 'HINT_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 114 |
| 115 /** |
| 105 * The partial [LibraryElement] associated with a library. | 116 * The partial [LibraryElement] associated with a library. |
| 106 * | 117 * |
| 107 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each | 118 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each |
| 108 * other. Directives 'library', 'part' and 'part of' are resolved. | 119 * other. Directives 'library', 'part' and 'part of' are resolved. |
| 109 * | 120 * |
| 110 * The result is only available for targets representing a Dart library. | 121 * The result is only available for targets representing a Dart library. |
| 111 */ | 122 */ |
| 112 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = | 123 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = |
| 113 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); | 124 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); |
| 114 | 125 |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 element = definedNames[setterName]; | 1655 element = definedNames[setterName]; |
| 1645 if (element != null) { | 1656 if (element != null) { |
| 1646 newNames[setterName] = element; | 1657 newNames[setterName] = element; |
| 1647 } | 1658 } |
| 1648 } | 1659 } |
| 1649 return newNames; | 1660 return newNames; |
| 1650 } | 1661 } |
| 1651 } | 1662 } |
| 1652 | 1663 |
| 1653 /** | 1664 /** |
| 1665 * A task that generates [HINTS] for a unit. |
| 1666 */ |
| 1667 class GenerateHintsTask extends SourceBasedAnalysisTask { |
| 1668 /** |
| 1669 * The name of the [RESOLVED_UNIT] input. |
| 1670 */ |
| 1671 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1672 |
| 1673 /** |
| 1674 * The task descriptor describing this kind of task. |
| 1675 */ |
| 1676 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1677 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]); |
| 1678 |
| 1679 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target) |
| 1680 : super(context, target); |
| 1681 |
| 1682 @override |
| 1683 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1684 |
| 1685 @override |
| 1686 void internalPerform() { |
| 1687 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 1688 Source source = getRequiredSource(); |
| 1689 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 1690 // |
| 1691 // Prepare inputs. |
| 1692 // |
| 1693 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 1694 CompilationUnitElement unitElement = unit.element; |
| 1695 LibraryElement libraryElement = unitElement.library; |
| 1696 // |
| 1697 // Use the HintGenerator to generate errors. |
| 1698 // |
| 1699 // TODO(scheglov) move collecting used imports into a separate task |
| 1700 // unit.accept(_importsVerifier); |
| 1701 // Dead code analysis. |
| 1702 unit.accept(new DeadCodeVerifier(errorReporter)); |
| 1703 // TODO(scheglov) move collecting used elements into a separate task |
| 1704 // unit.accept(_usedElementsVisitor); |
| 1705 // Dart2js analysis. |
| 1706 if (context.analysisOptions.dart2jsHint) { |
| 1707 unit.accept(new Dart2JSVerifier(errorReporter)); |
| 1708 } |
| 1709 // Dart best practices. |
| 1710 InheritanceManager inheritanceManager = |
| 1711 new InheritanceManager(libraryElement); |
| 1712 TypeProvider typeProvider = context.typeProvider; |
| 1713 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider)); |
| 1714 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); |
| 1715 // Find to-do comments. |
| 1716 new ToDoFinder(errorReporter).findIn(unit); |
| 1717 // |
| 1718 // Record outputs. |
| 1719 // |
| 1720 outputs[HINTS] = errorListener.errors; |
| 1721 } |
| 1722 |
| 1723 /** |
| 1724 * Return a map from the names of the inputs of this kind of task to the task |
| 1725 * input descriptors describing those inputs for a task with the |
| 1726 * given [target]. |
| 1727 */ |
| 1728 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 1729 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; |
| 1730 } |
| 1731 |
| 1732 /** |
| 1733 * Create a [GenerateHintsTask] based on the given [target] in |
| 1734 * the given [context]. |
| 1735 */ |
| 1736 static GenerateHintsTask createTask( |
| 1737 AnalysisContext context, AnalysisTarget target) { |
| 1738 return new GenerateHintsTask(context, target); |
| 1739 } |
| 1740 } |
| 1741 |
| 1742 /** |
| 1654 * A pair of a library [Source] and a unit [Source] in this library. | 1743 * A pair of a library [Source] and a unit [Source] in this library. |
| 1655 */ | 1744 */ |
| 1656 class LibraryUnitTarget implements AnalysisTarget { | 1745 class LibraryUnitTarget implements AnalysisTarget { |
| 1657 final Source library; | 1746 final Source library; |
| 1658 final Source unit; | 1747 final Source unit; |
| 1659 | 1748 |
| 1660 LibraryUnitTarget(this.library, this.unit); | 1749 LibraryUnitTarget(this.library, this.unit); |
| 1661 | 1750 |
| 1662 @override | 1751 @override |
| 1663 int get hashCode { | 1752 int get hashCode { |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 | 2360 |
| 2272 /** | 2361 /** |
| 2273 * Create a [VerifyUnitTask] based on the given [target] in | 2362 * Create a [VerifyUnitTask] based on the given [target] in |
| 2274 * the given [context]. | 2363 * the given [context]. |
| 2275 */ | 2364 */ |
| 2276 static VerifyUnitTask createTask( | 2365 static VerifyUnitTask createTask( |
| 2277 AnalysisContext context, AnalysisTarget target) { | 2366 AnalysisContext context, AnalysisTarget target) { |
| 2278 return new VerifyUnitTask(context, target); | 2367 return new VerifyUnitTask(context, target); |
| 2279 } | 2368 } |
| 2280 } | 2369 } |
| OLD | NEW |