Skip to content

Commit 9c9ee03

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Stop including class name in uniqueName.
Modifies the code generation logic that populates the `DiagnosticCode.uniqueName` field so that it doesn't include the diagnostic's class name. This paves the way for removing the last remenants of the diagnostic classes from the analyzer. Change-Id: I6a6a696453fe1f2bd8bd3cea00a9a496392fbf98 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464240 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent ae4a1f1 commit 9c9ee03

File tree

8 files changed

+1669
-1792
lines changed

8 files changed

+1669
-1792
lines changed

pkg/_fe_analyzer_shared/test/constants/data/errors.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ String method() => 'foo';
66

77
const String string0 =
88
/*cfe|dart2js.error: Method invocation is not a constant expression.*/
9-
/*analyzer.error: CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION*/ method();
9+
/*analyzer.error: CONST_EVAL_METHOD_INVOCATION*/ method();
1010

1111
main() {
1212
print(string0);

pkg/_fe_analyzer_shared/test/inheritance/data/function.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
/*class: A:A,Object*/
66
class A
7-
implements /*analyzer.error: CompileTimeErrorCode.FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY*/
7+
implements /*analyzer.error: FINAL_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY*/
88
/*cfe|cfe:builder.error: FinalClassImplementedOutsideOfLibrary*/ Function {}
99

1010
/*class: B:B,Object*/
1111
class B
12-
extends /*analyzer.error: CompileTimeErrorCode.FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY*/ /*cfe|cfe:builder.error: FinalClassExtendedOutsideOfLibrary*/
12+
extends /*analyzer.error: FINAL_CLASS_EXTENDED_OUTSIDE_OF_LIBRARY*/ /*cfe|cfe:builder.error: FinalClassExtendedOutsideOfLibrary*/
1313
Function {}
1414

1515
/*cfe|cfe:builder.class: C:C,Object,_C&Object&Function*/
1616
/*analyzer.class: C:C,Object*/
1717
/*cfe|cfe:builder.class: _C&Object&Function:Object,_C&Object&Function*/
1818
class /*cfe|cfe:builder.error: SubtypeOfFinalIsNotBaseFinalOrSealed*/ C
1919
extends Object
20-
with /*analyzer.error: CompileTimeErrorCode.CLASS_USED_AS_MIXIN*/
20+
with /*analyzer.error: CLASS_USED_AS_MIXIN*/
2121
/*cfe|cfe:builder.error: CantUseClassAsMixin*/ Function {}
2222

2323
// CFE hides that this is a mixin declaration since its mixed in type has been
2424
// removed.
2525
/*cfe|cfe:builder.class: D:D,Object*/
2626
class D = Object
27-
with /*analyzer.error: CompileTimeErrorCode.CLASS_USED_AS_MIXIN*/ /*cfe|cfe:builder.error: CantUseClassAsMixin*/
27+
with /*analyzer.error: CLASS_USED_AS_MIXIN*/ /*cfe|cfe:builder.error: CantUseClassAsMixin*/
2828
Function;

pkg/analysis_server/lib/src/diagnostic.g.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ conflictingKey = DiagnosticWithArguments(
2626
name: 'conflicting_key',
2727
problemMessage: "The key '{0}' can't be used when '{1}' is also used.",
2828
type: DiagnosticType.COMPILE_TIME_ERROR,
29-
uniqueName: 'TransformSetErrorCode.conflicting_key',
29+
uniqueName: 'conflicting_key',
3030
withArguments: _withArgumentsConflictingKey,
3131
expectedTypes: [ExpectedType.object, ExpectedType.object],
3232
);
@@ -37,7 +37,7 @@ const DiagnosticWithoutArguments expectedPrimary =
3737
name: 'expected_primary',
3838
problemMessage: "Expected either an identifier or a string literal.",
3939
type: DiagnosticType.COMPILE_TIME_ERROR,
40-
uniqueName: 'TransformSetErrorCode.expected_primary',
40+
uniqueName: 'expected_primary',
4141
expectedTypes: [],
4242
);
4343

