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:collection'; | 7 import 'dart:collection'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 if (_processError(error) == null) { | 69 if (_processError(error) == null) { |
70 continue; | 70 continue; |
71 } | 71 } |
72 var severity = computeSeverity(error, options); | 72 var severity = computeSeverity(error, options); |
73 status = status.max(severity); | 73 status = status.max(severity); |
74 } | 74 } |
75 } | 75 } |
76 return status; | 76 return status; |
77 } | 77 } |
78 | 78 |
79 void addCompilationUnitSource(CompilationUnitElement unit, | 79 void addCompilationUnitSource( |
80 Set<LibraryElement> libraries, Set<CompilationUnitElement> units) { | 80 CompilationUnitElement unit, Set<CompilationUnitElement> units) { |
81 if (unit == null || units.contains(unit)) { | 81 if (unit == null || units.contains(unit)) { |
82 return; | 82 return; |
83 } | 83 } |
84 units.add(unit); | 84 units.add(unit); |
85 sources.add(unit.source); | 85 sources.add(unit.source); |
86 } | 86 } |
87 | 87 |
88 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries, | 88 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries, |
89 Set<CompilationUnitElement> units) { | 89 Set<CompilationUnitElement> units) { |
90 if (library == null || !libraries.add(library)) { | 90 if (library == null || !libraries.add(library)) { |
91 return; | 91 return; |
92 } | 92 } |
93 // Maybe skip library. | 93 // Maybe skip library. |
94 { | 94 if (!_isAnalyzedLibrary(library)) { |
95 UriKind uriKind = library.source.uriKind; | 95 return; |
96 // Optionally skip package: libraries. | |
97 if (!options.showPackageWarnings && _isOtherPackage(library.source.uri)) { | |
98 return; | |
99 } | |
100 // Optionally skip SDK libraries. | |
101 if (!options.showSdkWarnings && uriKind == UriKind.DART_URI) { | |
102 return; | |
103 } | |
104 } | 96 } |
105 // Add compilation units. | 97 // Add compilation units. |
106 addCompilationUnitSource(library.definingCompilationUnit, libraries, units); | 98 addCompilationUnitSource(library.definingCompilationUnit, units); |
107 for (CompilationUnitElement child in library.parts) { | 99 for (CompilationUnitElement child in library.parts) { |
108 addCompilationUnitSource(child, libraries, units); | 100 addCompilationUnitSource(child, units); |
109 } | 101 } |
110 // Add referenced libraries. | 102 // Add referenced libraries. |
111 for (LibraryElement child in library.importedLibraries) { | 103 for (LibraryElement child in library.importedLibraries) { |
112 addLibrarySources(child, libraries, units); | 104 addLibrarySources(child, libraries, units); |
113 } | 105 } |
114 for (LibraryElement child in library.exportedLibraries) { | 106 for (LibraryElement child in library.exportedLibraries) { |
115 addLibrarySources(child, libraries, units); | 107 addLibrarySources(child, libraries, units); |
116 } | 108 } |
117 } | 109 } |
118 | 110 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 166 } |
175 | 167 |
176 // Compute max severity and set exitCode. | 168 // Compute max severity and set exitCode. |
177 ErrorSeverity status = maxErrorSeverity; | 169 ErrorSeverity status = maxErrorSeverity; |
178 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 170 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
179 status = ErrorSeverity.ERROR; | 171 status = ErrorSeverity.ERROR; |
180 } | 172 } |
181 return status; | 173 return status; |
182 } | 174 } |
183 | 175 |
184 /// Determine whether the given URI refers to a package other than the package | 176 /// Returns true if we want to report diagnostics for this library. |
185 /// being analyzed. | 177 bool _isAnalyzedLibrary(LibraryElement library) { |
186 bool _isOtherPackage(Uri uri) { | 178 switch (library.source.uriKind) { |
187 if (uri.scheme != 'package') { | 179 case UriKind.DART_URI: |
| 180 return options.showSdkWarnings; |
| 181 case UriKind.PACKAGE_URI: |
| 182 return _isAnalyzedPackage(library.source.uri); |
| 183 default: |
| 184 return true; |
| 185 } |
| 186 } |
| 187 |
| 188 /// Determine whether the given URI refers to a package being analyzed. |
| 189 bool _isAnalyzedPackage(Uri uri) { |
| 190 if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { |
188 return false; | 191 return false; |
189 } | 192 } |
190 if (_selfPackageName != null && | 193 |
191 uri.pathSegments.length > 0 && | 194 String packageName = uri.pathSegments.first; |
192 uri.pathSegments[0] == _selfPackageName) { | 195 if (packageName == _selfPackageName) { |
| 196 return true; |
| 197 } else if (!options.showPackageWarnings) { |
193 return false; | 198 return false; |
| 199 } else if (options.showPackageWarningsPrefix == null) { |
| 200 return true; |
| 201 } else { |
| 202 return packageName.startsWith(options.showPackageWarningsPrefix); |
194 } | 203 } |
195 return true; | |
196 } | 204 } |
197 | 205 |
198 _printColdPerf() { | 206 _printColdPerf() { |
199 // Print cold VM performance numbers. | 207 // Print cold VM performance numbers. |
200 int totalTime = currentTimeMillis() - startTime; | 208 int totalTime = currentTimeMillis() - startTime; |
201 int otherTime = totalTime; | 209 int otherTime = totalTime; |
202 for (PerformanceTag tag in PerformanceTag.all) { | 210 for (PerformanceTag tag in PerformanceTag.all) { |
203 if (tag != PerformanceTag.UNKNOWN) { | 211 if (tag != PerformanceTag.UNKNOWN) { |
204 int tagTime = tag.elapsedMs; | 212 int tagTime = tag.elapsedMs; |
205 outSink.writeln('${tag.label}-cold:$tagTime'); | 213 outSink.writeln('${tag.label}-cold:$tagTime'); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 331 } |
324 | 332 |
325 @override | 333 @override |
326 void logInformation(String message, [CaughtException exception]) { | 334 void logInformation(String message, [CaughtException exception]) { |
327 outSink.writeln(message); | 335 outSink.writeln(message); |
328 if (exception != null) { | 336 if (exception != null) { |
329 outSink.writeln(exception); | 337 outSink.writeln(exception); |
330 } | 338 } |
331 } | 339 } |
332 } | 340 } |
OLD | NEW |