@@ -19,61 +19,77 @@ part of "package:_fe_analyzer_shared/src/scanner/errors.dart";
19
19
class ScannerErrorCode extends DiagnosticCode {
20
20
/// Parameters:
21
21
/// String p0: the token that was expected but not found
22
- static const ScannerErrorCode expectedToken = const ScannerErrorCode (
22
+ static const ScannerErrorTemplate <
23
+ LocatableDiagnostic Function ({required String p0})
24
+ >
25
+ expectedToken = const ScannerErrorTemplate (
23
26
'EXPECTED_TOKEN' ,
24
27
"Expected to find '{0}'." ,
28
+ withArguments: _withArgumentsExpectedToken,
25
29
);
26
30
27
31
/// Parameters:
28
32
/// Object p0: the illegal character
29
- static const ScannerErrorCode illegalCharacter = const ScannerErrorCode (
33
+ static const ScannerErrorTemplate <
34
+ LocatableDiagnostic Function ({required Object p0})
35
+ >
36
+ illegalCharacter = const ScannerErrorTemplate (
30
37
'ILLEGAL_CHARACTER' ,
31
38
"Illegal character '{0}'." ,
39
+ withArguments: _withArgumentsIllegalCharacter,
32
40
);
33
41
34
42
/// No parameters.
35
- static const ScannerErrorCode missingDigit = const ScannerErrorCode (
36
- 'MISSING_DIGIT' ,
37
- "Decimal digit expected." ,
38
- );
43
+ static const ScannerErrorWithoutArguments missingDigit =
44
+ const ScannerErrorWithoutArguments (
45
+ 'MISSING_DIGIT' ,
46
+ "Decimal digit expected." ,
47
+ );
39
48
40
49
/// No parameters.
41
- static const ScannerErrorCode missingHexDigit = const ScannerErrorCode (
42
- 'MISSING_HEX_DIGIT' ,
43
- "Hexadecimal digit expected." ,
44
- );
50
+ static const ScannerErrorWithoutArguments missingHexDigit =
51
+ const ScannerErrorWithoutArguments (
52
+ 'MISSING_HEX_DIGIT' ,
53
+ "Hexadecimal digit expected." ,
54
+ );
45
55
46
56
/// No parameters.
47
- static const ScannerErrorCode missingIdentifier = const ScannerErrorCode (
48
- 'MISSING_IDENTIFIER' ,
49
- "Expected an identifier." ,
50
- );
57
+ static const ScannerErrorWithoutArguments missingIdentifier =
58
+ const ScannerErrorWithoutArguments (
59
+ 'MISSING_IDENTIFIER' ,
60
+ "Expected an identifier." ,
61
+ );
51
62
52
63
/// No parameters.
53
- static const ScannerErrorCode missingQuote = const ScannerErrorCode (
54
- 'MISSING_QUOTE' ,
55
- "Expected quote (' or \" )." ,
56
- );
64
+ static const ScannerErrorWithoutArguments missingQuote =
65
+ const ScannerErrorWithoutArguments (
66
+ 'MISSING_QUOTE' ,
67
+ "Expected quote (' or \" )." ,
68
+ );
57
69
58
70
/// Parameters:
59
71
/// Object p0: the path of the file that cannot be read
60
- static const ScannerErrorCode unableGetContent = const ScannerErrorCode (
72
+ static const ScannerErrorTemplate <
73
+ LocatableDiagnostic Function ({required Object p0})
74
+ >
75
+ unableGetContent = const ScannerErrorTemplate (
61
76
'UNABLE_GET_CONTENT' ,
62
77
"Unable to get content of '{0}'." ,
78
+ withArguments: _withArgumentsUnableGetContent,
63
79
);
64
80
65
81
/// No parameters.
66
- static const ScannerErrorCode
67
- unexpectedDollarInString = const ScannerErrorCode (
82
+ static const ScannerErrorWithoutArguments
83
+ unexpectedDollarInString = const ScannerErrorWithoutArguments (
68
84
'UNEXPECTED_DOLLAR_IN_STRING' ,
69
85
"A '\$ ' has special meaning inside a string, and must be followed by an "
70
86
"identifier or an expression in curly braces ({})." ,
71
87
correctionMessage: "Try adding a backslash (\\ ) to escape the '\$ '." ,
72
88
);
73
89
74
90
/// No parameters.
75
- static const ScannerErrorCode
76
- unexpectedSeparatorInNumber = const ScannerErrorCode (
91
+ static const ScannerErrorWithoutArguments
92
+ unexpectedSeparatorInNumber = const ScannerErrorWithoutArguments (
77
93
'UNEXPECTED_SEPARATOR_IN_NUMBER' ,
78
94
"Digit separators ('_') in a number literal can only be placed between two "
79
95
"digits." ,
@@ -82,14 +98,18 @@ class ScannerErrorCode extends DiagnosticCode {
82
98
83
99
/// Parameters:
84
100
/// String p0: the unsupported operator
85
- static const ScannerErrorCode unsupportedOperator = const ScannerErrorCode (
101
+ static const ScannerErrorTemplate <
102
+ LocatableDiagnostic Function ({required String p0})
103
+ >
104
+ unsupportedOperator = const ScannerErrorTemplate (
86
105
'UNSUPPORTED_OPERATOR' ,
87
106
"The '{0}' operator is not supported." ,
107
+ withArguments: _withArgumentsUnsupportedOperator,
88
108
);
89
109
90
110
/// No parameters.
91
- static const ScannerErrorCode unterminatedMultiLineComment =
92
- const ScannerErrorCode (
111
+ static const ScannerErrorWithoutArguments unterminatedMultiLineComment =
112
+ const ScannerErrorWithoutArguments (
93
113
'UNTERMINATED_MULTI_LINE_COMMENT' ,
94
114
"Unterminated multi-line comment." ,
95
115
correctionMessage:
@@ -98,8 +118,8 @@ class ScannerErrorCode extends DiagnosticCode {
98
118
);
99
119
100
120
/// No parameters.
101
- static const ScannerErrorCode unterminatedStringLiteral =
102
- const ScannerErrorCode (
121
+ static const ScannerErrorWithoutArguments unterminatedStringLiteral =
122
+ const ScannerErrorWithoutArguments (
103
123
'UNTERMINATED_STRING_LITERAL' ,
104
124
"Unterminated string literal." ,
105
125
);
@@ -123,4 +143,54 @@ class ScannerErrorCode extends DiagnosticCode {
123
143
124
144
@override
125
145
DiagnosticType get type => DiagnosticType .SYNTACTIC_ERROR ;
146
+
147
+ static LocatableDiagnostic _withArgumentsExpectedToken ({required String p0}) {
148
+ return new LocatableDiagnosticImpl (expectedToken, [p0]);
149
+ }
150
+
151
+ static LocatableDiagnostic _withArgumentsIllegalCharacter ({
152
+ required Object p0,
153
+ }) {
154
+ return new LocatableDiagnosticImpl (illegalCharacter, [p0]);
155
+ }
156
+
157
+ static LocatableDiagnostic _withArgumentsUnableGetContent ({
158
+ required Object p0,
159
+ }) {
160
+ return new LocatableDiagnosticImpl (unableGetContent, [p0]);
161
+ }
162
+
163
+ static LocatableDiagnostic _withArgumentsUnsupportedOperator ({
164
+ required String p0,
165
+ }) {
166
+ return new LocatableDiagnosticImpl (unsupportedOperator, [p0]);
167
+ }
168
+ }
169
+
170
+ final class ScannerErrorTemplate <T extends Function > extends ScannerErrorCode {
171
+ final T withArguments;
172
+
173
+ /// Initialize a newly created error code to have the given [name] .
174
+ const ScannerErrorTemplate (
175
+ super .name,
176
+ super .problemMessage, {
177
+ super .correctionMessage,
178
+ super .hasPublishedDocs = false ,
179
+ super .isUnresolvedIdentifier = false ,
180
+ super .uniqueName,
181
+ required this .withArguments,
182
+ });
183
+ }
184
+
185
+ final class ScannerErrorWithoutArguments extends ScannerErrorCode
186
+ with DiagnosticWithoutArguments {
187
+ /// Initialize a newly created error code to have the given [name] .
188
+ const ScannerErrorWithoutArguments (
189
+ super .name,
190
+ super .problemMessage, {
191
+ super .correctionMessage,
192
+ super .hasPublishedDocs = false ,
193
+ super .isUnresolvedIdentifier = false ,
194
+ super .uniqueName,
195
+ });
126
196
}
0 commit comments