| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 new ResultDescriptor<List<AnalysisError>>( | 284 new ResultDescriptor<List<AnalysisError>>( |
| 285 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); | 285 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * The [TypeProvider] of the context. | 288 * The [TypeProvider] of the context. |
| 289 */ | 289 */ |
| 290 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = | 290 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = |
| 291 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); | 291 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * The used [Element]s of a [LibraryUnitTarget]. | 294 * The used local [Element]s of a [LibraryUnitTarget]. |
| 295 */ | 295 */ |
| 296 final ResultDescriptor<UsedElements> USED_ELEMENTS = | 296 final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS = |
| 297 new ResultDescriptor<UsedElements>('USED_ELEMENTS', null); | 297 new ResultDescriptor<UsedLocalElements>('USED_LOCAL_ELEMENTS', null); |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * The errors produced while verifying a compilation unit. | 300 * The errors produced while verifying a compilation unit. |
| 301 * | 301 * |
| 302 * The list will be empty if there were no errors, but will not be `null`. | 302 * The list will be empty if there were no errors, but will not be `null`. |
| 303 * | 303 * |
| 304 * The result is only available for targets representing a Dart compilation unit
. | 304 * The result is only available for targets representing a Dart compilation unit
. |
| 305 */ | 305 */ |
| 306 final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS = | 306 final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS = |
| 307 new ResultDescriptor<List<AnalysisError>>( | 307 new ResultDescriptor<List<AnalysisError>>( |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 element = definedNames[setterName]; | 1662 element = definedNames[setterName]; |
| 1663 if (element != null) { | 1663 if (element != null) { |
| 1664 newNames[setterName] = element; | 1664 newNames[setterName] = element; |
| 1665 } | 1665 } |
| 1666 } | 1666 } |
| 1667 return newNames; | 1667 return newNames; |
| 1668 } | 1668 } |
| 1669 } | 1669 } |
| 1670 | 1670 |
| 1671 /** | 1671 /** |
| 1672 * A task that builds [USED_ELEMENTS] for a unit. | 1672 * A task that builds [USED_LOCAL_ELEMENTS] for a unit. |
| 1673 */ | 1673 */ |
| 1674 class GatherUsedElementsTask extends SourceBasedAnalysisTask { | 1674 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask { |
| 1675 /** | 1675 /** |
| 1676 * The name of the [RESOLVED_UNIT] input. | 1676 * The name of the [RESOLVED_UNIT] input. |
| 1677 */ | 1677 */ |
| 1678 static const String UNIT_INPUT = 'UNIT_INPUT'; | 1678 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1679 | 1679 |
| 1680 /** | 1680 /** |
| 1681 * The task descriptor describing this kind of task. | 1681 * The task descriptor describing this kind of task. |
| 1682 */ | 1682 */ |
| 1683 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 1683 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1684 'GatherUsedElementsTask', createTask, buildInputs, | 1684 'GatherUsedElementsTask', createTask, buildInputs, |
| 1685 <ResultDescriptor>[USED_ELEMENTS]); | 1685 <ResultDescriptor>[USED_LOCAL_ELEMENTS]); |
| 1686 | 1686 |
| 1687 GatherUsedElementsTask(InternalAnalysisContext context, AnalysisTarget target) | 1687 GatherUsedLocalElementsTask( |
| 1688 InternalAnalysisContext context, AnalysisTarget target) |
| 1688 : super(context, target); | 1689 : super(context, target); |
| 1689 | 1690 |
| 1690 @override | 1691 @override |
| 1691 TaskDescriptor get descriptor => DESCRIPTOR; | 1692 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1692 | 1693 |
| 1693 @override | 1694 @override |
| 1694 void internalPerform() { | 1695 void internalPerform() { |
| 1695 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 1696 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 1696 CompilationUnitElement unitElement = unit.element; | 1697 CompilationUnitElement unitElement = unit.element; |
| 1697 LibraryElement libraryElement = unitElement.library; | 1698 LibraryElement libraryElement = unitElement.library; |
| 1698 // | 1699 // |
| 1699 // Prepare visited elements. | 1700 // Prepare visited elements. |
| 1700 // | 1701 // |
| 1701 GatherUsedElementsVisitor visitor = | 1702 GatherUsedLocalElementsVisitor visitor = |
| 1702 new GatherUsedElementsVisitor(libraryElement); | 1703 new GatherUsedLocalElementsVisitor(libraryElement); |
| 1703 unit.accept(visitor); | 1704 unit.accept(visitor); |
| 1704 // | 1705 // |
| 1705 // Record outputs. | 1706 // Record outputs. |
| 1706 // | 1707 // |
| 1707 outputs[USED_ELEMENTS] = visitor.usedElements; | 1708 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; |
| 1708 } | 1709 } |
| 1709 | 1710 |
| 1710 /** | 1711 /** |
| 1711 * Return a map from the names of the inputs of this kind of task to the task | 1712 * Return a map from the names of the inputs of this kind of task to the task |
| 1712 * input descriptors describing those inputs for a task with the | 1713 * input descriptors describing those inputs for a task with the |
| 1713 * given [target]. | 1714 * given [target]. |
| 1714 */ | 1715 */ |
| 1715 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { | 1716 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 1716 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; | 1717 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; |
| 1717 } | 1718 } |
| 1718 | 1719 |
| 1719 /** | 1720 /** |
| 1720 * Create a [GatherUsedElementsTask] based on the given [target] in | 1721 * Create a [GatherUsedLocalElementsTask] based on the given [target] in |
| 1721 * the given [context]. | 1722 * the given [context]. |
| 1722 */ | 1723 */ |
| 1723 static GatherUsedElementsTask createTask( | 1724 static GatherUsedLocalElementsTask createTask( |
| 1724 AnalysisContext context, LibraryUnitTarget target) { | 1725 AnalysisContext context, LibraryUnitTarget target) { |
| 1725 return new GatherUsedElementsTask(context, target); | 1726 return new GatherUsedLocalElementsTask(context, target); |
| 1726 } | 1727 } |
| 1727 } | 1728 } |
| 1728 | 1729 |
| 1729 /** | 1730 /** |
| 1730 * A task that generates [HINTS] for a unit. | 1731 * A task that generates [HINTS] for a unit. |
| 1731 */ | 1732 */ |
| 1732 class GenerateHintsTask extends SourceBasedAnalysisTask { | 1733 class GenerateHintsTask extends SourceBasedAnalysisTask { |
| 1733 /** | 1734 /** |
| 1734 * The name of the [RESOLVED_UNIT] input. | 1735 * The name of the [RESOLVED_UNIT] input. |
| 1735 */ | 1736 */ |
| 1736 static const String UNIT_INPUT = 'UNIT_INPUT'; | 1737 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1737 | 1738 |
| 1738 /** | 1739 /** |
| 1739 * The name of a list of [USED_ELEMENTS] for each library unit input. | 1740 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. |
| 1740 */ | 1741 */ |
| 1741 static const String USED_ELEMENTS_INPUT = 'USED_ELEMENTS_INPUT'; | 1742 static const String USED_ELEMENTS_INPUT = 'USED_ELEMENTS_INPUT'; |
| 1742 | 1743 |
| 1743 /** | 1744 /** |
| 1744 * The task descriptor describing this kind of task. | 1745 * The task descriptor describing this kind of task. |
| 1745 */ | 1746 */ |
| 1746 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 1747 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1747 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]); | 1748 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]); |
| 1748 | 1749 |
| 1749 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target) | 1750 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target) |
| 1750 : super(context, target); | 1751 : super(context, target); |
| 1751 | 1752 |
| 1752 @override | 1753 @override |
| 1753 TaskDescriptor get descriptor => DESCRIPTOR; | 1754 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1754 | 1755 |
| 1755 @override | 1756 @override |
| 1756 void internalPerform() { | 1757 void internalPerform() { |
| 1757 RecordingErrorListener errorListener = new RecordingErrorListener(); | 1758 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 1758 Source source = getRequiredSource(); | 1759 Source source = getRequiredSource(); |
| 1759 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 1760 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 1760 // | 1761 // |
| 1761 // Prepare inputs. | 1762 // Prepare inputs. |
| 1762 // | 1763 // |
| 1763 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 1764 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 1764 List<UsedElements> usedElementsList = getRequiredInput(USED_ELEMENTS_INPUT); | 1765 List<UsedLocalElements> usedElementsList = |
| 1766 getRequiredInput(USED_ELEMENTS_INPUT); |
| 1765 CompilationUnitElement unitElement = unit.element; | 1767 CompilationUnitElement unitElement = unit.element; |
| 1766 LibraryElement libraryElement = unitElement.library; | 1768 LibraryElement libraryElement = unitElement.library; |
| 1767 // | 1769 // |
| 1768 // Generate errors. | 1770 // Generate errors. |
| 1769 // | 1771 // |
| 1770 // TODO(scheglov) move collecting used imports into a separate task | 1772 // TODO(scheglov) move collecting used imports into a separate task |
| 1771 // unit.accept(_importsVerifier); | 1773 // unit.accept(_importsVerifier); |
| 1772 // Dead code analysis. | 1774 // Dead code analysis. |
| 1773 unit.accept(new DeadCodeVerifier(errorReporter)); | 1775 unit.accept(new DeadCodeVerifier(errorReporter)); |
| 1774 // Unused elements. | 1776 // Unused elements. |
| 1775 { | 1777 { |
| 1776 UsedElements usedElements = new UsedElements.merge(usedElementsList); | 1778 UsedLocalElements usedElements = |
| 1777 UnusedElementsVerifier visitor = | 1779 new UsedLocalElements.merge(usedElementsList); |
| 1778 new UnusedElementsVerifier(errorListener, usedElements); | 1780 UnusedLocalElementsVerifier visitor = |
| 1781 new UnusedLocalElementsVerifier(errorListener, usedElements); |
| 1779 unitElement.accept(visitor); | 1782 unitElement.accept(visitor); |
| 1780 } | 1783 } |
| 1781 // Dart2js analysis. | 1784 // Dart2js analysis. |
| 1782 if (context.analysisOptions.dart2jsHint) { | 1785 if (context.analysisOptions.dart2jsHint) { |
| 1783 unit.accept(new Dart2JSVerifier(errorReporter)); | 1786 unit.accept(new Dart2JSVerifier(errorReporter)); |
| 1784 } | 1787 } |
| 1785 // Dart best practices. | 1788 // Dart best practices. |
| 1786 InheritanceManager inheritanceManager = | 1789 InheritanceManager inheritanceManager = |
| 1787 new InheritanceManager(libraryElement); | 1790 new InheritanceManager(libraryElement); |
| 1788 TypeProvider typeProvider = context.typeProvider; | 1791 TypeProvider typeProvider = context.typeProvider; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1800 * Return a map from the names of the inputs of this kind of task to the task | 1803 * Return a map from the names of the inputs of this kind of task to the task |
| 1801 * input descriptors describing those inputs for a task with the | 1804 * input descriptors describing those inputs for a task with the |
| 1802 * given [target]. | 1805 * given [target]. |
| 1803 */ | 1806 */ |
| 1804 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { | 1807 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { |
| 1805 Source libSource = target.library; | 1808 Source libSource = target.library; |
| 1806 return <String, TaskInput>{ | 1809 return <String, TaskInput>{ |
| 1807 UNIT_INPUT: RESOLVED_UNIT.of(target), | 1810 UNIT_INPUT: RESOLVED_UNIT.of(target), |
| 1808 USED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) { | 1811 USED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) { |
| 1809 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit); | 1812 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit); |
| 1810 return USED_ELEMENTS.of(target); | 1813 return USED_LOCAL_ELEMENTS.of(target); |
| 1811 }) | 1814 }) |
| 1812 }; | 1815 }; |
| 1813 } | 1816 } |
| 1814 | 1817 |
| 1815 /** | 1818 /** |
| 1816 * Create a [GenerateHintsTask] based on the given [target] in | 1819 * Create a [GenerateHintsTask] based on the given [target] in |
| 1817 * the given [context]. | 1820 * the given [context]. |
| 1818 */ | 1821 */ |
| 1819 static GenerateHintsTask createTask( | 1822 static GenerateHintsTask createTask( |
| 1820 AnalysisContext context, AnalysisTarget target) { | 1823 AnalysisContext context, AnalysisTarget target) { |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2531 @override | 2534 @override |
| 2532 bool moveNext() { | 2535 bool moveNext() { |
| 2533 if (_newSources.isEmpty) { | 2536 if (_newSources.isEmpty) { |
| 2534 return false; | 2537 return false; |
| 2535 } | 2538 } |
| 2536 currentTarget = _newSources.first; | 2539 currentTarget = _newSources.first; |
| 2537 _newSources.remove(currentTarget); | 2540 _newSources.remove(currentTarget); |
| 2538 return true; | 2541 return true; |
| 2539 } | 2542 } |
| 2540 } | 2543 } |
| OLD | NEW |