@@ -52,7 +52,7 @@ incompatibleElementKind = DiagnosticWithArguments(
5252
problemMessage:
5353
"An element of kind '{0}' can't be replaced by an element of kind '{1}'.",
5454
type: DiagnosticType.COMPILE_TIME_ERROR,
55-
uniqueName: 'TransformSetErrorCode.incompatible_element_kind',
55+
uniqueName: 'incompatible_element_kind',
5656
withArguments: _withArgumentsIncompatibleElementKind,
5757
expectedTypes: [ExpectedType.object, ExpectedType.object],
5858
);
@@ -68,7 +68,7 @@ invalidChangeForKind = DiagnosticWithArguments(
6868
problemMessage:
6969
"A change of type '{0}' can't be used for an element of kind '{1}'.",
7070
type: DiagnosticType.COMPILE_TIME_ERROR,
71-
uniqueName: 'TransformSetErrorCode.invalid_change_for_kind',
71+
uniqueName: 'invalid_change_for_kind',
7272
withArguments: _withArgumentsInvalidChangeForKind,
7373
expectedTypes: [ExpectedType.object, ExpectedType.object],
7474
);
@@ -82,7 +82,7 @@ invalidCharacter = DiagnosticWithArguments(
8282
name: 'invalid_character',
8383
problemMessage: "Invalid character '{0}'.",
8484
type: DiagnosticType.COMPILE_TIME_ERROR,
85-
uniqueName: 'TransformSetErrorCode.invalid_character',
85+
uniqueName: 'invalid_character',
8686
withArguments: _withArgumentsInvalidCharacter,
8787
expectedTypes: [ExpectedType.object],
8888
);
@@ -96,7 +96,7 @@ invalidKey = DiagnosticWithArguments(
9696
name: 'invalid_key',
9797
problemMessage: "Keys must be of type 'String' but found the type '{0}'.",
9898
type: DiagnosticType.COMPILE_TIME_ERROR,
99-
uniqueName: 'TransformSetErrorCode.invalid_key',
99+
uniqueName: 'invalid_key',
100100
withArguments: _withArgumentsInvalidKey,
101101
expectedTypes: [ExpectedType.object],
102102
);
@@ -110,7 +110,7 @@ invalidParameterStyle = DiagnosticWithArguments(
110110
name: 'invalid_parameter_style',
111111
problemMessage: "The parameter style must be one of the following: {0}.",
112112
type: DiagnosticType.COMPILE_TIME_ERROR,
113-
uniqueName: 'TransformSetErrorCode.invalid_parameter_style',
113+
uniqueName: 'invalid_parameter_style',
114114
withArguments: _withArgumentsInvalidParameterStyle,
115115
expectedTypes: [ExpectedType.object],
116116
);
@@ -122,7 +122,7 @@ invalidRequiredIf = DiagnosticWithoutArgumentsImpl(
122122
problemMessage:
123123
"The key 'requiredIf' can only be used with optional named parameters.",
124124
type: DiagnosticType.COMPILE_TIME_ERROR,
125-
uniqueName: 'TransformSetErrorCode.invalid_required_if',
125+
uniqueName: 'invalid_required_if',
126126
expectedTypes: [],
127127
);
128128

