| 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.error_formatter; | 5 library analyzer_cli.src.error_formatter; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer_cli/src/options.dart'; | 10 import 'package:analyzer_cli/src/options.dart'; |
| 11 | 11 |
| 12 /// Returns the given error's severity. | 12 /// Returns the given error's severity. |
| 13 ProcessedSeverity _identity(AnalysisError error) => | 13 ProcessedSeverity _identity(AnalysisError error) => |
| 14 new ProcessedSeverity(error.errorCode.errorSeverity); | 14 new ProcessedSeverity(error.errorCode.errorSeverity); |
| 15 | 15 |
| 16 String _pluralize(String word, int count) => count == 1 ? word : word + "s"; | 16 String _pluralize(String word, int count) => count == 1 ? word : word + "s"; |
| 17 | 17 |
| 18 /// Returns desired severity for the given [error] (or `null` if it's to be | 18 /// Returns desired severity for the given [error] (or `null` if it's to be |
| 19 /// suppressed). | 19 /// suppressed). |
| 20 typedef ProcessedSeverity _SeverityProcessor(AnalysisError error); | 20 typedef ProcessedSeverity _SeverityProcessor(AnalysisError error); |
| 21 | 21 |
| 22 /// Analysis statistics counter. | 22 /// Analysis statistics counter. |
| 23 class AnalysisStats { | 23 class AnalysisStats { |
| 24 /// The total number of diagnostics sent to [formatErrors]. |
| 25 int unfilteredCount; |
| 26 |
| 24 int errorCount; | 27 int errorCount; |
| 25 int hintCount; | 28 int hintCount; |
| 26 int lintCount; | 29 int lintCount; |
| 27 int warnCount; | 30 int warnCount; |
| 28 | 31 |
| 29 AnalysisStats() { | 32 AnalysisStats() { |
| 30 init(); | 33 init(); |
| 31 } | 34 } |
| 32 | 35 |
| 36 /// The total number of diagnostics reported to the user. |
| 37 int get filteredCount => errorCount + warnCount + hintCount + lintCount; |
| 38 |
| 33 /// (Re)set initial values. | 39 /// (Re)set initial values. |
| 34 void init() { | 40 void init() { |
| 41 unfilteredCount = 0; |
| 35 errorCount = 0; | 42 errorCount = 0; |
| 36 hintCount = 0; | 43 hintCount = 0; |
| 37 lintCount = 0; | 44 lintCount = 0; |
| 38 warnCount = 0; | 45 warnCount = 0; |
| 39 } | 46 } |
| 40 | 47 |
| 41 /// Print statistics to [out]. | 48 /// Print statistics to [out]. |
| 42 void print(StringSink out) { | 49 void print(StringSink out) { |
| 43 var hasErrors = errorCount != 0; | 50 var hasErrors = errorCount != 0; |
| 44 var hasWarns = warnCount != 0; | 51 var hasWarns = warnCount != 0; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 162 |
| 156 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) | 163 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) |
| 157 out.write('[$errorType] ${error.message} '); | 164 out.write('[$errorType] ${error.message} '); |
| 158 out.write('(${source.fullName}'); | 165 out.write('(${source.fullName}'); |
| 159 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); | 166 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); |
| 160 } | 167 } |
| 161 out.writeln(); | 168 out.writeln(); |
| 162 } | 169 } |
| 163 | 170 |
| 164 void formatErrors(List<AnalysisErrorInfo> errorInfos) { | 171 void formatErrors(List<AnalysisErrorInfo> errorInfos) { |
| 172 stats.unfilteredCount += errorInfos.length; |
| 173 |
| 165 var errors = new List<AnalysisError>(); | 174 var errors = new List<AnalysisError>(); |
| 166 var errorToLine = new Map<AnalysisError, LineInfo>(); | 175 var errorToLine = new Map<AnalysisError, LineInfo>(); |
| 167 for (AnalysisErrorInfo errorInfo in errorInfos) { | 176 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| 168 for (AnalysisError error in errorInfo.errors) { | 177 for (AnalysisError error in errorInfo.errors) { |
| 169 if (computeSeverity(error) != null) { | 178 if (computeSeverity(error) != null) { |
| 170 errors.add(error); | 179 errors.add(error); |
| 171 errorToLine[error] = errorInfo.lineInfo; | 180 errorToLine[error] = errorInfo.lineInfo; |
| 172 } | 181 } |
| 173 } | 182 } |
| 174 } | 183 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return result.toString(); | 233 return result.toString(); |
| 225 } | 234 } |
| 226 } | 235 } |
| 227 | 236 |
| 228 /// A severity with awareness of whether it was overridden by a processor. | 237 /// A severity with awareness of whether it was overridden by a processor. |
| 229 class ProcessedSeverity { | 238 class ProcessedSeverity { |
| 230 ErrorSeverity severity; | 239 ErrorSeverity severity; |
| 231 bool overridden; | 240 bool overridden; |
| 232 ProcessedSeverity(this.severity, [this.overridden = false]); | 241 ProcessedSeverity(this.severity, [this.overridden = false]); |
| 233 } | 242 } |
| OLD | NEW |