Skip to content

Commit 5343e1b

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Generalize static types of analyzer message constants.
Changes the static types of the diagnostic message constants for the analyzer (and linter) from derived classes like `ParserErrorWithoutArguments`, `ParserErrorTemplate`, or `ParserErrorCode` to the corresponding base classes (`DiagnosticWithoutArguments`, `DiagnosticWithArguments`, or `DiagnosticCode`). The actual runtime types of the constants is unchanged. This is a step toward simplifying the `DiagnosticCode` class hierarchy. Change-Id: I6a6a69643773adcf5834a9b9e3be90623611d4e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458961 Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent 72e3f7a commit 5343e1b

File tree

15 files changed

+1789
-1707
lines changed

15 files changed

+1789
-1707
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,22 @@ class DiagnosticType implements Comparable<DiagnosticType> {
575575
String toString() => name;
576576
}
577577

578+
/// Common functionality for [DiagnosticCode]-derived classes that represent
579+
/// errors that take arguments.
580+
///
581+
/// This class provides a [withArguments] getter, which can be used to supply
582+
/// arguments and produce a [LocatableDiagnostic].
583+
abstract class DiagnosticWithArguments<T extends Function>
584+
implements DiagnosticCode {
585+
/// Function accepting named arguments and returning [LocatableDiagnostic].
586+
///
587+
/// The value returned by this function can
588+
/// be associated with a location in the source code using the
589+
/// [LocatableDiagnostic.at] method, and then the result can be passed to
590+
/// [DiagnosticReporter.reportError].
591+
T get withArguments;
592+
}
593+
578594
/// Common functionality for [DiagnosticCode]-derived classes that represent
579595
/// errors that do not take arguments.
580596
///

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
2323
/// Parameters:
2424
/// Object p0: the conflicting key
2525
/// Object p1: the key that it conflicts with
26-
static const TransformSetErrorTemplate<
26+
static const DiagnosticWithArguments<
2727
LocatableDiagnostic Function({required Object p0, required Object p1})
2828
>
2929
conflictingKey = TransformSetErrorTemplate(
@@ -35,7 +35,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
3535
);
3636

