Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: pkg/analyzer/lib/source/error_processor.dart

Issue 1808123005: First batch of changes to make analyzer package strong mode error free (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
11 import 'package:yaml/yaml.dart'; 11 import 'package:yaml/yaml.dart';
12 12
13 /// String identifiers mapped to associated severities.
14 const Map<String, ErrorSeverity> severityMap = const {
15 'error': ErrorSeverity.ERROR,
16 'info': ErrorSeverity.INFO,
17 'warning': ErrorSeverity.WARNING
18 };
19
13 /// Error processor configuration derived from analysis (or embedder) options. 20 /// Error processor configuration derived from analysis (or embedder) options.
14 class ErrorConfig { 21 class ErrorConfig {
15 /// The processors in this config. 22 /// The processors in this config.
16 final List<ErrorProcessor> processors = <ErrorProcessor>[]; 23 final List<ErrorProcessor> processors = <ErrorProcessor>[];
17 24
18 /// Create an error config for the given error code map. 25 /// Create an error config for the given error code map.
19 /// For example: 26 /// For example:
20 /// new ErrorConfig({'missing_return' : 'error'}); 27 /// new ErrorConfig({'missing_return' : 'error'});
21 /// will create a processor config that turns `missing_return` hints into 28 /// will create a processor config that turns `missing_return` hints into
22 /// errors. 29 /// errors.
(...skipping 27 matching lines...) Expand all
50 if (k is String) { 57 if (k is String) {
51 _process(k, v); 58 _process(k, v);
52 } 59 }
53 }); 60 });
54 } 61 }
55 } 62 }
56 63
57 ErrorSeverity _toSeverity(String severity) => severityMap[severity]; 64 ErrorSeverity _toSeverity(String severity) => severityMap[severity];
58 } 65 }
59 66
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 };
66
67 /// Process errors by filtering or changing associated [ErrorSeverity]. 67 /// Process errors by filtering or changing associated [ErrorSeverity].
68 class ErrorProcessor { 68 class ErrorProcessor {
69 /// The code name of the associated error. 69 /// The code name of the associated error.
70 final String code; 70 final String code;
71 71
72 /// The desired severity of the processed error. 72 /// The desired severity of the processed error.
73 /// 73 ///
74 /// If `null`, this processor will "filter" the associated error code. 74 /// If `null`, this processor will "filter" the associated error code.
75 final ErrorSeverity severity; 75 final ErrorSeverity severity;
76 76
(...skipping 12 matching lines...) Expand all
89 /// Return an error processor associated with this [context] for the given 89 /// Return an error processor associated with this [context] for the given
90 /// [error], or `null` if none is found. 90 /// [error], or `null` if none is found.
91 static ErrorProcessor getProcessor( 91 static ErrorProcessor getProcessor(
92 AnalysisContext context, AnalysisError error) { 92 AnalysisContext context, AnalysisError error) {
93 if (context == null) { 93 if (context == null) {
94 return null; 94 return null;
95 } 95 }
96 96
97 // Let the user configure how specific errors are processed. 97 // Let the user configure how specific errors are processed.
98 List<ErrorProcessor> processors = 98 List<ErrorProcessor> processors =
99 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); 99 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS)
100 as List<ErrorProcessor>;
100 101
101 // Give strong mode a chance to upgrade it. 102 // Give strong mode a chance to upgrade it.
102 if (context.analysisOptions.strongMode) { 103 if (context.analysisOptions.strongMode) {
103 processors = processors.toList(); 104 processors = processors.toList();
104 processors.add(_StrongModeTypeErrorProcessor.instance); 105 processors.add(_StrongModeTypeErrorProcessor.instance);
105 } 106 }
106
107 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error), 107 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error),
108 orElse: () => null); 108 orElse: () => null);
109 } 109 }
110 } 110 }
111 111
112 /// In strong mode, this upgrades static type warnings to errors. 112 /// In strong mode, this upgrades static type warnings to errors.
113 class _StrongModeTypeErrorProcessor implements ErrorProcessor { 113 class _StrongModeTypeErrorProcessor implements ErrorProcessor {
114 static final instance = new _StrongModeTypeErrorProcessor(); 114 static final instance = new _StrongModeTypeErrorProcessor();
115 115
116 // TODO(rnystrom): As far as I know, this is only used to implement 116 // TODO(rnystrom): As far as I know, this is only used to implement
117 // appliesTo(). Consider making it private in ErrorProcessor if possible. 117 // appliesTo(). Consider making it private in ErrorProcessor if possible.
118 String get code => throw new UnsupportedError( 118 String get code => throw new UnsupportedError(
119 "_StrongModeTypeErrorProcessor is not specific to an error code."); 119 "_StrongModeTypeErrorProcessor is not specific to an error code.");
120 120
121 /// In strong mode, type warnings are upgraded to errors. 121 /// In strong mode, type warnings are upgraded to errors.
122 ErrorSeverity get severity => ErrorSeverity.ERROR; 122 ErrorSeverity get severity => ErrorSeverity.ERROR;
123 123
124 /// Check if this processor applies to the given [error]. 124 /// Check if this processor applies to the given [error].
125 bool appliesTo(AnalysisError error) => 125 bool appliesTo(AnalysisError error) =>
126 error.errorCode.type == ErrorType.STATIC_TYPE_WARNING; 126 error.errorCode.type == ErrorType.STATIC_TYPE_WARNING;
127 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698