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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/analysis_impl.dart

Issue 2680373002: Extract hints generation into a separte method and make is optional. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analyzer/context/declared_variables.dart'; 5 import 'package:analyzer/context/declared_variables.dart';
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/error/error.dart'; 8 import 'package:analyzer/error/error.dart';
9 import 'package:analyzer/error/listener.dart'; 9 import 'package:analyzer/error/listener.dart';
10 import 'package:analyzer/src/context/context.dart'; 10 import 'package:analyzer/src/context/context.dart';
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 _resolveDirectives(units); 84 _resolveDirectives(units);
85 85
86 units.forEach((file, unit) { 86 units.forEach((file, unit) {
87 _resolveFile(file, unit); 87 _resolveFile(file, unit);
88 }); 88 });
89 89
90 _computeConstants(); 90 _computeConstants();
91 91
92 units.forEach((file, unit) { 92 units.forEach((file, unit) {
93 { 93 _computeVerifyErrors(file, unit);
94 var visitor = new GatherUsedLocalElementsVisitor(_libraryElement);
95 unit.accept(visitor);
96 _usedLocalElementsList.add(visitor.usedElements);
97 }
98 {
99 var visitor = new GatherUsedImportedElementsVisitor(_libraryElement);
100 unit.accept(visitor);
101 _usedImportedElementsList.add(visitor.usedElements);
102 }
103 }); 94 });
104 95
105 units.forEach((file, unit) { 96 if (_analysisOptions.hint) {
106 _computeVerifyErrorsAndHints(file, unit); 97 units.forEach((file, unit) {
107 }); 98 {
99 var visitor = new GatherUsedLocalElementsVisitor(_libraryElement);
100 unit.accept(visitor);
101 _usedLocalElementsList.add(visitor.usedElements);
102 }
103 {
104 var visitor =
105 new GatherUsedImportedElementsVisitor(_libraryElement);
106 unit.accept(visitor);
107 _usedImportedElementsList.add(visitor.usedElements);
108 }
109 });
110 units.forEach((file, unit) {
111 _computeHints(file, unit);
112 });
113 }
108 } finally { 114 } finally {
109 _context.dispose(); 115 _context.dispose();
110 } 116 }
111 117
112 // Return full results. 118 // Return full results.
113 Map<FileState, UnitAnalysisResult> results = {}; 119 Map<FileState, UnitAnalysisResult> results = {};
114 units.forEach((file, unit) { 120 units.forEach((file, unit) {
115 List<AnalysisError> errors = _getErrorListener(file).errors; 121 List<AnalysisError> errors = _getErrorListener(file).errors;
116 errors = _filterIgnoredErrors(file, errors); 122 errors = _filterIgnoredErrors(file, errors);
117 results[file] = new UnitAnalysisResult(file, unit, errors); 123 results[file] = new UnitAnalysisResult(file, unit, errors);
(...skipping 17 matching lines...) Expand all
135 nodeMap[constant] = node; 141 nodeMap[constant] = node;
136 } 142 }
137 143
138 for (_ConstantNode node in nodes) { 144 for (_ConstantNode node in nodes) {
139 if (!node.isEvaluated) { 145 if (!node.isEvaluated) {
140 new _ConstantWalker(evaluationEngine).walk(node); 146 new _ConstantWalker(evaluationEngine).walk(node);
141 } 147 }
142 } 148 }
143 } 149 }
144 150
145 void _computeVerifyErrorsAndHints(FileState file, CompilationUnit unit) { 151 void _computeHints(FileState file, CompilationUnit unit) {
152 AnalysisErrorListener errorListener = _getErrorListener(file);
153 ErrorReporter errorReporter = _getErrorReporter(file);
154
155 unit.accept(
156 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem));
157
158 // Dart2js analysis.
159 if (_analysisOptions.dart2jsHint) {
160 unit.accept(new Dart2JSVerifier(errorReporter));
161 }
162
163 InheritanceManager inheritanceManager = new InheritanceManager(
164 _libraryElement,
165 includeAbstractFromSuperclasses: true);
166
167 unit.accept(new BestPracticesVerifier(
168 errorReporter, _typeProvider, _libraryElement, inheritanceManager,
169 typeSystem: _context.typeSystem));
170
171 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
172
173 new ToDoFinder(errorReporter).findIn(unit);
174
175 // Verify imports.
176 {
177 ImportsVerifier verifier = new ImportsVerifier();
178 verifier.addImports(unit);
179 _usedImportedElementsList.forEach(verifier.removeUsedElements);
180 verifier.generateDuplicateImportHints(errorReporter);
181 verifier.generateUnusedImportHints(errorReporter);
182 verifier.generateUnusedShownNameHints(errorReporter);
183 }
184
185 // Unused local elements.
186 {
187 UsedLocalElements usedElements =
188 new UsedLocalElements.merge(_usedLocalElementsList);
189 UnusedLocalElementsVerifier visitor =
190 new UnusedLocalElementsVerifier(errorListener, usedElements);
191 unit.element.accept(visitor);
192 }
193 }
194
195 void _computeVerifyErrors(FileState file, CompilationUnit unit) {
146 RecordingErrorListener errorListener = _getErrorListener(file); 196 RecordingErrorListener errorListener = _getErrorListener(file);
147 CompilationUnitElement unitElement = unit.element; 197 CompilationUnitElement unitElement = unit.element;
148 198
149 // 199 //
150 // Use the ErrorVerifier to compute errors. 200 // Use the ErrorVerifier to compute errors.
151 // 201 //
152 List<PendingError> pendingErrors; 202 List<PendingError> pendingErrors;
153 { 203 {
154 RequiredConstantsComputer computer = 204 RequiredConstantsComputer computer =
155 new RequiredConstantsComputer(file.source); 205 new RequiredConstantsComputer(file.source);
156 unit.accept(computer); 206 unit.accept(computer);
157 pendingErrors = computer.pendingErrors; 207 pendingErrors = computer.pendingErrors;
158 List<ConstantEvaluationTarget> requiredConstants = 208 List<ConstantEvaluationTarget> requiredConstants =
159 computer.requiredConstants; 209 computer.requiredConstants;
160 } 210 }
161 211
162 if (_analysisOptions.strongMode) { 212 if (_analysisOptions.strongMode) {
163 AnalysisOptionsImpl options = _analysisOptions as AnalysisOptionsImpl; 213 AnalysisOptionsImpl options = _analysisOptions as AnalysisOptionsImpl;
164 CodeChecker checker = new CodeChecker( 214 CodeChecker checker = new CodeChecker(
165 _typeProvider, 215 _typeProvider,
166 new StrongTypeSystemImpl(_typeProvider, 216 new StrongTypeSystemImpl(_typeProvider,
167 implicitCasts: options.implicitCasts, 217 implicitCasts: options.implicitCasts,
168 nonnullableTypes: options.nonnullableTypes), 218 nonnullableTypes: options.nonnullableTypes),
169 errorListener, 219 errorListener,
170 options); 220 options);
171 checker.visitCompilationUnit(unit); 221 checker.visitCompilationUnit(unit);
172 } 222 }
173 223
174 var errorReporter = _getErrorReporter(file); 224 ErrorReporter errorReporter = _getErrorReporter(file);
175 225
176 // 226 //
177 // Validate the directives. 227 // Validate the directives.
178 // 228 //
179 _validateUriBasedDirectives(file, unit); 229 _validateUriBasedDirectives(file, unit);
180 230
181 // 231 //
182 // Use the ConstantVerifier to compute errors. 232 // Use the ConstantVerifier to compute errors.
183 // 233 //
184 ConstantVerifier constantVerifier = new ConstantVerifier( 234 ConstantVerifier constantVerifier = new ConstantVerifier(
(...skipping 10 matching lines...) Expand all
195 new InheritanceManager(_libraryElement), 245 new InheritanceManager(_libraryElement),
196 _analysisOptions.enableSuperMixins); 246 _analysisOptions.enableSuperMixins);
197 unit.accept(errorVerifier); 247 unit.accept(errorVerifier);
198 248
199 // 249 //
200 // Convert the pending errors into actual errors. 250 // Convert the pending errors into actual errors.
201 // 251 //
202 for (PendingError pendingError in pendingErrors) { 252 for (PendingError pendingError in pendingErrors) {
203 errorListener.onError(pendingError.toAnalysisError()); 253 errorListener.onError(pendingError.toAnalysisError());
204 } 254 }
205
206 //
207 // Find dead code.
208 //
209 unit.accept(
210 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem));
211
212 // Dart2js analysis.
213 if (_analysisOptions.dart2jsHint) {
214 unit.accept(new Dart2JSVerifier(errorReporter));
215 }
216
217 InheritanceManager inheritanceManager = new InheritanceManager(
218 _libraryElement,
219 includeAbstractFromSuperclasses: true);
220
221 unit.accept(new BestPracticesVerifier(
222 errorReporter, _typeProvider, _libraryElement, inheritanceManager,
223 typeSystem: _context.typeSystem));
224
225 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
226
227 new ToDoFinder(errorReporter).findIn(unit);
228
229 // Verify imports.
230 {
231 ImportsVerifier verifier = new ImportsVerifier();
232 verifier.addImports(unit);
233 _usedImportedElementsList.forEach(verifier.removeUsedElements);
234 ErrorReporter errorReporter = _getErrorReporter(file);
235 verifier.generateDuplicateImportHints(errorReporter);
236 verifier.generateUnusedImportHints(errorReporter);
237 verifier.generateUnusedShownNameHints(errorReporter);
238 }
239
240 {
241 GatherUsedLocalElementsVisitor visitor =
242 new GatherUsedLocalElementsVisitor(_libraryElement);
243 unit.accept(visitor);
244 }
245
246 // Unused local elements.
247 {
248 UsedLocalElements usedElements =
249 new UsedLocalElements.merge(_usedLocalElementsList);
250 UnusedLocalElementsVerifier visitor =
251 new UnusedLocalElementsVerifier(errorListener, usedElements);
252 unitElement.accept(visitor);
253 }
254 } 255 }
255 256
256 void _createAnalysisContext() { 257 void _createAnalysisContext() {
257 AnalysisContextImpl analysisContext = 258 AnalysisContextImpl analysisContext =
258 AnalysisEngine.instance.createAnalysisContext(); 259 AnalysisEngine.instance.createAnalysisContext();
259 analysisContext.analysisOptions = _analysisOptions; 260 analysisContext.analysisOptions = _analysisOptions;
260 analysisContext.declaredVariables.addAll(_declaredVariables); 261 analysisContext.declaredVariables.addAll(_declaredVariables);
261 analysisContext.sourceFactory = _sourceFactory.clone(); 262 analysisContext.sourceFactory = _sourceFactory.clone();
262 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); 263 analysisContext.contentCache = new _ContentCacheWrapper(_fsState);
263 this._context = analysisContext; 264 this._context = analysisContext;
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 739 }
739 740
740 /** 741 /**
741 * Either the name or the source associated with a part-of directive. 742 * Either the name or the source associated with a part-of directive.
742 */ 743 */
743 class _NameOrSource { 744 class _NameOrSource {
744 final String name; 745 final String name;
745 final Source source; 746 final Source source;
746 _NameOrSource(this.name, this.source); 747 _NameOrSource(this.name, this.source);
747 } 748 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698