@@ -11,7 +11,6 @@ import 'package:analyzer/source/error_processor.dart';
11
11
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart' ;
12
12
import 'package:analyzer/src/analysis_options/error/option_codes.dart' ;
13
13
import 'package:analyzer/src/dart/error/hint_codes.dart' ;
14
- import 'package:analyzer/src/dart/error/syntactic_errors.dart' ;
15
14
import 'package:analyzer/src/error/codes.dart' ;
16
15
import 'package:analyzer/src/file_system/file_system.dart' ;
17
16
import 'package:analyzer/src/generated/engine.dart' ;
@@ -149,14 +148,21 @@ analyzer:
149
148
@reflectiveTest
150
149
class ErrorCodeValuesTest {
151
150
test_errorCodes () {
151
+ // Now that we're using unique names for comparison, the only reason to
152
+ // split the codes by class is to find all of the classes that need to be
153
+ // checked against `errorCodeValues`.
152
154
var errorTypeMap = < Type , List <ErrorCode >> {};
153
155
for (ErrorCode code in errorCodeValues) {
154
- errorTypeMap.putIfAbsent (code.runtimeType, () => < ErrorCode > []).add (code);
156
+ Type type = code.runtimeType;
157
+ if (type == HintCodeWithUniqueName ) {
158
+ type = HintCode ;
159
+ }
160
+ errorTypeMap.putIfAbsent (type, () => < ErrorCode > []).add (code);
155
161
}
156
162
157
- int missingErrorCodeCount = 0 ;
163
+ StringBuffer missingCodes = StringBuffer () ;
158
164
errorTypeMap.forEach ((Type errorType, List <ErrorCode > codes) {
159
- var listedNames = codes.map ((ErrorCode code) => code.name ).toSet ();
165
+ var listedNames = codes.map ((ErrorCode code) => code.uniqueName ).toSet ();
160
166
161
167
var declaredNames = reflectClass (errorType)
162
168
.declarations
@@ -165,115 +171,23 @@ class ErrorCodeValuesTest {
165
171
String name = declarationMirror.simpleName.toString ();
166
172
//TODO(danrubel): find a better way to extract the text from the symbol
167
173
assert (name.startsWith ('Symbol("' ) && name.endsWith ('")' ));
168
- return name.substring (8 , name.length - 2 );
174
+ return errorType. toString () + '.' + name.substring (8 , name.length - 2 );
169
175
}).where ((String name) {
170
176
return name == name.toUpperCase ();
171
177
}).toList ();
172
178
173
- // Remove declared names that are not supposed to be in errorCodeValues
174
-
175
- if (errorType == AnalysisOptionsErrorCode ) {
176
- declaredNames
177
- .remove (AnalysisOptionsErrorCode .INCLUDED_FILE_PARSE_ERROR .name);
178
- } else if (errorType == AnalysisOptionsWarningCode ) {
179
- declaredNames
180
- .remove (AnalysisOptionsWarningCode .INCLUDE_FILE_NOT_FOUND .name);
181
- declaredNames
182
- .remove (AnalysisOptionsWarningCode .INCLUDED_FILE_WARNING .name);
183
- declaredNames
184
- .remove (AnalysisOptionsWarningCode .INVALID_SECTION_FORMAT .name);
185
- } else if (errorType == StaticWarningCode ) {
186
- declaredNames.remove (
187
- StaticWarningCode .FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS .name +
188
- '_PLUS' );
189
- declaredNames.remove ('EXTRA_POSITIONAL_ARGUMENTS' );
190
- declaredNames.remove ('EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED' );
191
- declaredNames.remove ('IMPORT_OF_NON_LIBRARY' );
192
- declaredNames.remove ('NOT_ENOUGH_REQUIRED_ARGUMENTS' );
193
- declaredNames.remove ('REDIRECT_TO_MISSING_CONSTRUCTOR' );
194
- declaredNames.remove ('REDIRECT_TO_NON_CLASS' );
195
- declaredNames.remove ('UNDEFINED_CLASS' );
196
- declaredNames.remove ('UNDEFINED_NAMED_PARAMETER' );
197
- } else if (errorType == StrongModeCode ) {
198
- void removeCode (StrongModeCode code) {
199
- declaredNames.remove (code.name);
200
- }
201
-
202
- removeCode (StrongModeCode .DOWN_CAST_COMPOSITE );
203
- removeCode (StrongModeCode .DOWN_CAST_IMPLICIT );
204
- removeCode (StrongModeCode .DOWN_CAST_IMPLICIT_ASSIGN );
205
- removeCode (StrongModeCode .DYNAMIC_CAST );
206
- removeCode (StrongModeCode .ASSIGNMENT_CAST );
207
- removeCode (StrongModeCode .INVALID_PARAMETER_DECLARATION );
208
- removeCode (StrongModeCode .COULD_NOT_INFER );
209
- removeCode (StrongModeCode .INFERRED_TYPE );
210
- removeCode (StrongModeCode .INFERRED_TYPE_LITERAL );
211
- removeCode (StrongModeCode .INFERRED_TYPE_ALLOCATION );
212
- removeCode (StrongModeCode .INFERRED_TYPE_CLOSURE );
213
- removeCode (StrongModeCode .INVALID_CAST_LITERAL );
214
- removeCode (StrongModeCode .INVALID_CAST_LITERAL_LIST );
215
- removeCode (StrongModeCode .INVALID_CAST_LITERAL_MAP );
216
- removeCode (StrongModeCode .INVALID_CAST_LITERAL_SET );
217
- removeCode (StrongModeCode .INVALID_CAST_FUNCTION_EXPR );
218
- removeCode (StrongModeCode .INVALID_CAST_NEW_EXPR );
219
- removeCode (StrongModeCode .INVALID_CAST_METHOD );
220
- removeCode (StrongModeCode .INVALID_CAST_FUNCTION );
221
- removeCode (StrongModeCode .INVALID_SUPER_INVOCATION );
222
- removeCode (StrongModeCode .NON_GROUND_TYPE_CHECK_INFO );
223
- removeCode (StrongModeCode .DYNAMIC_INVOKE );
224
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_PARAMETER );
225
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_RETURN );
226
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_VARIABLE );
227
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_FIELD );
228
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_TYPE );
229
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_LIST_LITERAL );
230
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_MAP_LITERAL );
231
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_FUNCTION );
232
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_METHOD );
233
- removeCode (StrongModeCode .IMPLICIT_DYNAMIC_INVOKE );
234
- removeCode (StrongModeCode .NOT_INSTANTIATED_BOUND );
235
- removeCode (StrongModeCode .TOP_LEVEL_CYCLE );
236
- removeCode (StrongModeCode .TOP_LEVEL_FUNCTION_LITERAL_BLOCK );
237
- removeCode (StrongModeCode .TOP_LEVEL_IDENTIFIER_NO_TYPE );
238
- removeCode (StrongModeCode .TOP_LEVEL_INSTANCE_GETTER );
239
- removeCode (StrongModeCode .TOP_LEVEL_INSTANCE_METHOD );
240
- } else if (errorType == TodoCode ) {
241
- declaredNames.remove ('TODO_REGEX' );
242
- } else if (errorType == CompileTimeErrorCode ) {
243
- declaredNames.remove ('ANNOTATION_WITH_TYPE_ARGUMENTS' );
244
- declaredNames.remove ('NOT_ENOUGH_REQUIRED_ARGUMENTS' );
245
- } else if (errorType == ParserErrorCode ) {
246
- declaredNames.remove ('CONST_AFTER_FACTORY' );
247
- declaredNames.remove ('CONST_AND_COVARIANT' );
248
- declaredNames.remove ('CONST_AND_VAR' );
249
- declaredNames.remove ('COVARIANT_AFTER_FINAL' );
250
- declaredNames.remove ('COVARIANT_AFTER_VAR' );
251
- declaredNames.remove ('EXTERNAL_AFTER_CONST' );
252
- declaredNames.remove ('EXTERNAL_AFTER_FACTORY' );
253
- declaredNames.remove ('EXTERNAL_AFTER_STATIC' );
254
- declaredNames.remove ('MISSING_CLASS_BODY' );
255
- declaredNames.remove ('STATIC_AFTER_CONST' );
256
- declaredNames.remove ('STATIC_AFTER_FINAL' );
257
- declaredNames.remove ('STATIC_AFTER_VAR' );
258
- }
259
-
260
- // Assert that all remaining declared names are in errorCodeValues
179
+ // Assert that all declared names are in errorCodeValues
261
180
262
181
for (String declaredName in declaredNames) {
263
182
if (! listedNames.contains (declaredName)) {
264
- ++ missingErrorCodeCount ;
265
- print (' errorCodeValues is missing $ errorType $declaredName ' );
183
+ missingCodes. writeln () ;
184
+ missingCodes. write (' $declaredName ' );
266
185
}
267
186
}
268
187
});
269
- expect (missingErrorCodeCount, 0 , reason: 'missing error code names' );
270
-
271
- // Apparently, duplicate error codes are allowed
272
- // expect(
273
- // ErrorFilterOptionValidator.errorCodes.length,
274
- // errorCodeValues.length,
275
- // reason: 'some errorCodeValues have the same name',
276
- // );
188
+ if (missingCodes.isNotEmpty) {
189
+ fail ('Missing error codes:$missingCodes ' );
190
+ }
277
191
}
278
192
}
279
193
0 commit comments