@@ -142,7 +142,7 @@ invalidValue = DiagnosticWithArguments(
142142
problemMessage:
143143
"The value of '{0}' should be of type '{1}' but is of type '{2}'.",
144144
type: DiagnosticType.COMPILE_TIME_ERROR,
145-
uniqueName: 'TransformSetErrorCode.invalid_value',
145+
uniqueName: 'invalid_value',
146146
withArguments: _withArgumentsInvalidValue,
147147
expectedTypes: [
148148
ExpectedType.object,
@@ -161,7 +161,7 @@ invalidValueOneOf = DiagnosticWithArguments(
161161
name: 'invalid_value_one_of',
162162
problemMessage: "The value of '{0}' must be one of the following: '{1}'.",
163163
type: DiagnosticType.COMPILE_TIME_ERROR,
164-
uniqueName: 'TransformSetErrorCode.invalid_value_one_of',
164+
uniqueName: 'invalid_value_one_of',
165165
withArguments: _withArgumentsInvalidValueOneOf,
166166
expectedTypes: [ExpectedType.object, ExpectedType.object],
167167
);
@@ -175,7 +175,7 @@ missingKey = DiagnosticWithArguments(
175175
name: 'missing_key',
176176
problemMessage: "Missing the required key '{0}'.",
177177
type: DiagnosticType.COMPILE_TIME_ERROR,
178-
uniqueName: 'TransformSetErrorCode.missing_key',
178+
uniqueName: 'missing_key',
179179
withArguments: _withArgumentsMissingKey,
180180
expectedTypes: [ExpectedType.object],
181181
);
@@ -189,7 +189,7 @@ missingOneOfMultipleKeys = DiagnosticWithArguments(
189189
name: 'missing_one_of_multiple_keys',
190190
problemMessage: "Exactly one of the following keys must be provided: {0}.",
191191
type: DiagnosticType.COMPILE_TIME_ERROR,
192-
uniqueName: 'TransformSetErrorCode.missing_one_of_multiple_keys',
192+
uniqueName: 'missing_one_of_multiple_keys',
193193
withArguments: _withArgumentsMissingOneOfMultipleKeys,
194194
expectedTypes: [ExpectedType.object],
195195
);
@@ -200,7 +200,7 @@ const DiagnosticWithoutArguments missingTemplateEnd =
200200
name: 'missing_template_end',
201201
problemMessage: "Missing the end brace for the template.",
202202
type: DiagnosticType.COMPILE_TIME_ERROR,
203-
uniqueName: 'TransformSetErrorCode.missing_template_end',
203+
uniqueName: 'missing_template_end',
204204
expectedTypes: [],
205205
);
206206

@@ -213,7 +213,7 @@ missingToken = DiagnosticWithArguments(
213213
name: 'missing_token',
214214
problemMessage: "Expected to find {0}.",
215215
type: DiagnosticType.COMPILE_TIME_ERROR,
216-
uniqueName: 'TransformSetErrorCode.missing_token',
216+
uniqueName: 'missing_token',
217217
withArguments: _withArgumentsMissingToken,
218218
expectedTypes: [ExpectedType.object],
219219
);
@@ -223,7 +223,7 @@ const DiagnosticWithoutArguments missingUri = DiagnosticWithoutArgumentsImpl(
223223
name: 'missing_uri',
224224
problemMessage: "At least one URI must be provided.",
225225
type: DiagnosticType.COMPILE_TIME_ERROR,
226-
uniqueName: 'TransformSetErrorCode.missing_uri',
226+
uniqueName: 'missing_uri',
227227
expectedTypes: [],
228228
);
229229

@@ -236,7 +236,7 @@ undefinedVariable = DiagnosticWithArguments(
236236
name: 'undefined_variable',
237237
problemMessage: "The variable '{0}' isn't defined.",
238238
type: DiagnosticType.COMPILE_TIME_ERROR,
239-
uniqueName: 'TransformSetErrorCode.undefined_variable',
239+
uniqueName: 'undefined_variable',
240240
withArguments: _withArgumentsUndefinedVariable,
241241
expectedTypes: [ExpectedType.object],
242242
);
@@ -250,7 +250,7 @@ unexpectedTransformSetToken = DiagnosticWithArguments(
250250
name: 'unexpected_transform_set_token',
251251
problemMessage: "Didn't expect to find {0}.",
252252
type: DiagnosticType.COMPILE_TIME_ERROR,
253-
uniqueName: 'TransformSetErrorCode.unexpected_transform_set_token',
253+
uniqueName: 'unexpected_transform_set_token',
254254
withArguments: _withArgumentsUnexpectedTransformSetToken,
255255
expectedTypes: [ExpectedType.object],
256256
);
@@ -264,7 +264,7 @@ unknownAccessor = DiagnosticWithArguments(
264264
name: 'unknown_accessor',
265265
problemMessage: "The accessor '{0}' is invalid.",
266266
type: DiagnosticType.COMPILE_TIME_ERROR,
267-
uniqueName: 'TransformSetErrorCode.unknown_accessor',
267+
uniqueName: 'unknown_accessor',
268268
withArguments: _withArgumentsUnknownAccessor,
269269
expectedTypes: [ExpectedType.object],
270270
);
@@ -278,7 +278,7 @@ unsupportedKey = DiagnosticWithArguments(
278278
name: 'unsupported_key',
279279
problemMessage: "The key '{0}' isn't supported.",
280280
type: DiagnosticType.COMPILE_TIME_ERROR,
281-
uniqueName: 'TransformSetErrorCode.unsupported_key',
281+
uniqueName: 'unsupported_key',
282282
withArguments: _withArgumentsUnsupportedKey,
283283
expectedTypes: [ExpectedType.object],
284284
);
@@ -291,7 +291,7 @@ const DiagnosticWithoutArguments unsupportedStatic =
291291
"The key 'static' is only supported for elements in a class, enum, "
292292
"extension, or mixin.",
293293
type: DiagnosticType.COMPILE_TIME_ERROR,
294-
uniqueName: 'TransformSetErrorCode.unsupported_static',
294+
uniqueName: 'unsupported_static',
295295
expectedTypes: [],
296296
);
297297

