| 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.source.error_processor; | 5 library analyzer.source.error_processor; |
| 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/utilities_general.dart'; | 9 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 10 import 'package:analyzer/src/task/options.dart'; | 10 import 'package:analyzer/src/task/options.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 }); | 47 }); |
| 48 } else if (codes is Map) { | 48 } else if (codes is Map) { |
| 49 codes.forEach((k, v) { | 49 codes.forEach((k, v) { |
| 50 if (k is String) { | 50 if (k is String) { |
| 51 _process(k, v); | 51 _process(k, v); |
| 52 } | 52 } |
| 53 }); | 53 }); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 ErrorSeverity _toSeverity(String severity) { | 57 ErrorSeverity _toSeverity(String severity) => severityMap[severity]; |
| 58 switch (severity) { | 58 } |
| 59 case 'error': | |
| 60 return ErrorSeverity.ERROR; | |
| 61 case 'info': | |
| 62 return ErrorSeverity.INFO; | |
| 63 case 'warning': | |
| 64 return ErrorSeverity.WARNING; | |
| 65 } | |
| 66 return null; | |
| 67 } | |
| 68 | 59 |
| 69 } | 60 /// String identifiers mapped to associated severities. |
| 61 const Map<String, ErrorSeverity> severityMap = const { |
| 62 'error': ErrorSeverity.ERROR, |
| 63 'info': ErrorSeverity.INFO, |
| 64 'warning': ErrorSeverity.WARNING |
| 65 }; |
| 70 | 66 |
| 71 /// Process errors by filtering or changing associated [ErrorSeverity]. | 67 /// Process errors by filtering or changing associated [ErrorSeverity]. |
| 72 class ErrorProcessor { | 68 class ErrorProcessor { |
| 73 /// The code name of the associated error. | 69 /// The code name of the associated error. |
| 74 final String code; | 70 final String code; |
| 75 | 71 |
| 76 /// The desired severity of the processed error. | 72 /// The desired severity of the processed error. |
| 77 /// | 73 /// |
| 78 /// If `null`, this processor will "filter" the associated error code. | 74 /// If `null`, this processor will "filter" the associated error code. |
| 79 final ErrorSeverity severity; | 75 final ErrorSeverity severity; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 AnalysisContext context, AnalysisError error) { | 92 AnalysisContext context, AnalysisError error) { |
| 97 if (context == null) { | 93 if (context == null) { |
| 98 return null; | 94 return null; |
| 99 } | 95 } |
| 100 List<ErrorProcessor> processors = | 96 List<ErrorProcessor> processors = |
| 101 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); | 97 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); |
| 102 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error), | 98 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error), |
| 103 orElse: () => null); | 99 orElse: () => null); |
| 104 } | 100 } |
| 105 } | 101 } |
| OLD | NEW |