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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 /// then no error or performance information is printed. If [printMode] is `1` , | 114 /// then no error or performance information is printed. If [printMode] is `1` , |
115 /// then both will be printed. If [printMode] is `2`, then only performance | 115 /// then both will be printed. If [printMode] is `2`, then only performance |
116 /// information will be printed, and it will be marked as being for a cold VM. | 116 /// information will be printed, and it will be marked as being for a cold VM. |
117 ErrorSeverity analyzeSync({int printMode: 1}) { | 117 ErrorSeverity analyzeSync({int printMode: 1}) { |
118 setupForAnalysis(); | 118 setupForAnalysis(); |
119 return _analyzeSync(printMode); | 119 return _analyzeSync(printMode); |
120 } | 120 } |
121 | 121 |
122 /// Fills [errorInfos] using [sources]. | 122 /// Fills [errorInfos] using [sources]. |
123 void prepareErrors() { | 123 void prepareErrors() { |
124 for (Source source in sources) { | 124 return _prepareErrorsTag.makeCurrentWhile(() { |
125 context.computeErrors(source); | 125 for (Source source in sources) { |
126 context.computeErrors(source); | |
127 errorInfos.add(context.getErrors(source)); | |
Brian Wilkerson
2015/12/16 15:08:43
The original code looks weird to me. Seems like we
skybrian
2015/12/17 04:20:27
Yes that does seem strange, but I think I'd like t
Brian Wilkerson
2015/12/17 15:05:41
sounds good
| |
128 } | |
129 }); | |
130 } | |
126 | 131 |
127 errorInfos.add(context.getErrors(source)); | 132 static final PerformanceTag _prepareErrorsTag = |
Brian Wilkerson
2015/12/16 15:08:43
Don't forget to sort and format the file before co
skybrian
2015/12/17 04:20:27
Formatted. It's not clear to me which order this f
Brian Wilkerson
2015/12/17 15:05:41
The sort function available from either IntelliJ o
| |
128 } | 133 new PerformanceTag("AnalyzerImpl.prepareErrors"); |
129 } | |
130 | 134 |
131 /// Fills [sources]. | 135 /// Fills [sources]. |
132 void prepareSources(LibraryElement library) { | 136 void prepareSources(LibraryElement library) { |
133 var units = new Set<CompilationUnitElement>(); | 137 var units = new Set<CompilationUnitElement>(); |
134 var libraries = new Set<LibraryElement>(); | 138 var libraries = new Set<LibraryElement>(); |
135 addLibrarySources(library, libraries, units); | 139 addLibrarySources(library, libraries, units); |
136 } | 140 } |
137 | 141 |
138 /// Setup local fields such as the analysis context for analysis. | 142 /// Setup local fields such as the analysis context for analysis. |
139 void setupForAnalysis() { | 143 void setupForAnalysis() { |
140 sources.clear(); | 144 sources.clear(); |
141 errorInfos.clear(); | 145 errorInfos.clear(); |
142 Uri libraryUri = librarySource.uri; | 146 Uri libraryUri = librarySource.uri; |
143 if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { | 147 if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { |
144 _selfPackageName = libraryUri.pathSegments[0]; | 148 _selfPackageName = libraryUri.pathSegments[0]; |
145 } | 149 } |
146 } | 150 } |
147 | 151 |
148 /// The sync version of analysis. | 152 /// The sync version of analysis. |
149 ErrorSeverity _analyzeSync(int printMode) { | 153 ErrorSeverity _analyzeSync(int printMode) { |
150 // Don't try to analyze parts. | 154 // Don't try to analyze parts. |
151 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 155 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
152 stderr.writeln("Only libraries can be analyzed."); | 156 stderr.writeln("Only libraries can be analyzed."); |
153 stderr.writeln( | 157 stderr.writeln( |
154 "${librarySource.fullName} is a part and can not be analyzed."); | 158 "${librarySource.fullName} is a part and can not be analyzed."); |
155 return ErrorSeverity.ERROR; | 159 return ErrorSeverity.ERROR; |
156 } | 160 } |
157 // Resolve library. | 161 var libraryElement = _resolveLibrary(); |
158 var libraryElement = context.computeLibraryElement(librarySource); | |
159 // Prepare source and errors. | |
160 prepareSources(libraryElement); | 162 prepareSources(libraryElement); |
161 prepareErrors(); | 163 prepareErrors(); |
162 | 164 |
163 // Print errors and performance numbers. | 165 // Print errors and performance numbers. |
164 if (printMode == 1) { | 166 if (printMode == 1) { |
165 _printErrorsAndPerf(); | 167 _printErrors(); |
166 } else if (printMode == 2) { | 168 } else if (printMode == 2) { |
167 _printColdPerf(); | 169 _printColdPerf(); |
168 } | 170 } |
169 | 171 |
170 // Compute max severity and set exitCode. | 172 // Compute max severity and set exitCode. |
171 ErrorSeverity status = maxErrorSeverity; | 173 ErrorSeverity status = maxErrorSeverity; |
172 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 174 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
173 status = ErrorSeverity.ERROR; | 175 status = ErrorSeverity.ERROR; |
174 } | 176 } |
175 return status; | 177 return status; |
176 } | 178 } |
177 | 179 |
180 LibraryElement _resolveLibrary() { | |
181 return _resolveLibraryTag.makeCurrentWhile(() { | |
182 return context.computeLibraryElement(librarySource); | |
183 }); | |
184 } | |
185 | |
186 static final PerformanceTag _resolveLibraryTag = | |
187 new PerformanceTag("AnalyzerImpl._resolveLibrary"); | |
188 | |
178 bool _isDesiredError(AnalysisError error) { | 189 bool _isDesiredError(AnalysisError error) { |
179 if (error.errorCode.type == ErrorType.TODO) { | 190 if (error.errorCode.type == ErrorType.TODO) { |
180 return false; | 191 return false; |
181 } | 192 } |
182 if (computeSeverity(error, options) == ErrorSeverity.INFO && | 193 if (computeSeverity(error, options) == ErrorSeverity.INFO && |
183 options.disableHints) { | 194 options.disableHints) { |
184 return false; | 195 return false; |
185 } | 196 } |
186 return true; | 197 return true; |
187 } | 198 } |
(...skipping 20 matching lines...) Expand all Loading... | |
208 if (tag != PerformanceTag.UNKNOWN) { | 219 if (tag != PerformanceTag.UNKNOWN) { |
209 int tagTime = tag.elapsedMs; | 220 int tagTime = tag.elapsedMs; |
210 outSink.writeln('${tag.label}-cold:$tagTime'); | 221 outSink.writeln('${tag.label}-cold:$tagTime'); |
211 otherTime -= tagTime; | 222 otherTime -= tagTime; |
212 } | 223 } |
213 } | 224 } |
214 outSink.writeln('other-cold:$otherTime'); | 225 outSink.writeln('other-cold:$otherTime'); |
215 outSink.writeln("total-cold:$totalTime"); | 226 outSink.writeln("total-cold:$totalTime"); |
216 } | 227 } |
217 | 228 |
218 _printErrorsAndPerf() { | 229 _printErrors() { |
219 // The following is a hack. We currently print out to stderr to ensure that | 230 // The following is a hack. We currently print out to stderr to ensure that |
220 // when in batch mode we print to stderr, this is because the prints from | 231 // when in batch mode we print to stderr, this is because the prints from |
221 // batch are made to stderr. The reason that options.shouldBatch isn't used | 232 // batch are made to stderr. The reason that options.shouldBatch isn't used |
222 // is because when the argument flags are constructed in BatchRunner and | 233 // is because when the argument flags are constructed in BatchRunner and |
223 // passed in from batch mode which removes the batch flag to prevent the | 234 // passed in from batch mode which removes the batch flag to prevent the |
224 // "cannot have the batch flag and source file" error message. | 235 // "cannot have the batch flag and source file" error message. |
225 StringSink sink = options.machineFormat ? errorSink : outSink; | 236 StringSink sink = options.machineFormat ? errorSink : outSink; |
226 | 237 |
227 // Print errors. | 238 // Print errors. |
228 ErrorFormatter formatter = | 239 ErrorFormatter formatter = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 } | 289 } |
279 | 290 |
280 @override | 291 @override |
281 void logInformation(String message, [CaughtException exception]) { | 292 void logInformation(String message, [CaughtException exception]) { |
282 outSink.writeln(message); | 293 outSink.writeln(message); |
283 if (exception != null) { | 294 if (exception != null) { |
284 outSink.writeln(exception); | 295 outSink.writeln(exception); |
285 } | 296 } |
286 } | 297 } |
287 } | 298 } |
OLD | NEW |