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/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 this.options, this.startTime); | 58 this.options, this.startTime); |
59 | 59 |
60 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 60 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
61 ErrorSeverity get maxErrorSeverity { | 61 ErrorSeverity get maxErrorSeverity { |
62 var status = ErrorSeverity.NONE; | 62 var status = ErrorSeverity.NONE; |
63 for (AnalysisErrorInfo errorInfo in errorInfos) { | 63 for (AnalysisErrorInfo errorInfo in errorInfos) { |
64 for (AnalysisError error in errorInfo.errors) { | 64 for (AnalysisError error in errorInfo.errors) { |
65 if (!_isDesiredError(error)) { | 65 if (!_isDesiredError(error)) { |
66 continue; | 66 continue; |
67 } | 67 } |
68 var severity = computeSeverity(error, options.enableTypeChecks); | 68 var severity = computeSeverity(error, options); |
69 status = status.max(severity); | 69 status = status.max(severity); |
70 } | 70 } |
71 } | 71 } |
72 return status; | 72 return status; |
73 } | 73 } |
74 | 74 |
75 void addCompilationUnitSource(CompilationUnitElement unit, | 75 void addCompilationUnitSource(CompilationUnitElement unit, |
76 Set<LibraryElement> libraries, Set<CompilationUnitElement> units) { | 76 Set<LibraryElement> libraries, Set<CompilationUnitElement> units) { |
77 if (unit == null || units.contains(unit)) { | 77 if (unit == null || units.contains(unit)) { |
78 return; | 78 return; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 183 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
184 status = ErrorSeverity.ERROR; | 184 status = ErrorSeverity.ERROR; |
185 } | 185 } |
186 return status; | 186 return status; |
187 } | 187 } |
188 | 188 |
189 bool _isDesiredError(AnalysisError error) { | 189 bool _isDesiredError(AnalysisError error) { |
190 if (error.errorCode.type == ErrorType.TODO) { | 190 if (error.errorCode.type == ErrorType.TODO) { |
191 return false; | 191 return false; |
192 } | 192 } |
193 if (computeSeverity(error, options.enableTypeChecks) == | 193 if (computeSeverity(error, options) == |
194 ErrorSeverity.INFO && | 194 ErrorSeverity.INFO && |
195 options.disableHints) { | 195 options.disableHints) { |
196 return false; | 196 return false; |
197 } | 197 } |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 /// Determine whether the given URI refers to a package other than the package | 201 /// Determine whether the given URI refers to a package other than the package |
202 /// being analyzed. | 202 /// being analyzed. |
203 bool _isOtherPackage(Uri uri) { | 203 bool _isOtherPackage(Uri uri) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // passed in from batch mode which removes the batch flag to prevent the | 235 // passed in from batch mode which removes the batch flag to prevent the |
236 // "cannot have the batch flag and source file" error message. | 236 // "cannot have the batch flag and source file" error message. |
237 StringSink sink = options.machineFormat ? errorSink : outSink; | 237 StringSink sink = options.machineFormat ? errorSink : outSink; |
238 | 238 |
239 // Print errors. | 239 // Print errors. |
240 ErrorFormatter formatter = | 240 ErrorFormatter formatter = |
241 new ErrorFormatter(sink, options, _isDesiredError); | 241 new ErrorFormatter(sink, options, _isDesiredError); |
242 formatter.formatErrors(errorInfos); | 242 formatter.formatErrors(errorInfos); |
243 } | 243 } |
244 | 244 |
245 /// Compute the severity of the error; however, if | 245 /// Compute the severity of the error; however: |
246 /// [enableTypeChecks] is false, then de-escalate checked-mode compile time | 246 /// * if [options.enableTypeChecks] is false, then de-escalate checked-mode |
247 /// errors to a severity of [ErrorSeverity.INFO]. | 247 /// compile time errors to a severity of [ErrorSeverity.INFO]. |
| 248 /// * if [options.hintsAreFatal] is true, escalate hints to errors. |
248 static ErrorSeverity computeSeverity( | 249 static ErrorSeverity computeSeverity( |
249 AnalysisError error, bool enableTypeChecks) { | 250 AnalysisError error, CommandLineOptions options) { |
250 if (!enableTypeChecks && | 251 if (!options.enableTypeChecks && |
251 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { | 252 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { |
252 return ErrorSeverity.INFO; | 253 return ErrorSeverity.INFO; |
253 } | 254 } |
| 255 if (options.hintsAreFatal && error.errorCode is HintCode) { |
| 256 return ErrorSeverity.ERROR; |
| 257 } |
254 return error.errorCode.errorSeverity; | 258 return error.errorCode.errorSeverity; |
255 } | 259 } |
256 | 260 |
257 /// Return the corresponding package directory or `null` if none is found. | 261 /// Return the corresponding package directory or `null` if none is found. |
258 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { | 262 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { |
259 // We are going to ask parent file, so get absolute path. | 263 // We are going to ask parent file, so get absolute path. |
260 sourceFile = sourceFile.getAbsoluteFile(); | 264 sourceFile = sourceFile.getAbsoluteFile(); |
261 // Look in the containing directories. | 265 // Look in the containing directories. |
262 JavaFile dir = sourceFile.getParentFile(); | 266 JavaFile dir = sourceFile.getParentFile(); |
263 while (dir != null) { | 267 while (dir != null) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 306 } |
303 | 307 |
304 @override | 308 @override |
305 void logInformation2(String message, Object exception) { | 309 void logInformation2(String message, Object exception) { |
306 outSink.writeln(message); | 310 outSink.writeln(message); |
307 if (exception != null) { | 311 if (exception != null) { |
308 outSink.writeln(exception.toString()); | 312 outSink.writeln(exception.toString()); |
309 } | 313 } |
310 } | 314 } |
311 } | 315 } |
OLD | NEW |