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

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

Issue 1055573003: Report unused elements in GenerateHintsTask. (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 | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | 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 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 /** 1729 /**
1730 * A task that generates [HINTS] for a unit. 1730 * A task that generates [HINTS] for a unit.
1731 */ 1731 */
1732 class GenerateHintsTask extends SourceBasedAnalysisTask { 1732 class GenerateHintsTask extends SourceBasedAnalysisTask {
1733 /** 1733 /**
1734 * The name of the [RESOLVED_UNIT] input. 1734 * The name of the [RESOLVED_UNIT] input.
1735 */ 1735 */
1736 static const String UNIT_INPUT = 'UNIT_INPUT'; 1736 static const String UNIT_INPUT = 'UNIT_INPUT';
1737 1737
1738 /** 1738 /**
1739 * The name of a list of [USED_ELEMENTS] for each library unit input.
1740 */
1741 static const String USED_ELEMENTS_INPUT = 'USED_ELEMENTS_INPUT';
1742
1743 /**
1739 * The task descriptor describing this kind of task. 1744 * The task descriptor describing this kind of task.
1740 */ 1745 */
1741 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1746 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1742 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]); 1747 'GenerateHintsTask', createTask, buildInputs, <ResultDescriptor>[HINTS]);
1743 1748
1744 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target) 1749 GenerateHintsTask(InternalAnalysisContext context, AnalysisTarget target)
1745 : super(context, target); 1750 : super(context, target);
1746 1751
1747 @override 1752 @override
1748 TaskDescriptor get descriptor => DESCRIPTOR; 1753 TaskDescriptor get descriptor => DESCRIPTOR;
1749 1754
1750 @override 1755 @override
1751 void internalPerform() { 1756 void internalPerform() {
1752 RecordingErrorListener errorListener = new RecordingErrorListener(); 1757 RecordingErrorListener errorListener = new RecordingErrorListener();
1753 Source source = getRequiredSource(); 1758 Source source = getRequiredSource();
1754 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 1759 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
1755 // 1760 //
1756 // Prepare inputs. 1761 // Prepare inputs.
1757 // 1762 //
1758 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 1763 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1764 List<UsedElements> usedElementsList = getRequiredInput(USED_ELEMENTS_INPUT);
1759 CompilationUnitElement unitElement = unit.element; 1765 CompilationUnitElement unitElement = unit.element;
1760 LibraryElement libraryElement = unitElement.library; 1766 LibraryElement libraryElement = unitElement.library;
1761 // 1767 //
1762 // Use the HintGenerator to generate errors. 1768 // Generate errors.
1763 // 1769 //
1764 // TODO(scheglov) move collecting used imports into a separate task 1770 // TODO(scheglov) move collecting used imports into a separate task
1765 // unit.accept(_importsVerifier); 1771 // unit.accept(_importsVerifier);
1766 // Dead code analysis. 1772 // Dead code analysis.
1767 unit.accept(new DeadCodeVerifier(errorReporter)); 1773 unit.accept(new DeadCodeVerifier(errorReporter));
1768 // TODO(scheglov) move collecting used elements into a separate task 1774 // Unused elements.
1769 // unit.accept(_usedElementsVisitor); 1775 {
1776 UsedElements usedElements = new UsedElements.merge(usedElementsList);
1777 UnusedElementsVerifier visitor =
1778 new UnusedElementsVerifier(errorListener, usedElements);
1779 unitElement.accept(visitor);
1780 }
1770 // Dart2js analysis. 1781 // Dart2js analysis.
1771 if (context.analysisOptions.dart2jsHint) { 1782 if (context.analysisOptions.dart2jsHint) {
1772 unit.accept(new Dart2JSVerifier(errorReporter)); 1783 unit.accept(new Dart2JSVerifier(errorReporter));
1773 } 1784 }
1774 // Dart best practices. 1785 // Dart best practices.
1775 InheritanceManager inheritanceManager = 1786 InheritanceManager inheritanceManager =
1776 new InheritanceManager(libraryElement); 1787 new InheritanceManager(libraryElement);
1777 TypeProvider typeProvider = context.typeProvider; 1788 TypeProvider typeProvider = context.typeProvider;
1778 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider)); 1789 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider));
1779 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); 1790 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
1780 // Find to-do comments. 1791 // Find to-do comments.
1781 new ToDoFinder(errorReporter).findIn(unit); 1792 new ToDoFinder(errorReporter).findIn(unit);
1782 // 1793 //
1783 // Record outputs. 1794 // Record outputs.
1784 // 1795 //
1785 outputs[HINTS] = errorListener.errors; 1796 outputs[HINTS] = errorListener.errors;
1786 } 1797 }
1787 1798
1788 /** 1799 /**
1789 * Return a map from the names of the inputs of this kind of task to the task 1800 * Return a map from the names of the inputs of this kind of task to the task
1790 * input descriptors describing those inputs for a task with the 1801 * input descriptors describing those inputs for a task with the
1791 * given [target]. 1802 * given [target].
1792 */ 1803 */
1793 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) { 1804 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
1794 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(target)}; 1805 Source libSource = target.library;
1806 return <String, TaskInput>{
1807 UNIT_INPUT: RESOLVED_UNIT.of(target),
1808 USED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
1809 LibraryUnitTarget target = new LibraryUnitTarget(libSource, unit);
1810 return USED_ELEMENTS.of(target);
1811 })
1812 };
1795 } 1813 }
1796 1814
1797 /** 1815 /**
1798 * Create a [GenerateHintsTask] based on the given [target] in 1816 * Create a [GenerateHintsTask] based on the given [target] in
1799 * the given [context]. 1817 * the given [context].
1800 */ 1818 */
1801 static GenerateHintsTask createTask( 1819 static GenerateHintsTask createTask(
1802 AnalysisContext context, AnalysisTarget target) { 1820 AnalysisContext context, AnalysisTarget target) {
1803 return new GenerateHintsTask(context, target); 1821 return new GenerateHintsTask(context, target);
1804 } 1822 }
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 @override 2531 @override
2514 bool moveNext() { 2532 bool moveNext() {
2515 if (_newSources.isEmpty) { 2533 if (_newSources.isEmpty) {
2516 return false; 2534 return false;
2517 } 2535 }
2518 currentTarget = _newSources.first; 2536 currentTarget = _newSources.first;
2519 _newSources.remove(currentTarget); 2537 _newSources.remove(currentTarget);
2520 return true; 2538 return true;
2521 } 2539 }
2522 } 2540 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698