@@ -301,7 +301,7 @@ const DiagnosticWithoutArguments unsupportedVersion =
301301
name: 'unsupported_version',
302302
problemMessage: "Only version '1' is supported at this time.",
303303
type: DiagnosticType.COMPILE_TIME_ERROR,
304-
uniqueName: 'TransformSetErrorCode.unsupported_version',
304+
uniqueName: 'unsupported_version',
305305
expectedTypes: [],
306306
);
307307

@@ -315,7 +315,7 @@ wrongToken = DiagnosticWithArguments(
315315
name: 'wrong_token',
316316
problemMessage: "Expected to find {0}, but found {1}.",
317317
type: DiagnosticType.COMPILE_TIME_ERROR,
318-
uniqueName: 'TransformSetErrorCode.wrong_token',
318+
uniqueName: 'wrong_token',
319319
withArguments: _withArgumentsWrongToken,
320320
expectedTypes: [ExpectedType.object, ExpectedType.object],
321321
);
@@ -329,7 +329,7 @@ yamlSyntaxError = DiagnosticWithArguments(
329329
name: 'yaml_syntax_error',
330330
problemMessage: "Parse error: {0}",
331331
type: DiagnosticType.COMPILE_TIME_ERROR,
332-
uniqueName: 'TransformSetErrorCode.yaml_syntax_error',
332+
uniqueName: 'yaml_syntax_error',
333333
withArguments: _withArgumentsYamlSyntaxError,
334334
expectedTypes: [ExpectedType.object],
335335
);

pkg/analysis_server/tool/presubmit/verify_error_fix_status.dart

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ String? verifyErrorFixStatus() {
5656
var lintRuleCodes = {
5757
for (var rule in Registry.ruleRegistry.rules) ...rule.diagnosticCodes,
5858
};
59-
var lintRuleNames = {
60-
for (var lintCode in lintRuleCodes) lintCode.uniqueName.suffix,
61-
};
59+
var lintRuleNames = {for (var lintCode in lintRuleCodes) lintCode.uniqueName};
6260

6361
var errorData = ErrorData();
6462
for (var code in diagnosticCodeValues) {
65-
var name = code.uniqueName.suffix;
63+
var name = code.uniqueName;
6664
if (code.type == .TODO) {
6765
// To-do codes are ignored.
6866
continue;
@@ -85,7 +83,7 @@ String? verifyErrorFixStatus() {
8583
}
8684
}
8785
for (var lintCode in lintRuleCodes) {
88-
var name = lintCode.uniqueName.suffix;
86+
var name = lintCode.uniqueName;
8987
var info = statusInfo.nodes[name];
9088
if (info == null) {
9189
errorData.codesWithNoEntry.add(name);
@@ -103,9 +101,7 @@ String? verifyErrorFixStatus() {
103101
}
104102
}
105103

106-
var codeNames = {
107-
for (var code in diagnosticCodeValues) code.uniqueName.suffix,
108-
};
104+
var codeNames = {for (var code in diagnosticCodeValues) code.uniqueName};
109105
for (var key in statusInfo.keys) {
110106
if (key is String) {
111107
if (!codeNames.contains(key) && !lintRuleNames.contains(key)) {
@@ -230,10 +226,3 @@ extension on DiagnosticCode {
230226
PubspecFixGenerator.codesWithFixes.contains(self);
231227
}
232228
}
233-
234-
extension on String {
235-
String get suffix => switch (split('.')) {
236-
[_, var s] => s,
237-
_ => throw 'Expected ErrorClass.ERROR_CODE, found $this',
238-
};
239-
}

0 commit comments

Comments
 (0)