Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1065693002: Generate hints for imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 new ResultDescriptor<List<AnalysisError>>( 274 new ResultDescriptor<List<AnalysisError>>(
275 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS); 275 'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS);
276 276
277 /** 277 /**
278 * The [TypeProvider] of the context. 278 * The [TypeProvider] of the context.
279 */ 279 */
280 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = 280 final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
281 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); 281 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null);
282 282
283 /** 283 /**
284 * The used local [Element]s of a [LibraryUnitTarget]. 284 * The [UsedImportedElements] of a [LibraryUnitTarget].
285 */
286 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS =
287 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null);
288
289 /**
290 * The [UsedLocalElements] of a [LibraryUnitTarget].
285 */ 291 */
286 final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS = 292 final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS =
287 new ResultDescriptor<UsedLocalElements>('USED_LOCAL_ELEMENTS', null); 293 new ResultDescriptor<UsedLocalElements>('USED_LOCAL_ELEMENTS', null);
288 294
289 /** 295 /**
290 * The errors produced while verifying a compilation unit. 296 * The errors produced while verifying a compilation unit.
291 * 297 *
292 * The list will be empty if there were no errors, but will not be `null`. 298 * The list will be empty if there were no errors, but will not be `null`.
293 * 299 *
294 * The result is only available for targets representing a Dart compilation unit . 300 * The result is only available for targets representing a Dart compilation unit .
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 element = definedNames[setterName]; 1658 element = definedNames[setterName];
1653 if (element != null) { 1659 if (element != null) {
1654 newNames[setterName] = element; 1660 newNames[setterName] = element;
1655 } 1661 }
1656 } 1662 }
1657 return newNames; 1663 return newNames;
1658 } 1664 }
1659 } 1665 }
1660 1666
1661 /** 1667 /**
1668 * A task that builds [USED_IMPORTED_ELEMENTS] for a unit.
1669 */
1670 class GatherUsedImportedElementsTask extends SourceBasedAnalysisTask {
1671 /**
1672 * The name of the [RESOLVED_UNIT] input.
1673 */
1674 static const String UNIT_INPUT = 'UNIT_INPUT';
1675
1676 /**
1677 * The task descriptor describing this kind of task.
1678 */
1679 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1680 'GatherUsedImportedElementsTask', createTask, buildInputs,
1681 <ResultDescriptor>[USED_IMPORTED_ELEMENTS]);
1682
1683 GatherUsedImportedElementsTask(
1684 InternalAnalysisContext context, AnalysisTarget target)
1685 : super(context, target);
1686
1687 @override
1688 TaskDescriptor get descriptor => DESCRIPTOR;
1689
1690 @override
1691 void internalPerform() {
1692 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1693 CompilationUnitElement unitElement = unit.element;
1694 LibraryElement libraryElement = unitElement.library;
1695 //
1696 // Prepare used imported elements.
1697 //
1698 GatherUsedImportedElementsVisitor visitor =
1699 new GatherUsedImportedElementsVisitor(libraryElement);
1700 unit.accept(visitor);
1701 //
1702 // Record outputs.
1703 //
1704 outputs[USED_IMPORTED_ELEMENTS] = visitor.usedElements;
1705 }
1706
1707 /**
1708 * Return a map from the names of the inputs of this kind of task to the task
1709 * input descriptors describing those inputs for a task with the
1710 * given [target].
1711 */
1712 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
1713 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)};
1714 }
1715
1716 /**
1717 * Create a [GatherUsedImportedElementsTask] based on the given [target] in
1718 * the given [context].
1719 */
1720 static GatherUsedImportedElementsTask createTask(
1721 AnalysisContext context, LibraryUnitTarget target) {
1722 return new GatherUsedImportedElementsTask(context, target);
1723 }
1724 }
1725
1726 /**
1662 * A task that builds [USED_LOCAL_ELEMENTS] for a unit. 1727 * A task that builds [USED_LOCAL_ELEMENTS] for a unit.
1663 */ 1728 */
1664 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask { 1729 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask {
1665 /** 1730 /**
1666 * The name of the [RESOLVED_UNIT] input. 1731 * The name of the [RESOLVED_UNIT] input.
1667 */ 1732 */
1668 static const String UNIT_INPUT = 'UNIT_INPUT'; 1733 static const String UNIT_INPUT = 'UNIT_INPUT';
1669 1734
1670 /** 1735 /**
1671 * The task descriptor describing this kind of task. 1736 * The task descriptor describing this kind of task.
1672 */ 1737 */
1673 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1738 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1674 'GatherUsedElementsTask', createTask, buildInputs, 1739 'GatherUsedLocalElementsTask', createTask, buildInputs,
1675 <ResultDescriptor>[USED_LOCAL_ELEMENTS]); 1740 <ResultDescriptor>[USED_LOCAL_ELEMENTS]);
1676 1741
1677 GatherUsedLocalElementsTask( 1742 GatherUsedLocalElementsTask(
1678 InternalAnalysisContext context, AnalysisTarget target) 1743 InternalAnalysisContext context, AnalysisTarget target)
1679 : super(context, target); 1744 : super(context, target);
1680 1745
1681 @override 1746 @override
1682 TaskDescriptor get descriptor => DESCRIPTOR; 1747 TaskDescriptor get descriptor => DESCRIPTOR;
1683 1748
1684 @override 1749 @override
1685 void internalPerform() { 1750 void internalPerform() {
1686 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 1751 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1687 CompilationUnitElement unitElement = unit.element; 1752 CompilationUnitElement unitElement = unit.element;
1688 LibraryElement libraryElement = unitElement.library; 1753 LibraryElement libraryElement = unitElement.library;
1689 // 1754 //
1690 // Prepare visited elements. 1755 // Prepare used local elements.
1691 // 1756 //
1692 GatherUsedLocalElementsVisitor visitor = 1757 GatherUsedLocalElementsVisitor visitor =
1693 new GatherUsedLocalElementsVisitor(libraryElement); 1758 new GatherUsedLocalElementsVisitor(libraryElement);
1694 unit.accept(visitor); 1759 unit.accept(visitor);
1695 // 1760 //
1696 // Record outputs. 1761 // Record outputs.
1697 // 1762 //
1698 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; 1763 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements;
1699 } 1764 }
1700 1765
(...skipping 21 matching lines...) Expand all
1722 */ 1787 */
1723 class GenerateHintsTask extends SourceBasedAnalysisTask { 1788 class GenerateHintsTask extends SourceBasedAnalysisTask {
1724 /** 1789 /**
1725 * The name of the [RESOLVED_UNIT] input. 1790 * The name of the [RESOLVED_UNIT] input.
1726 */ 1791 */
1727 static const String UNIT_INPUT = 'UNIT_INPUT'; 1792 static const String UNIT_INPUT = 'UNIT_INPUT';
1728 1793
1729 /** 1794 /**
1730 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. 1795 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
1731 */ 1796 */
1732 static const String USED_ELEMENTS_INPUT = 'USED_ELEMENTS_INPUT'; 1797 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
1798
1799 /**
1800 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
1801 */
1802 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS';
1733 1803
1734 /** 1804 /**
1735 * The task descriptor describing this kind of task. 1805 * The task descriptor describing this kind of task.
1736 */ 1806 */
1737 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1807 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1738 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]); 1808 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]);
1739 1809
1740 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target) 1810 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target)
1741 : super(context, target); 1811 : super(context, target);
1742 1812
1743 @override 1813 @override
1744 TaskDescriptor get descriptor => DESCRIPTOR; 1814 TaskDescriptor get descriptor => DESCRIPTOR;
1745 1815
1746 @override 1816 @override
1747 void internalPerform() { 1817 void internalPerform() {
1748 RecordingErrorListener errorListener = new RecordingErrorListener(); 1818 RecordingErrorListener errorListener = new RecordingErrorListener();
1749 Source source = getRequiredSource(); 1819 Source source = getRequiredSource();
1750 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 1820 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
1751 // 1821 //
1752 // Prepare inputs. 1822 // Prepare inputs.
1753 // 1823 //
1754 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 1824 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1755 List<UsedLocalElements> usedElementsList = 1825 List<UsedImportedElements> usedImportedElementsList =
1756 getRequiredInput(USED_ELEMENTS_INPUT); 1826 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT);
1827 List<UsedLocalElements> usedLocalElementsList =
1828 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT);
1757 CompilationUnitElement unitElement = unit.element; 1829 CompilationUnitElement unitElement = unit.element;
1758 LibraryElement libraryElement = unitElement.library; 1830 LibraryElement libraryElement = unitElement.library;
1759 // 1831 //
1760 // Generate errors. 1832 // Generate errors.
1761 // 1833 //
1762 // TODO(scheglov) move collecting used imports into a separate task
1763 // unit.accept(_importsVerifier);
1764 // Dead code analysis.
1765 unit.accept(new DeadCodeVerifier(errorReporter)); 1834 unit.accept(new DeadCodeVerifier(errorReporter));
1766 // Unused elements. 1835 // Verify imports.
1836 {
1837 ImportsVerifier verifier = new ImportsVerifier();
1838 verifier.addImports(unit);
1839 usedImportedElementsList.forEach(verifier.removeUsedElements);
1840 verifier.generateDuplicateImportHints(errorReporter);
1841 verifier.generateUnusedImportHints(errorReporter);
1842 }
1843 // Unused local elements.
1767 { 1844 {
1768 UsedLocalElements usedElements = 1845 UsedLocalElements usedElements =
1769 new UsedLocalElements.merge(usedElementsList); 1846 new UsedLocalElements.merge(usedLocalElementsList);
1770 UnusedLocalElementsVerifier visitor = 1847 UnusedLocalElementsVerifier visitor =
1771 new UnusedLocalElementsVerifier(errorListener, usedElements); 1848 new UnusedLocalElementsVerifier(errorListener, usedElements);
1772 unitElement.accept(visitor); 1849 unitElement.accept(visitor);
1773 } 1850 }
1774 // Dart2js analysis. 1851 // Dart2js analysis.
1775 if (context.analysisOptions.dart2jsHint) { 1852 if (context.analysisOptions.dart2jsHint) {
1776 unit.accept(new Dart2JSVerifier(errorReporter)); 1853 unit.accept(new Dart2JSVerifier(errorReporter));
1777 } 1854 }
1778 // Dart best practices. 1855 // Dart best practices.
1779 InheritanceManager inheritanceManager = 1856 InheritanceManager inheritanceManager =
(...skipping 11 matching lines...) Expand all
1791 1868
1792 /** 1869 /**
1793 * Return a map from the names of the inputs of this kind of task to the task 1870 * Return a map from the names of the inputs of this kind of task to the task
1794 * input descriptors describing those inputs for a task with the 1871 * input descriptors describing those inputs for a task with the
1795 * given [target]. 1872 * given [target].
1796 */ 1873 */
1797 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { 1874 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
1798 Source libSource = target.library; 1875 Source libSource = target.library;
1799 return <String, TaskInput>{ 1876 return <String, TaskInput>{
1800 UNIT_INPUT: RESOLVED_UNIT.of(target), 1877 UNIT_INPUT: RESOLVED_UNIT.of(target),
1801 USED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) { 1878 USED_LOCAL_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
1802 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit); 1879 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit);
1803 return USED_LOCAL_ELEMENTS.of(target); 1880 return USED_LOCAL_ELEMENTS.of(target);
1881 }),
1882 USED_IMPORTED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
1883 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit);
1884 return USED_IMPORTED_ELEMENTS.of(target);
1804 }) 1885 })
1805 }; 1886 };
1806 } 1887 }
1807 1888
1808 /** 1889 /**
1809 * Create a [GenerateHintsTask] based on the given [target] in 1890 * Create a [GenerateHintsTask] based on the given [target] in
1810 * the given [context]. 1891 * the given [context].
1811 */ 1892 */
1812 static GenerateHintsTask createTask( 1893 static GenerateHintsTask createTask(
1813 AnalysisContext context, AnalysisTarget target) { 1894 AnalysisContext context, AnalysisTarget target) {
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 @override 2605 @override
2525 bool moveNext() { 2606 bool moveNext() {
2526 if (_newSources.isEmpty) { 2607 if (_newSources.isEmpty) {
2527 return false; 2608 return false;
2528 } 2609 }
2529 currentTarget = _newSources.first; 2610 currentTarget = _newSources.first;
2530 _newSources.remove(currentTarget); 2611 _newSources.remove(currentTarget);
2531 return true; 2612 return true;
2532 } 2613 }
2533 } 2614 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698