Skip to content

Commit 21ab9e1

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Add uniqueNameCheck constructor parameter.
Adds the constructor parameter `uniqueNameCheck` to `DiagnosticCode` and derived classes. If a non-null value is supplied for this parameter, an assertion checks that it's equal to `uniqueName`. (Passing a `null` value disables the assertion; this is necessary to preserve analyzer API compatibility). The reason for this change is that the value supplied for `uniqueName` when calling constructors in the `DiagnosticCode` class hierarchy is not necessarily the same as the value that is eventually stored in the `uniqueName` field; it goes through a sequence of manipulations while being passed up the superclass chain that make its actual behavior difficult to follow. The `uniqueNameCheck` field allows me to test the theory that the actual values that wind up in `uniqueName` are simply the analyzer codes, with the exception that `LinterLintCode.` is replaced with `LintCode.`. In a follow-up CL, I plan to eliminate nearly all the manipulations of `uniqueName` that occur while being passed up the superclass chain, which will simplify the code generation logic for computing `uniqueName` values. Adding `uniqueNameCheck` now allows me to test out the new, simpler logic, and verify that it will produce the same result as today's more complex logic. The `uniqueNameCheck` parameter is marked as `@deprecated` to prevent clients from trying to use it; this ensures that when I remove it in a follow-up CL, it won't be necessary to bump the analyzer major version. Change-Id: I6a6a696440bce62a31b988d12064244e54e37b6b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458820 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent d91281f commit 21ab9e1

File tree

33 files changed

+1936
-113
lines changed

33 files changed

+1936
-113
lines changed

pkg/_fe_analyzer_shared/lib/src/base/errors.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ abstract class DiagnosticCode {
243243
* associated with the error will be created from the given [problemMessage]
244244
* template. The correction associated with the error will be created from the
245245
* given [correctionMessage] template.
246+
*
247+
* If a non-null value is supplied for [uniqueNameCheck], it should be the
248+
* same as [uniqueName]. This parameter is marked `@deprecated` because it
249+
* should not be used by client; it exists as a temporary measure to aid in
250+
* migration and will soon be removed.
246251
*/
247252
const DiagnosticCode({
248253
String? correctionMessage,
@@ -251,7 +256,12 @@ abstract class DiagnosticCode {
251256
required this.name,
252257
required String problemMessage,
253258
required this.uniqueName,
254-
}) : _correctionMessage = correctionMessage,
259+
@deprecated String? uniqueNameCheck,
260+
}) : assert(
261+
uniqueName == uniqueNameCheck || uniqueNameCheck == null,
262+
'$uniqueName != $uniqueNameCheck',
263+
),
264+
_correctionMessage = correctionMessage,
255265
_problemMessage = problemMessage;
256266

