Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 error_formatter; | 5 library error_formatter; |
| 6 | 6 |
| 7 import 'generated/engine.dart'; | 7 import 'generated/engine.dart'; |
| 8 import 'generated/error.dart'; | 8 import 'generated/error.dart'; |
| 9 import 'generated/source_io.dart'; | 9 import 'generated/source_io.dart'; |
| 10 import '../options.dart'; | 10 import '../options.dart'; |
| 11 | 11 |
| 12 typedef bool _ErrorFilter(AnalysisError error); | |
|
Brian Wilkerson
2014/03/21 13:23:00
Perhaps document that the function is expected to
scheglov
2014/03/21 16:17:38
Done.
| |
| 13 bool _anyError(AnalysisError error) => true; | |
| 14 | |
| 12 /** | 15 /** |
| 13 * Helper for formatting [AnalysisError]s. | 16 * Helper for formatting [AnalysisError]s. |
| 14 * The two format options are a user consumable format and a machine consumable format. | 17 * The two format options are a user consumable format and a machine consumable format. |
| 15 */ | 18 */ |
| 16 class ErrorFormatter { | 19 class ErrorFormatter { |
| 17 StringSink out; | 20 final StringSink out; |
| 18 CommandLineOptions options; | 21 final CommandLineOptions options; |
| 22 final _ErrorFilter errorFilter; | |
| 19 | 23 |
| 20 ErrorFormatter(this.out, this.options); | 24 ErrorFormatter(this.out, this.options, [this.errorFilter = _anyError]); |
| 21 | 25 |
| 22 void formatErrors(List<AnalysisErrorInfo> errorInfos) { | 26 void formatErrors(List<AnalysisErrorInfo> errorInfos) { |
| 23 var errors = new List<AnalysisError>(); | 27 var errors = new List<AnalysisError>(); |
| 24 var errorToLine = new Map<AnalysisError, LineInfo>(); | 28 var errorToLine = new Map<AnalysisError, LineInfo>(); |
| 25 for (AnalysisErrorInfo errorInfo in errorInfos) { | 29 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| 26 for (AnalysisError error in errorInfo.errors) { | 30 for (AnalysisError error in errorInfo.errors) { |
| 27 errors.add(error); | 31 if (errorFilter(error)) { |
| 28 errorToLine[error] = errorInfo.lineInfo; | 32 errors.add(error); |
| 33 errorToLine[error] = errorInfo.lineInfo; | |
| 34 } | |
| 29 } | 35 } |
| 30 } | 36 } |
| 31 // sort errors | 37 // sort errors |
| 32 errors.sort((AnalysisError error1, AnalysisError error2) { | 38 errors.sort((AnalysisError error1, AnalysisError error2) { |
| 33 // severity | 39 // severity |
| 34 int compare = error2.errorCode.errorSeverity.compareTo(error1.errorCode.er rorSeverity); | 40 int compare = error2.errorCode.errorSeverity.compareTo(error1.errorCode.er rorSeverity); |
| 35 if (compare != 0) { | 41 if (compare != 0) { |
| 36 return compare; | 42 return compare; |
| 37 } | 43 } |
| 38 // path | 44 // path |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 } | 161 } |
| 156 | 162 |
| 157 static String pluralize(String word, int count) { | 163 static String pluralize(String word, int count) { |
| 158 if (count == 1) { | 164 if (count == 1) { |
| 159 return word; | 165 return word; |
| 160 } else { | 166 } else { |
| 161 return word + "s"; | 167 return word + "s"; |
| 162 } | 168 } |
| 163 } | 169 } |
| 164 } | 170 } |
| OLD | NEW |