@@ -19,61 +19,77 @@ part of "package:_fe_analyzer_shared/src/scanner/errors.dart";
1919class ScannerErrorCode extends DiagnosticCode {
2020 /// Parameters:
2121 /// 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 (
2326 'EXPECTED_TOKEN' ,
2427 "Expected to find '{0}'." ,
28+ withArguments: _withArgumentsExpectedToken,
2529 );
2630
2731 /// Parameters:
2832 /// 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 (
3037 'ILLEGAL_CHARACTER' ,
3138 "Illegal character '{0}'." ,
39+ withArguments: _withArgumentsIllegalCharacter,
3240 );
3341
3442 /// 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+ );
3948
4049 /// 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+ );
4555
4656 /// 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+ );
5162
5263 /// 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+ );
5769
5870 /// Parameters:
5971 /// 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 (
6176 'UNABLE_GET_CONTENT' ,
6277 "Unable to get content of '{0}'." ,
78+ withArguments: _withArgumentsUnableGetContent,
6379 );
6480
6581 /// No parameters.
66- static const ScannerErrorCode
67- unexpectedDollarInString = const ScannerErrorCode (
82+ static const ScannerErrorWithoutArguments
83+ unexpectedDollarInString = const ScannerErrorWithoutArguments (
6884 'UNEXPECTED_DOLLAR_IN_STRING' ,
6985 "A '\$ ' has special meaning inside a string, and must be followed by an "
7086 "identifier or an expression in curly braces ({})." ,
7187 correctionMessage: "Try adding a backslash (\\ ) to escape the '\$ '." ,
7288 );
7389
7490 /// No parameters.
75- static const ScannerErrorCode
76- unexpectedSeparatorInNumber = const ScannerErrorCode (
91+ static const ScannerErrorWithoutArguments
92+ unexpectedSeparatorInNumber = const ScannerErrorWithoutArguments (
7793 'UNEXPECTED_SEPARATOR_IN_NUMBER' ,
7894 "Digit separators ('_') in a number literal can only be placed between two "
7995 "digits." ,
@@ -82,14 +98,18 @@ class ScannerErrorCode extends DiagnosticCode {
8298
8399 /// Parameters:
84100 /// 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 (
86105 'UNSUPPORTED_OPERATOR' ,
87106 "The '{0}' operator is not supported." ,
107+ withArguments: _withArgumentsUnsupportedOperator,
88108 );
89109
90110 /// No parameters.
91- static const ScannerErrorCode unterminatedMultiLineComment =
92- const ScannerErrorCode (
111+ static const ScannerErrorWithoutArguments unterminatedMultiLineComment =
112+ const ScannerErrorWithoutArguments (
93113 'UNTERMINATED_MULTI_LINE_COMMENT' ,
94114 "Unterminated multi-line comment." ,
95115 correctionMessage:
@@ -98,8 +118,8 @@ class ScannerErrorCode extends DiagnosticCode {
98118 );
99119
100120 /// No parameters.
101- static const ScannerErrorCode unterminatedStringLiteral =
102- const ScannerErrorCode (
121+ static const ScannerErrorWithoutArguments unterminatedStringLiteral =
122+ const ScannerErrorWithoutArguments (
103123 'UNTERMINATED_STRING_LITERAL' ,
104124 "Unterminated string literal." ,
105125 );
@@ -123,4 +143,54 @@ class ScannerErrorCode extends DiagnosticCode {
123143
124144 @override
125145 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+ });
126196}
0 commit comments