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_cli.src.analyzer_impl; | 5 library analyzer_cli.src.analyzer_impl; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 /// of that package. Otherwise `null`. This allows us to analyze the file | 58 /// of that package. Otherwise `null`. This allows us to analyze the file |
59 /// specified on the command line as though it is reached via a "package:" | 59 /// specified on the command line as though it is reached via a "package:" |
60 /// URI, but avoid suppressing its output in the event that the user has not | 60 /// URI, but avoid suppressing its output in the event that the user has not |
61 /// specified the "--package-warnings" option. | 61 /// specified the "--package-warnings" option. |
62 String _selfPackageName; | 62 String _selfPackageName; |
63 | 63 |
64 AnalyzerImpl(this.analysisOptions, this.context, this.analysisDriver, | 64 AnalyzerImpl(this.analysisOptions, this.context, this.analysisDriver, |
65 this.librarySource, this.options, this.stats, this.startTime); | 65 this.librarySource, this.options, this.stats, this.startTime); |
66 | 66 |
67 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 67 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
68 ErrorSeverity get maxErrorSeverity { | 68 ErrorSeverity computeMaxErrorSeverity() { |
69 ErrorSeverity status = ErrorSeverity.NONE; | 69 ErrorSeverity status = ErrorSeverity.NONE; |
70 for (AnalysisErrorInfo errorInfo in errorInfos) { | 70 for (AnalysisErrorInfo errorInfo in errorInfos) { |
71 for (AnalysisError error in errorInfo.errors) { | 71 for (AnalysisError error in errorInfo.errors) { |
72 if (_defaultSeverityProcessor(error) == null) { | 72 if (_defaultSeverityProcessor(error) == null) { |
73 continue; | 73 continue; |
74 } | 74 } |
75 ErrorSeverity severity = computeSeverity(error, options); | 75 status = status.max(computeSeverity(error, options, analysisOptions)); |
76 status = status.max(severity); | |
77 } | 76 } |
78 } | 77 } |
79 return status; | 78 return status; |
80 } | 79 } |
81 | 80 |
82 void addCompilationUnitSource( | 81 void addCompilationUnitSource( |
83 CompilationUnitElement unit, Set<CompilationUnitElement> units) { | 82 CompilationUnitElement unit, Set<CompilationUnitElement> units) { |
84 if (unit == null || !units.add(unit)) { | 83 if (unit == null || !units.add(unit)) { |
85 return; | 84 return; |
86 } | 85 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 prepareSources(libraryElement); | 177 prepareSources(libraryElement); |
179 await prepareErrors(); | 178 await prepareErrors(); |
180 | 179 |
181 // Print errors and performance numbers. | 180 // Print errors and performance numbers. |
182 if (printMode == 1) { | 181 if (printMode == 1) { |
183 formatter.formatErrors(errorInfos); | 182 formatter.formatErrors(errorInfos); |
184 } else if (printMode == 2) { | 183 } else if (printMode == 2) { |
185 _printColdPerf(); | 184 _printColdPerf(); |
186 } | 185 } |
187 | 186 |
188 // Compute max severity and set exitCode. | 187 // Compute and return max severity. |
189 ErrorSeverity status = maxErrorSeverity; | 188 return computeMaxErrorSeverity(); |
190 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | |
191 status = ErrorSeverity.ERROR; | |
192 } | |
193 return status; | |
194 } | 189 } |
195 | 190 |
196 /// Returns true if we want to report diagnostics for this library. | 191 /// Returns true if we want to report diagnostics for this library. |
197 bool _isAnalyzedLibrary(LibraryElement library) { | 192 bool _isAnalyzedLibrary(LibraryElement library) { |
198 Source source = library.source; | 193 Source source = library.source; |
199 switch (source.uriKind) { | 194 switch (source.uriKind) { |
200 case UriKind.DART_URI: | 195 case UriKind.DART_URI: |
201 return options.showSdkWarnings; | 196 return options.showSdkWarnings; |
202 case UriKind.PACKAGE_URI: | 197 case UriKind.PACKAGE_URI: |
203 if (_isPathInPubCache(source.fullName)) { | 198 if (_isPathInPubCache(source.fullName)) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (tag != PerformanceTag.UNKNOWN) { | 230 if (tag != PerformanceTag.UNKNOWN) { |
236 int tagTime = tag.elapsedMs; | 231 int tagTime = tag.elapsedMs; |
237 outSink.writeln('${tag.label}-cold:$tagTime'); | 232 outSink.writeln('${tag.label}-cold:$tagTime'); |
238 otherTime -= tagTime; | 233 otherTime -= tagTime; |
239 } | 234 } |
240 } | 235 } |
241 outSink.writeln('other-cold:$otherTime'); | 236 outSink.writeln('other-cold:$otherTime'); |
242 outSink.writeln("total-cold:$totalTime"); | 237 outSink.writeln("total-cold:$totalTime"); |
243 } | 238 } |
244 | 239 |
245 ProcessedSeverity _defaultSeverityProcessor(AnalysisError error) => | 240 ErrorSeverity _defaultSeverityProcessor(AnalysisError error) => |
246 determineProcessedSeverity(error, options, analysisOptions); | 241 determineProcessedSeverity(error, options, analysisOptions); |
247 | 242 |
248 Future<LibraryElement> _resolveLibrary() async { | 243 Future<LibraryElement> _resolveLibrary() async { |
249 PerformanceTag previous = _resolveLibraryTag.makeCurrent(); | 244 PerformanceTag previous = _resolveLibraryTag.makeCurrent(); |
250 try { | 245 try { |
251 if (analysisDriver != null) { | 246 if (analysisDriver != null) { |
252 String path = librarySource.fullName; | 247 String path = librarySource.fullName; |
253 analysisDriver.priorityFiles = [path]; | 248 analysisDriver.priorityFiles = [path]; |
254 UnitElementResult elementResult = | 249 UnitElementResult elementResult = |
255 await analysisDriver.getUnitElement(path); | 250 await analysisDriver.getUnitElement(path); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 303 } |
309 | 304 |
310 @override | 305 @override |
311 void logInformation(String message, [CaughtException exception]) { | 306 void logInformation(String message, [CaughtException exception]) { |
312 outSink.writeln(message); | 307 outSink.writeln(message); |
313 if (exception != null) { | 308 if (exception != null) { |
314 outSink.writeln(exception); | 309 outSink.writeln(exception); |
315 } | 310 } |
316 } | 311 } |
317 } | 312 } |
OLD | NEW |