3737
/// No parameters.
38-
static const TransformSetErrorWithoutArguments expectedPrimary =
38+
static const DiagnosticWithoutArguments expectedPrimary =
3939
TransformSetErrorWithoutArguments(
4040
name: 'expected_primary',
4141
problemMessage: "Expected either an identifier or a string literal.",
@@ -46,7 +46,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
4646
/// Parameters:
4747
/// Object p0: the old kind
4848
/// Object p1: the new kind
49-
static const TransformSetErrorTemplate<
49+
static const DiagnosticWithArguments<
5050
LocatableDiagnostic Function({required Object p0, required Object p1})
5151
>
5252
incompatibleElementKind = TransformSetErrorTemplate(
@@ -61,7 +61,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
6161
/// Parameters:
6262
/// Object p0: the change kind that is invalid
6363
/// Object p1: the element kind for the transform
64-
static const TransformSetErrorTemplate<
64+
static const DiagnosticWithArguments<
6565
LocatableDiagnostic Function({required Object p0, required Object p1})
6666
>
6767
invalidChangeForKind = TransformSetErrorTemplate(
@@ -75,7 +75,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
7575

7676
/// Parameters:
7777
/// Object p0: the character that is invalid
78-
static const TransformSetErrorTemplate<
78+
static const DiagnosticWithArguments<
7979
LocatableDiagnostic Function({required Object p0})
8080
>
8181
invalidCharacter = TransformSetErrorTemplate(
@@ -88,7 +88,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
8888

8989
/// Parameters:
9090
/// Object p0: the actual type of the key
91-
static const TransformSetErrorTemplate<
91+
static const DiagnosticWithArguments<
9292
LocatableDiagnostic Function({required Object p0})
9393
>
9494
invalidKey = TransformSetErrorTemplate(
@@ -101,7 +101,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
101101

102102
/// Parameters:
103103
/// Object p0: the list of valid parameter styles
104-
static const TransformSetErrorTemplate<
104+
static const DiagnosticWithArguments<
105105
LocatableDiagnostic Function({required Object p0})
106106
>
107107
invalidParameterStyle = TransformSetErrorTemplate(
@@ -113,7 +113,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
113113
);
114114

115115
/// No parameters.
116-
static const TransformSetErrorWithoutArguments
116+
static const DiagnosticWithoutArguments
117117
invalidRequiredIf = TransformSetErrorWithoutArguments(
118118
name: 'invalid_required_if',
119119
problemMessage:
@@ -126,7 +126,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
126126
/// Object p0: the key with which the value is associated
127127
/// Object p1: the expected type of the value
128128
/// Object p2: the actual type of the value
129-
static const TransformSetErrorTemplate<
129+
static const DiagnosticWithArguments<
130130
LocatableDiagnostic Function({
131131
required Object p0,
132132
required Object p1,
@@ -149,7 +149,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
149149
/// Parameters:
150150
/// Object p0: the key with which the value is associated
151151
/// Object p1: the allowed values as a comma-separated list
152-
static const TransformSetErrorTemplate<
152+
static const DiagnosticWithArguments<
153153
LocatableDiagnostic Function({required Object p0, required Object p1})
154154
>
155155
invalidValueOneOf = TransformSetErrorTemplate(
@@ -162,7 +162,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
162162

163163
/// Parameters:
164164
/// Object p0: the missing key
165-
static const TransformSetErrorTemplate<
165+
static const DiagnosticWithArguments<
166166
LocatableDiagnostic Function({required Object p0})
167167
>
168168
missingKey = TransformSetErrorTemplate(
@@ -175,7 +175,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
175175

176176
/// Parameters:
177177
/// Object p0: the list of valid keys
178-
static const TransformSetErrorTemplate<
178+
static const DiagnosticWithArguments<
179179
LocatableDiagnostic Function({required Object p0})
180180
>
181181
missingOneOfMultipleKeys = TransformSetErrorTemplate(
@@ -187,7 +187,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
187187
);
188188

189189
/// No parameters.
190-
static const TransformSetErrorWithoutArguments missingTemplateEnd =
190+
static const DiagnosticWithoutArguments missingTemplateEnd =
191191
TransformSetErrorWithoutArguments(
192192
name: 'missing_template_end',
193193
problemMessage: "Missing the end brace for the template.",
@@ -197,7 +197,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
197197

198198
/// Parameters:
199199
/// Object p0: a description of the expected kinds of tokens
200-
static const TransformSetErrorTemplate<
200+
static const DiagnosticWithArguments<
201201
LocatableDiagnostic Function({required Object p0})
202202
>
203203
missingToken = TransformSetErrorTemplate(
@@ -209,7 +209,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
209209
);
210210

211211
/// No parameters.
212-
static const TransformSetErrorWithoutArguments missingUri =
212+
static const DiagnosticWithoutArguments missingUri =
213213
TransformSetErrorWithoutArguments(
214214
name: 'missing_uri',
215215
problemMessage: "At least one URI must be provided.",
@@ -219,7 +219,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
219219

220220
/// Parameters:
221221
/// Object p0: the missing key
222-
static const TransformSetErrorTemplate<
222+
static const DiagnosticWithArguments<
223223
LocatableDiagnostic Function({required Object p0})
224224
>
225225
undefinedVariable = TransformSetErrorTemplate(
@@ -232,7 +232,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
232232

233233
/// Parameters:
234234
/// Object p0: the token that was unexpectedly found
235-
static const TransformSetErrorTemplate<
235+
static const DiagnosticWithArguments<
236236
LocatableDiagnostic Function({required Object p0})
237237
>
238238
unexpectedTransformSetToken = TransformSetErrorTemplate(
@@ -245,7 +245,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
245245

246246
/// Parameters:
247247
/// Object p0: a description of the expected kind of token
248-
static const TransformSetErrorTemplate<
248+
static const DiagnosticWithArguments<
249249
LocatableDiagnostic Function({required Object p0})
250250
>
251251
unknownAccessor = TransformSetErrorTemplate(
@@ -258,7 +258,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
258258

259259
/// Parameters:
260260
/// Object p0: the unsupported key
261-
static const TransformSetErrorTemplate<
261+
static const DiagnosticWithArguments<
262262
LocatableDiagnostic Function({required Object p0})
263263
>
264264
unsupportedKey = TransformSetErrorTemplate(
@@ -270,7 +270,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
270270
);
271271

272272
/// No parameters.
273-
static const TransformSetErrorWithoutArguments unsupportedStatic =
273+
static const DiagnosticWithoutArguments unsupportedStatic =
274274
TransformSetErrorWithoutArguments(
275275
name: 'unsupported_static',
276276
problemMessage:
@@ -281,7 +281,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
281281
);
282282

283283
/// No parameters.
284-
static const TransformSetErrorWithoutArguments unsupportedVersion =
284+
static const DiagnosticWithoutArguments unsupportedVersion =
285285
TransformSetErrorWithoutArguments(
286286
name: 'unsupported_version',
287287
problemMessage: "Only version '1' is supported at this time.",
@@ -292,7 +292,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
292292
/// Parameters:
293293
/// Object p0: a description of the expected kind of token
294294
/// Object p1: a description of the actual kind of token
295-
static const TransformSetErrorTemplate<
295+
static const DiagnosticWithArguments<
296296
LocatableDiagnostic Function({required Object p0, required Object p1})
297297
>
298298
wrongToken = TransformSetErrorTemplate(
@@ -305,7 +305,7 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
305305

306306
/// Parameters:
307307
/// Object p0: the message produced by the YAML parser
308-
static const TransformSetErrorTemplate<
308+
static const DiagnosticWithArguments<
309309
LocatableDiagnostic Function({required Object p0})
310310
>
311311
yamlSyntaxError = TransformSetErrorTemplate(
@@ -465,7 +465,9 @@ class TransformSetErrorCode extends DiagnosticCodeWithExpectedTypes {
465465
}
466466

467467
final class TransformSetErrorTemplate<T extends Function>
468-
extends TransformSetErrorCode {
468+
extends TransformSetErrorCode
469+
implements DiagnosticWithArguments<T> {
470+
@override
469471
final T withArguments;
470472

471473
/// Initialize a newly created error code to have the given [name].

0 commit comments

Comments
 (0)