257267
/**
@@ -329,6 +339,7 @@ class DiagnosticCodeImpl extends DiagnosticCode {
329339
required super.problemMessage,
330340
required this.type,
331341
required super.uniqueName,
342+
required super.uniqueNameCheck,
332343
});
333344

334345
@override
@@ -348,6 +359,7 @@ abstract class DiagnosticCodeWithExpectedTypes extends DiagnosticCodeImpl {
348359
required super.problemMessage,
349360
required super.type,
350361
required super.uniqueName,
362+
required super.uniqueNameCheck,
351363
this.expectedTypes,
352364
});
353365
}

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.g.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
2929
conflictingKey = TransformSetErrorTemplate(
3030
name: 'conflicting_key',
3131
problemMessage: "The key '{0}' can't be used when '{1}' is also used.",
32+
uniqueNameCheck: 'TransformSetErrorCode.conflicting_key',
3233
withArguments: _withArgumentsConflictingKey,
3334
expectedTypes: [ExpectedType.object, ExpectedType.object],
3435
);
@@ -38,6 +39,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
3839
TransformSetErrorWithoutArguments(
3940
name: 'expected_primary',
4041
problemMessage: "Expected either an identifier or a string literal.",
42+
uniqueNameCheck: 'TransformSetErrorCode.expected_primary',
4143
expectedTypes: [],
4244
);
4345

@@ -51,6 +53,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
5153
name: 'incompatible_element_kind',
5254
problemMessage:
5355
"An element of kind '{0}' can't be replaced by an element of kind '{1}'.",
56+
uniqueNameCheck: 'TransformSetErrorCode.incompatible_element_kind',
5457
withArguments: _withArgumentsIncompatibleElementKind,
5558
expectedTypes: [ExpectedType.object, ExpectedType.object],
5659
);
@@ -65,6 +68,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
6568
name: 'invalid_change_for_kind',
6669
problemMessage:
6770
"A change of type '{0}' can't be used for an element of kind '{1}'.",
71+
uniqueNameCheck: 'TransformSetErrorCode.invalid_change_for_kind',
6872
withArguments: _withArgumentsInvalidChangeForKind,
6973
expectedTypes: [ExpectedType.object, ExpectedType.object],
7074
);
@@ -77,6 +81,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
7781
invalidCharacter = TransformSetErrorTemplate(
7882
name: 'invalid_character',
7983
problemMessage: "Invalid character '{0}'.",
84+
uniqueNameCheck: 'TransformSetErrorCode.invalid_character',
8085
withArguments: _withArgumentsInvalidCharacter,
8186
expectedTypes: [ExpectedType.object],
8287
);
@@ -89,6 +94,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
8994
invalidKey = TransformSetErrorTemplate(
9095
name: 'invalid_key',
9196
problemMessage: "Keys must be of type 'String' but found the type '{0}'.",
97+
uniqueNameCheck: 'TransformSetErrorCode.invalid_key',
9298
withArguments: _withArgumentsInvalidKey,
9399
expectedTypes: [ExpectedType.object],
94100
);
@@ -101,6 +107,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
101107
invalidParameterStyle = TransformSetErrorTemplate(
102108
name: 'invalid_parameter_style',
103109
problemMessage: "The parameter style must be one of the following: {0}.",
110+
uniqueNameCheck: 'TransformSetErrorCode.invalid_parameter_style',
104111
withArguments: _withArgumentsInvalidParameterStyle,
105112
expectedTypes: [ExpectedType.object],
106113
);
@@ -111,6 +118,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
111118
name: 'invalid_required_if',
112119
problemMessage:
113120
"The key 'requiredIf' can only be used with optional named parameters.",
121+
uniqueNameCheck: 'TransformSetErrorCode.invalid_required_if',
114122
expectedTypes: [],
115123
);
116124

@@ -129,6 +137,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
129137
name: 'invalid_value',
130138
problemMessage:
131139
"The value of '{0}' should be of type '{1}' but is of type '{2}'.",
140+
uniqueNameCheck: 'TransformSetErrorCode.invalid_value',
132141
withArguments: _withArgumentsInvalidValue,
133142
expectedTypes: [
134143
ExpectedType.object,
@@ -146,6 +155,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
146155
invalidValueOneOf = TransformSetErrorTemplate(
147156
name: 'invalid_value_one_of',
148157
problemMessage: "The value of '{0}' must be one of the following: '{1}'.",
158+
uniqueNameCheck: 'TransformSetErrorCode.invalid_value_one_of',
149159
withArguments: _withArgumentsInvalidValueOneOf,
150160
expectedTypes: [ExpectedType.object, ExpectedType.object],
151161
);
@@ -158,6 +168,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
158168
missingKey = TransformSetErrorTemplate(
159169
name: 'missing_key',
160170
problemMessage: "Missing the required key '{0}'.",
171+
uniqueNameCheck: 'TransformSetErrorCode.missing_key',
161172
withArguments: _withArgumentsMissingKey,
162173
expectedTypes: [ExpectedType.object],
163174
);
@@ -170,6 +181,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
170181
missingOneOfMultipleKeys = TransformSetErrorTemplate(
171182
name: 'missing_one_of_multiple_keys',
172183
problemMessage: "Exactly one of the following keys must be provided: {0}.",
184+
uniqueNameCheck: 'TransformSetErrorCode.missing_one_of_multiple_keys',
173185
withArguments: _withArgumentsMissingOneOfMultipleKeys,
174186
expectedTypes: [ExpectedType.object],
175187
);
@@ -179,6 +191,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
179191
TransformSetErrorWithoutArguments(
180192
name: 'missing_template_end',
181193
problemMessage: "Missing the end brace for the template.",
194+
uniqueNameCheck: 'TransformSetErrorCode.missing_template_end',
182195
expectedTypes: [],
183196
);
184197

@@ -190,6 +203,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
190203
missingToken = TransformSetErrorTemplate(
191204
name: 'missing_token',
192205
problemMessage: "Expected to find {0}.",
206+
uniqueNameCheck: 'TransformSetErrorCode.missing_token',
193207
withArguments: _withArgumentsMissingToken,
194208
expectedTypes: [ExpectedType.object],
195209
);
@@ -199,6 +213,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
199213
TransformSetErrorWithoutArguments(
200214
name: 'missing_uri',
201215
problemMessage: "At least one URI must be provided.",
216+
uniqueNameCheck: 'TransformSetErrorCode.missing_uri',
202217
expectedTypes: [],
203218
);
204219

@@ -210,6 +225,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
210225
undefinedVariable = TransformSetErrorTemplate(
211226
name: 'undefined_variable',
212227
problemMessage: "The variable '{0}' isn't defined.",
228+
uniqueNameCheck: 'TransformSetErrorCode.undefined_variable',
213229
withArguments: _withArgumentsUndefinedVariable,
214230
expectedTypes: [ExpectedType.object],
215231
);
@@ -222,6 +238,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
222238
unexpectedTransformSetToken = TransformSetErrorTemplate(
223239
name: 'unexpected_transform_set_token',
224240
problemMessage: "Didn't expect to find {0}.",
241+
uniqueNameCheck: 'TransformSetErrorCode.unexpected_transform_set_token',
225242
withArguments: _withArgumentsUnexpectedTransformSetToken,
226243
expectedTypes: [ExpectedType.object],
227244
);
@@ -234,6 +251,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
234251
unknownAccessor = TransformSetErrorTemplate(
235252
name: 'unknown_accessor',
236253
problemMessage: "The accessor '{0}' is invalid.",
254+
uniqueNameCheck: 'TransformSetErrorCode.unknown_accessor',
237255
withArguments: _withArgumentsUnknownAccessor,
238256
expectedTypes: [ExpectedType.object],
239257
);
@@ -246,6 +264,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
246264
unsupportedKey = TransformSetErrorTemplate(
247265
name: 'unsupported_key',
248266
problemMessage: "The key '{0}' isn't supported.",
267+
uniqueNameCheck: 'TransformSetErrorCode.unsupported_key',
249268
withArguments: _withArgumentsUnsupportedKey,
250269
expectedTypes: [ExpectedType.object],
251270
);
@@ -257,6 +276,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
257276
problemMessage:
258277
"The key 'static' is only supported for elements in a class, enum, "
259278
"extension, or mixin.",
279+
uniqueNameCheck: 'TransformSetErrorCode.unsupported_static',
260280
expectedTypes: [],
261281
);
262282

@@ -265,6 +285,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
265285
TransformSetErrorWithoutArguments(
266286
name: 'unsupported_version',
267287
problemMessage: "Only version '1' is supported at this time.",
288+
uniqueNameCheck: 'TransformSetErrorCode.unsupported_version',
268289
expectedTypes: [],
269290
);
270291

@@ -277,6 +298,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
277298
wrongToken = TransformSetErrorTemplate(
278299
name: 'wrong_token',
279300
problemMessage: "Expected to find {0}, but found {1}.",
301+
uniqueNameCheck: 'TransformSetErrorCode.wrong_token',
280302
withArguments: _withArgumentsWrongToken,
281303
expectedTypes: [ExpectedType.object, ExpectedType.object],
282304
);
@@ -289,6 +311,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
289311
yamlSyntaxError = TransformSetErrorTemplate(
290312
name: 'yaml_syntax_error',
291313
problemMessage: "Parse error: {0}",
314+
uniqueNameCheck: 'TransformSetErrorCode.yaml_syntax_error',
292315
withArguments: _withArgumentsYamlSyntaxError,
293316
expectedTypes: [ExpectedType.object],
294317
);
@@ -301,6 +324,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
301324
super.hasPublishedDocs = false,
302325
super.isUnresolvedIdentifier = false,
303326
String? uniqueName,
327+
required String super.uniqueNameCheck,
304328
required super.expectedTypes,
305329
}) : super(
306330
type: DiagnosticType.COMPILE_TIME_ERROR,
@@ -452,6 +476,7 @@ final class TransformSetErrorTemplate<T extends Function>
452476
super.hasPublishedDocs = false,
453477
super.isUnresolvedIdentifier = false,
454478
super.uniqueName,
479+
required super.uniqueNameCheck,
455480
required super.expectedTypes,
456481
required this.withArguments,
457482
});
@@ -467,6 +492,7 @@ final class TransformSetErrorWithoutArguments extends TransformSetErrorCode
467492
super.hasPublishedDocs = false,
468493
super.isUnresolvedIdentifier = false,
469494
super.uniqueName,
495+
required super.uniqueNameCheck,
470496
required super.expectedTypes,
471497
});
472498
}

pkg/analysis_server/test/protocol_server_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ class AnalysisErrorTest {
175175
'my_lint',
176176
'my message',
177177
correctionMessage: 'correction',
178+
// ignore: deprecated_member_use
179+
uniqueNameCheck: 'LintCode.my_lint',
178180
),
179181
offset: 10,
180182
length: 20,

pkg/analysis_server/test/shared/shared_code_actions_fixes_tests.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ class _DeprecatedCamelCaseTypes extends AnalysisRule {
876876
correctionMessage:
877877
'Try changing the name to follow the UpperCamelCase style.',
878878
hasPublishedDocs: true,
879+
// ignore: deprecated_member_use
880+
uniqueNameCheck: 'LintCode.camel_case_types',
879881
);
880882

881883
_DeprecatedCamelCaseTypes()

pkg/analysis_server/test/src/services/completion/yaml/analysis_options_generator_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ class InternalRule extends AnalysisRule {
325325
'internal_rule',
326326
'Internal rule.',
327327
correctionMessage: 'Try internal rule.',
328+
// ignore: deprecated_member_use
329+
uniqueNameCheck: 'LintCode.internal_rule',
328330
);
329331

330332
InternalRule()
@@ -339,7 +341,12 @@ class InternalRule extends AnalysisRule {
339341
}
340342

341343
class _RemovedLint extends AnalysisRule {
342-
static const LintCode _code = LintCode('removed_lint', 'Removed rule.');
344+
static const LintCode _code = LintCode(
345+
'removed_lint',
346+
'Removed rule.',
347+
// ignore: deprecated_member_use
348+
uniqueNameCheck: 'LintCode.removed_lint',
349+
);
343350

344351
_RemovedLint()
345352
: super(name: 'removed_lint', state: RuleState.removed(), description: '');

pkg/analysis_server/test/src/services/correction/fix/analysis_options/remove_lint_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class DeprecatedRule extends AnalysisRule {
2222
'deprecated_rule',
2323
'Deprecated rule.',
2424
correctionMessage: 'Try deprecated rule.',
25+
// ignore: deprecated_member_use
26+
uniqueNameCheck: 'LintCode.deprecated_rule',
2527
);
2628

2729
DeprecatedRule()
@@ -40,6 +42,8 @@ class RemovedRule extends AnalysisRule {
4042
'removed_rule',
4143
'Removed rule.',
4244
correctionMessage: 'Try removed rule.',
45+
// ignore: deprecated_member_use
46+
uniqueNameCheck: 'LintCode.removed_rule',
4347
);
4448

4549
RemovedRule()

pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ class FixProcessorMapTest {
4848
required CorrectionProducerContext context,
4949
}) => MockCorrectionProducer();
5050

51-
var lintCode = LintCode('test_rule', 'Test rule.');
51+
var lintCode = LintCode(
52+
'test_rule',
53+
'Test rule.',
54+
// ignore: deprecated_member_use
55+
uniqueNameCheck: 'LintCode.test_rule',
56+
);
5257
expect(registeredFixGenerators.lintProducers[lintCode], null);
5358
registeredFixGenerators.registerFixForLint(lintCode, generator);
5459
expect(

pkg/analysis_server_plugin/test/src/lint_rules.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class NeedsPackageRule extends AnalysisRule {
1313
static const LintCode code = LintCode(
1414
'needs_package',
1515
'Needs Package at {0}',
16+
// ignore: deprecated_member_use
17+
uniqueNameCheck: 'LintCode.needs_package',
1618
);
1719

1820
NeedsPackageRule()
@@ -34,7 +36,12 @@ class NeedsPackageRule extends AnalysisRule {
3436
}
3537

3638
class NoBoolsRule extends AnalysisRule {
37-
static const LintCode code = LintCode('no_bools', 'No bools message');
39+
static const LintCode code = LintCode(
40+
'no_bools',
41+
'No bools message',
42+
// ignore: deprecated_member_use
43+
uniqueNameCheck: 'LintCode.no_bools',
44+
);
3845

3946
NoBoolsRule() : super(name: 'no_bools', description: 'No bools desc');
4047

@@ -56,6 +63,8 @@ class NoDoublesCustomSeverityRule extends AnalysisRule {
5663
'no_doubles_custom_severity',
5764
'No doubles message',
5865
severity: DiagnosticSeverity.WARNING,
66+
// ignore: deprecated_member_use
67+
uniqueNameCheck: 'LintCode.no_doubles_custom_severity',
5968
);
6069

6170
NoDoublesCustomSeverityRule()
@@ -78,7 +87,12 @@ class NoDoublesCustomSeverityRule extends AnalysisRule {
7887
}
7988

8089
class NoDoublesRule extends AnalysisRule {
81-
static const LintCode code = LintCode('no_doubles', 'No doubles message');
90+
static const LintCode code = LintCode(
91+
'no_doubles',
92+
'No doubles message',
93+
// ignore: deprecated_member_use
94+
uniqueNameCheck: 'LintCode.no_doubles',
95+
);
8296

8397
NoDoublesRule()
8498
: super(name: 'no_doubles', description: 'No doubles message');
@@ -100,6 +114,8 @@ class NoReferencesToStringsRule extends AnalysisRule {
100114
static const LintCode code = LintCode(
101115
'no_references_to_strings',
102116
'No references to Strings',
117+
// ignore: deprecated_member_use
118+
uniqueNameCheck: 'LintCode.no_references_to_strings',
103119
);
104120

105121
NoReferencesToStringsRule()

0 commit comments

Comments
 (0)