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 /// Returns desired severity for the given [error] (or `null` if it's to be | 16 /// Returns desired severity for the given [error] (or `null` if it's to be |
17 /// suppressed). | 17 /// suppressed). |
18 typedef ProcessedSeverity _SeverityProcessor(AnalysisError error); | 18 typedef ProcessedSeverity _SeverityProcessor(AnalysisError error); |
19 | 19 |
20 /// Helper for formatting [AnalysisError]s. | 20 /// Helper for formatting [AnalysisError]s. |
21 /// The two format options are a user consumable format and a machine consumable | 21 /// The two format options are a user consumable format and a machine consumable |
22 /// format. | 22 /// format. |
23 class ErrorFormatter { | 23 class ErrorFormatter { |
24 /// The total number of errors sent to [formatErrors]. | |
25 static int get inputErrorCount => _inputErrorCount; | |
26 static int _inputErrorCount = 0; | |
Brian Wilkerson
2016/03/18 14:13:17
This looks like it's duplicating some work that Ph
skybrian
2016/03/18 22:32:44
It's a slightly different statistic. Merged into A
| |
27 | |
24 final StringSink out; | 28 final StringSink out; |
25 final CommandLineOptions options; | 29 final CommandLineOptions options; |
26 final _SeverityProcessor processSeverity; | 30 final _SeverityProcessor processSeverity; |
27 | 31 |
28 ErrorFormatter(this.out, this.options, [this.processSeverity = _identity]); | 32 ErrorFormatter(this.out, this.options, [this.processSeverity = _identity]); |
29 | 33 |
30 /// Compute the severity for this [error] or `null` if this error should be | 34 /// Compute the severity for this [error] or `null` if this error should be |
31 /// filtered. | 35 /// filtered. |
32 ErrorSeverity computeSeverity(AnalysisError error) => | 36 ErrorSeverity computeSeverity(AnalysisError error) => |
33 processSeverity(error)?.severity; | 37 processSeverity(error)?.severity; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 80 |
77 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) | 81 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) |
78 out.write('[$errorType] ${error.message} '); | 82 out.write('[$errorType] ${error.message} '); |
79 out.write('(${source.fullName}'); | 83 out.write('(${source.fullName}'); |
80 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); | 84 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); |
81 } | 85 } |
82 out.writeln(); | 86 out.writeln(); |
83 } | 87 } |
84 | 88 |
85 void formatErrors(List<AnalysisErrorInfo> errorInfos) { | 89 void formatErrors(List<AnalysisErrorInfo> errorInfos) { |
90 _inputErrorCount += errorInfos.length; | |
91 | |
86 var errors = new List<AnalysisError>(); | 92 var errors = new List<AnalysisError>(); |
87 var errorToLine = new Map<AnalysisError, LineInfo>(); | 93 var errorToLine = new Map<AnalysisError, LineInfo>(); |
88 for (AnalysisErrorInfo errorInfo in errorInfos) { | 94 for (AnalysisErrorInfo errorInfo in errorInfos) { |
89 for (AnalysisError error in errorInfo.errors) { | 95 for (AnalysisError error in errorInfo.errors) { |
90 if (computeSeverity(error) != null) { | 96 if (computeSeverity(error) != null) { |
91 errors.add(error); | 97 errors.add(error); |
92 errorToLine[error] = errorInfo.lineInfo; | 98 errorToLine[error] = errorInfo.lineInfo; |
93 } | 99 } |
94 } | 100 } |
95 } | 101 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 } | 217 } |
212 } | 218 } |
213 } | 219 } |
214 | 220 |
215 /// A severity with awareness of whether it was overriden by a processor. | 221 /// A severity with awareness of whether it was overriden by a processor. |
216 class ProcessedSeverity { | 222 class ProcessedSeverity { |
217 ErrorSeverity severity; | 223 ErrorSeverity severity; |
218 bool overridden; | 224 bool overridden; |
219 ProcessedSeverity(this.severity, [this.overridden = false]); | 225 ProcessedSeverity(this.severity, [this.overridden = false]); |
220 } | 226 } |
OLD | NEW |