| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 /// If the file specified on the command line is part of a package, the name | 57 /// If the file specified on the command line is part of a package, the name |
| 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. | |
| 68 ErrorSeverity computeMaxErrorSeverity() { | |
| 69 ErrorSeverity status = ErrorSeverity.NONE; | |
| 70 for (AnalysisErrorInfo errorInfo in errorInfos) { | |
| 71 for (AnalysisError error in errorInfo.errors) { | |
| 72 if (_defaultSeverityProcessor(error) == null) { | |
| 73 continue; | |
| 74 } | |
| 75 status = status.max(computeSeverity(error, options, analysisOptions)); | |
| 76 } | |
| 77 } | |
| 78 return status; | |
| 79 } | |
| 80 | |
| 81 void addCompilationUnitSource( | 67 void addCompilationUnitSource( |
| 82 CompilationUnitElement unit, Set<CompilationUnitElement> units) { | 68 CompilationUnitElement unit, Set<CompilationUnitElement> units) { |
| 83 if (unit == null || !units.add(unit)) { | 69 if (unit == null || !units.add(unit)) { |
| 84 return; | 70 return; |
| 85 } | 71 } |
| 86 Source source = unit.source; | 72 Source source = unit.source; |
| 87 if (source != null) { | 73 if (source != null) { |
| 88 sources.add(source); | 74 sources.add(source); |
| 89 } | 75 } |
| 90 } | 76 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 116 /// the analysis engine. If [printMode] is `0`, then no error or performance | 102 /// the analysis engine. If [printMode] is `0`, then no error or performance |
| 117 /// information is printed. If [printMode] is `1`, then errors will be printed
. | 103 /// information is printed. If [printMode] is `1`, then errors will be printed
. |
| 118 /// If [printMode] is `2`, then performance information will be printed, and | 104 /// If [printMode] is `2`, then performance information will be printed, and |
| 119 /// it will be marked as being for a cold VM. | 105 /// it will be marked as being for a cold VM. |
| 120 Future<ErrorSeverity> analyze(ErrorFormatter formatter, | 106 Future<ErrorSeverity> analyze(ErrorFormatter formatter, |
| 121 {int printMode: 1}) async { | 107 {int printMode: 1}) async { |
| 122 setupForAnalysis(); | 108 setupForAnalysis(); |
| 123 return await _analyze(printMode, formatter); | 109 return await _analyze(printMode, formatter); |
| 124 } | 110 } |
| 125 | 111 |
| 112 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
| 113 ErrorSeverity computeMaxErrorSeverity() { |
| 114 ErrorSeverity status = ErrorSeverity.NONE; |
| 115 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| 116 for (AnalysisError error in errorInfo.errors) { |
| 117 if (_defaultSeverityProcessor(error) == null) { |
| 118 continue; |
| 119 } |
| 120 status = status.max(computeSeverity(error, options, analysisOptions)); |
| 121 } |
| 122 } |
| 123 return status; |
| 124 } |
| 125 |
| 126 /// Fills [errorInfos] using [sources]. | 126 /// Fills [errorInfos] using [sources]. |
| 127 Future<Null> prepareErrors() async { | 127 Future<Null> prepareErrors() async { |
| 128 PerformanceTag previous = _prepareErrorsTag.makeCurrent(); | 128 PerformanceTag previous = _prepareErrorsTag.makeCurrent(); |
| 129 try { | 129 try { |
| 130 for (Source source in sources) { | 130 for (Source source in sources) { |
| 131 if (analysisDriver != null) { | 131 if (analysisDriver != null) { |
| 132 String path = source.fullName; | 132 String path = source.fullName; |
| 133 ErrorsResult errorsResult = await analysisDriver.getErrors(path); | 133 ErrorsResult errorsResult = await analysisDriver.getErrors(path); |
| 134 errorInfos.add(new AnalysisErrorInfoImpl( | 134 errorInfos.add(new AnalysisErrorInfoImpl( |
| 135 errorsResult.errors, errorsResult.lineInfo)); | 135 errorsResult.errors, errorsResult.lineInfo)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (printMode == 1) { | 181 if (printMode == 1) { |
| 182 formatter.formatErrors(errorInfos); | 182 formatter.formatErrors(errorInfos); |
| 183 } else if (printMode == 2) { | 183 } else if (printMode == 2) { |
| 184 _printColdPerf(); | 184 _printColdPerf(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Compute and return max severity. | 187 // Compute and return max severity. |
| 188 return computeMaxErrorSeverity(); | 188 return computeMaxErrorSeverity(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 ErrorSeverity _defaultSeverityProcessor(AnalysisError error) => |
| 192 determineProcessedSeverity(error, options, analysisOptions); |
| 193 |
| 191 /// Returns true if we want to report diagnostics for this library. | 194 /// Returns true if we want to report diagnostics for this library. |
| 192 bool _isAnalyzedLibrary(LibraryElement library) { | 195 bool _isAnalyzedLibrary(LibraryElement library) { |
| 193 Source source = library.source; | 196 Source source = library.source; |
| 194 switch (source.uriKind) { | 197 switch (source.uriKind) { |
| 195 case UriKind.DART_URI: | 198 case UriKind.DART_URI: |
| 196 return options.showSdkWarnings; | 199 return options.showSdkWarnings; |
| 197 case UriKind.PACKAGE_URI: | 200 case UriKind.PACKAGE_URI: |
| 198 if (_isPathInPubCache(source.fullName)) { | 201 if (_isPathInPubCache(source.fullName)) { |
| 199 return false; | 202 return false; |
| 200 } | 203 } |
| 201 return _isAnalyzedPackage(source.uri); | 204 return _isAnalyzedPackage(source.uri); |
| 202 default: | 205 default: |
| 203 return true; | 206 return true; |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 210 // TODO(devoncarew): This is never called. |
| 207 /// Determine whether the given URI refers to a package being analyzed. | 211 /// Determine whether the given URI refers to a package being analyzed. |
| 208 bool _isAnalyzedPackage(Uri uri) { | 212 bool _isAnalyzedPackage(Uri uri) { |
| 209 if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { | 213 if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { |
| 210 return false; | 214 return false; |
| 211 } | 215 } |
| 212 String packageName = uri.pathSegments.first; | 216 String packageName = uri.pathSegments.first; |
| 213 if (packageName == _selfPackageName) { | 217 if (packageName == _selfPackageName) { |
| 214 return true; | 218 return true; |
| 215 } else if (!options.showPackageWarnings) { | 219 } else if (!options.showPackageWarnings) { |
| 216 return false; | 220 return false; |
| 217 } else if (options.showPackageWarningsPrefix == null) { | 221 } else if (options.showPackageWarningsPrefix == null) { |
| 218 return true; | 222 return true; |
| 219 } else { | 223 } else { |
| 220 return packageName.startsWith(options.showPackageWarningsPrefix); | 224 return packageName.startsWith(options.showPackageWarningsPrefix); |
| 221 } | 225 } |
| 222 } | 226 } |
| 223 | 227 |
| 224 // TODO(devoncarew): This is never called. | |
| 225 void _printColdPerf() { | 228 void _printColdPerf() { |
| 226 // Print cold VM performance numbers. | 229 // Print cold VM performance numbers. |
| 227 int totalTime = currentTimeMillis - startTime; | 230 int totalTime = currentTimeMillis - startTime; |
| 228 int otherTime = totalTime; | 231 int otherTime = totalTime; |
| 229 for (PerformanceTag tag in PerformanceTag.all) { | 232 for (PerformanceTag tag in PerformanceTag.all) { |
| 230 if (tag != PerformanceTag.unknown) { | 233 if (tag != PerformanceTag.unknown) { |
| 231 int tagTime = tag.elapsedMs; | 234 int tagTime = tag.elapsedMs; |
| 232 outSink.writeln('${tag.label}-cold:$tagTime'); | 235 outSink.writeln('${tag.label}-cold:$tagTime'); |
| 233 otherTime -= tagTime; | 236 otherTime -= tagTime; |
| 234 } | 237 } |
| 235 } | 238 } |
| 236 outSink.writeln('other-cold:$otherTime'); | 239 outSink.writeln('other-cold:$otherTime'); |
| 237 outSink.writeln("total-cold:$totalTime"); | 240 outSink.writeln("total-cold:$totalTime"); |
| 238 } | 241 } |
| 239 | 242 |
| 240 ErrorSeverity _defaultSeverityProcessor(AnalysisError error) => | |
| 241 determineProcessedSeverity(error, options, analysisOptions); | |
| 242 | |
| 243 Future<LibraryElement> _resolveLibrary() async { | 243 Future<LibraryElement> _resolveLibrary() async { |
| 244 PerformanceTag previous = _resolveLibraryTag.makeCurrent(); | 244 PerformanceTag previous = _resolveLibraryTag.makeCurrent(); |
| 245 try { | 245 try { |
| 246 if (analysisDriver != null) { | 246 if (analysisDriver != null) { |
| 247 String path = librarySource.fullName; | 247 String path = librarySource.fullName; |
| 248 analysisDriver.priorityFiles = [path]; | 248 analysisDriver.priorityFiles = [path]; |
| 249 UnitElementResult elementResult = | 249 UnitElementResult elementResult = |
| 250 await analysisDriver.getUnitElement(path); | 250 await analysisDriver.getUnitElement(path); |
| 251 return elementResult.element.library; | 251 return elementResult.element.library; |
| 252 } else { | 252 } else { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 | 304 |
| 305 @override | 305 @override |
| 306 void logInformation(String message, [CaughtException exception]) { | 306 void logInformation(String message, [CaughtException exception]) { |
| 307 outSink.writeln(message); | 307 outSink.writeln(message); |
| 308 if (exception != null) { | 308 if (exception != null) { |
| 309 outSink.writeln(exception); | 309 outSink.writeln(exception); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| OLD | NEW |