Skip to content

Commit 9a251b4

Browse files
stereotype441Commit Queue
authored andcommitted
[_fe_analyzer_shared] Code generate ScannerErrorCode class.
I suspect that the reason this wasn't previously code generated was because even though it follows the conventions of the other analyzer error code classes, and is used by the analyzer, it exists in `pkg/_fe_analyzer_shared`, since it is used by the scanner. In order for this to be code generated without creating a reverse dependency from `_fe_analyzer_shared` to `analyzer`, I had to change the code generator so that the generated files import `package:_fe_analyzer_shared/src/base/errors.dart` rather than `package:analyzer/error/error.dart`. This is a benign change so I went ahead and let it apply to all code generated by the analyzer error message code generator, even though it's only strictly necessary for code generated into the `_fe_analyzer_shared` package. Since code in `pkg/_fe_analyzer_shared` is required to use explicit `new` or `const` when constructing class instances, and since this coding convention is enforced by a custom CFE-based lints that doesn't understand `ignore:` comments, I also had to modify the code generator to insert the appropriate `const` keywords when generating the new code. To reduce churn and confusion, I added the `const` keywords only to error code classes inside `pkg/_fe_analyzer_shared`. I also had to improve the code generator so that it properly escapes `$` if it appears inside an error message. Previously, this was not a problem, because there were no code generated error messages that contained `$`. In the process of making this change, I discovered that entries for `ScannerErrorCode.UNEXPECTED_SEPARATOR_IN_NUMBER` were missing from `error_fix_status.yaml` and from the `diagnosticCodeValues` list. I've added the missing entries as part of the CL. Change-Id: Ib6e734a47e77b406059df9cfdeff9e401f22bd88 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439060 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent d8117e1 commit 9a251b4

File tree

17 files changed

+239
-138
lines changed

17 files changed

+239
-138
lines changed

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

Lines changed: 6 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../base/errors.dart';
5+
// ignore: deprecated_member_use_from_same_package
6+
import 'package:_fe_analyzer_shared/src/scanner/errors.g.dart';
7+
68
import '../messages/codes.dart';
79
import 'error_token.dart';
810
import 'token.dart' show Token, TokenType;
911
import 'token_constants.dart';
1012

13+
// ignore: deprecated_member_use_from_same_package
14+
export 'package:_fe_analyzer_shared/src/scanner/errors.g.dart';
15+
1116
/**
1217
* Translates the given error [token] into an analyzer error and reports it
1318
* using [reportError].
@@ -128,118 +133,3 @@ typedef ReportError(
128133
int offset,
129134
List<Object>? arguments,
130135
);
131-
132-
/**
133-
* The error codes used for errors detected by the scanner.
134-
*/
135-
class ScannerErrorCode extends DiagnosticCode {
136-
/**
137-
* Parameters:
138-
* 0: the token that was expected but not found
139-
*/
140-
static const ScannerErrorCode EXPECTED_TOKEN = const ScannerErrorCode(
141-
'EXPECTED_TOKEN',
142-
"Expected to find '{0}'.",
143-
);
144-
145-
/**
146-
* Parameters:
147-
* 0: the illegal character
148-
*/
149-
static const ScannerErrorCode ILLEGAL_CHARACTER = const ScannerErrorCode(
150-
'ILLEGAL_CHARACTER',
151-
"Illegal character '{0}'.",
152-
);
153-
154-
static const ScannerErrorCode MISSING_DIGIT = const ScannerErrorCode(
155-
'MISSING_DIGIT',
156-
"Decimal digit expected.",
157-
);
158-
159-
static const ScannerErrorCode MISSING_HEX_DIGIT = const ScannerErrorCode(
160-
'MISSING_HEX_DIGIT',
161-
"Hexadecimal digit expected.",
162-
);
163-
164-
static const ScannerErrorCode MISSING_IDENTIFIER = const ScannerErrorCode(
165-
'MISSING_IDENTIFIER',
166-
"Expected an identifier.",
167-
);
168-
169-
static const ScannerErrorCode MISSING_QUOTE = const ScannerErrorCode(
170-
'MISSING_QUOTE',
171-
"Expected quote (' or \").",
172-
);
173-
174-
/**
175-
* Parameters:
176-
* 0: the path of the file that cannot be read
177-
*/
178-
static const ScannerErrorCode UNABLE_GET_CONTENT = const ScannerErrorCode(
179-
'UNABLE_GET_CONTENT',
180-
"Unable to get content of '{0}'.",
181-
);
182-
183-
static const ScannerErrorCode UNEXPECTED_DOLLAR_IN_STRING =
184-
const ScannerErrorCode(
185-
'UNEXPECTED_DOLLAR_IN_STRING',
186-
"A '\$' has special meaning inside a string, and must be followed by "
187-
"an identifier or an expression in curly braces ({}).",
188-
correctionMessage: "Try adding a backslash (\\) to escape the '\$'.",
189-
);
190-
191-
static const ScannerErrorCode UNEXPECTED_SEPARATOR_IN_NUMBER =
192-
const ScannerErrorCode(
193-
'UNEXPECTED_SEPARATOR_IN_NUMBER',
194-
"Digit separators ('_') in a number literal can only be placed "
195-
"between two digits.",
196-
correctionMessage: "Try removing the '_'.",
197-
);
198-
199-
/**
200-
* Parameters:
201-
* 0: the unsupported operator
202-
*/
203-
static const ScannerErrorCode UNSUPPORTED_OPERATOR = const ScannerErrorCode(
204-
'UNSUPPORTED_OPERATOR',
205-
"The '{0}' operator is not supported.",
206-
);
207-
208-
static const ScannerErrorCode UNTERMINATED_MULTI_LINE_COMMENT =
209-
const ScannerErrorCode(
210-
'UNTERMINATED_MULTI_LINE_COMMENT',
211-
"Unterminated multi-line comment.",
212-
correctionMessage:
213-
"Try terminating the comment with '*/', or "
214-
"removing any unbalanced occurrences of '/*'"
215-
" (because comments nest in Dart).",
216-
);
217-
218-
static const ScannerErrorCode UNTERMINATED_STRING_LITERAL =
219-
const ScannerErrorCode(
220-
'UNTERMINATED_STRING_LITERAL',
221-
"Unterminated string literal.",
222-
);
223-
224-
/**
225-
* Initialize a newly created error code to have the given [name]. The message
226-
* associated with the error will be created from the given [problemMessage]
227-
* template. The correction associated with the error will be created from the
228-
* given [correctionMessage] template.
229-
*/
230-
const ScannerErrorCode(
231-
String name,
232-
String problemMessage, {
233-
super.correctionMessage,
234-
}) : super(
235-
problemMessage: problemMessage,
236-
name: name,
237-
uniqueName: 'ScannerErrorCode.$name',
238-
);
239-
240-
@override
241-
DiagnosticSeverity get severity => DiagnosticSeverity.ERROR;
242-
243-
@override
244-
DiagnosticType get type => DiagnosticType.SYNTACTIC_ERROR;
245-
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// THIS FILE IS GENERATED. DO NOT EDIT.
6+
//
7+
// Instead modify 'pkg/analyzer/messages.yaml' and run
8+
// 'dart run pkg/analyzer/tool/messages/generate.dart' to update.
9+
10+
// While transitioning `HintCodes` to `WarningCodes`, we refer to deprecated
11+
// codes here.
12+
// ignore_for_file: deprecated_member_use_from_same_package
13+
//
14+
// Generated comments don't quite align with flutter style.
15+
// ignore_for_file: flutter_style_todos
16+
17+
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18+
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19+
@Deprecated(
20+
// This library is deprecated to prevent it from being accidentally imported
21+
// It should only be imported by the corresponding non-code-generated library
22+
// (which suppresses the deprecation warning using an "ignore" comment).
23+
'Use package:_fe_analyzer_shared/src/scanner/errors.dart instead',
24+
)
25+
library;
26+
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
28+
29+
class ScannerErrorCode extends DiagnosticCode {
30+
/// Parameters:
31+
/// 0: the token that was expected but not found
32+
static const ScannerErrorCode EXPECTED_TOKEN = const ScannerErrorCode(
33+
'EXPECTED_TOKEN',
34+
"Expected to find '{0}'.",
35+
);
36+
37+
/// Parameters:
38+
/// 0: the illegal character
39+
static const ScannerErrorCode ILLEGAL_CHARACTER = const ScannerErrorCode(
40+
'ILLEGAL_CHARACTER',
41+
"Illegal character '{0}'.",
42+
);
43+
44+
static const ScannerErrorCode MISSING_DIGIT = const ScannerErrorCode(
45+
'MISSING_DIGIT',
46+
"Decimal digit expected.",
47+
);
48+
49+
static const ScannerErrorCode MISSING_HEX_DIGIT = const ScannerErrorCode(
50+
'MISSING_HEX_DIGIT',
51+
"Hexadecimal digit expected.",
52+
);
53+
54+
static const ScannerErrorCode MISSING_IDENTIFIER = const ScannerErrorCode(
55+
'MISSING_IDENTIFIER',
56+
"Expected an identifier.",
57+
);
58+
59+
static const ScannerErrorCode MISSING_QUOTE = const ScannerErrorCode(
60+
'MISSING_QUOTE',
61+
"Expected quote (' or \").",
62+
);
63+
64+
/// Parameters:
65+
/// 0: the path of the file that cannot be read
66+
static const ScannerErrorCode UNABLE_GET_CONTENT = const ScannerErrorCode(
67+
'UNABLE_GET_CONTENT',
68+
"Unable to get content of '{0}'.",
69+
);
70+
71+
static const ScannerErrorCode
72+
UNEXPECTED_DOLLAR_IN_STRING = const ScannerErrorCode(
73+
'UNEXPECTED_DOLLAR_IN_STRING',
74+
"A '\$' has special meaning inside a string, and must be followed by an "
75+
"identifier or an expression in curly braces ({}).",
76+
correctionMessage: "Try adding a backslash (\\) to escape the '\$'.",
77+
);
78+
79+
static const ScannerErrorCode
80+
UNEXPECTED_SEPARATOR_IN_NUMBER = const ScannerErrorCode(
81+
'UNEXPECTED_SEPARATOR_IN_NUMBER',
82+
"Digit separators ('_') in a number literal can only be placed between two "
83+
"digits.",
84+
correctionMessage: "Try removing the '_'.",
85+
);
86+
87+
/// Parameters:
88+
/// 0: the unsupported operator
89+
static const ScannerErrorCode UNSUPPORTED_OPERATOR = const ScannerErrorCode(
90+
'UNSUPPORTED_OPERATOR',
91+
"The '{0}' operator is not supported.",
92+
);
93+
94+
static const ScannerErrorCode UNTERMINATED_MULTI_LINE_COMMENT =
95+
const ScannerErrorCode(
96+
'UNTERMINATED_MULTI_LINE_COMMENT',
97+
"Unterminated multi-line comment.",
98+
correctionMessage:
99+
"Try terminating the comment with '*/', or removing any unbalanced "
100+
"occurrences of '/*' (because comments nest in Dart).",
101+
);
102+
103+
static const ScannerErrorCode UNTERMINATED_STRING_LITERAL =
104+
const ScannerErrorCode(
105+
'UNTERMINATED_STRING_LITERAL',
106+
"Unterminated string literal.",
107+
);
108+
109+
/// Initialize a newly created error code to have the given [name].
110+
const ScannerErrorCode(
111+
String name,
112+
String problemMessage, {
113+
super.correctionMessage,
114+
super.hasPublishedDocs = false,
115+
super.isUnresolvedIdentifier = false,
116+
String? uniqueName,
117+
}) : super(
118+
name: name,
119+
problemMessage: problemMessage,
120+
uniqueName: 'ScannerErrorCode.${uniqueName ?? name}',
121+
);
122+
123+
@override
124+
DiagnosticSeverity get severity => DiagnosticType.SYNTACTIC_ERROR.severity;
125+
126+
@override
127+
DiagnosticType get type => DiagnosticType.SYNTACTIC_ERROR;
128+
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,6 +3407,8 @@ ScannerErrorCode.UNABLE_GET_CONTENT:
34073407
status: noFix
34083408
ScannerErrorCode.UNEXPECTED_DOLLAR_IN_STRING:
34093409
status: noFix
3410+
ScannerErrorCode.UNEXPECTED_SEPARATOR_IN_NUMBER:
3411+
status: hasFix
34103412
ScannerErrorCode.UNSUPPORTED_OPERATOR:
34113413
status: noFix
34123414
ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT:

pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
class AnalysisOptionsErrorCode extends DiagnosticCode {
3030
/// An error code indicating that there is a syntactic error in the included

pkg/analyzer/lib/src/dart/error/ffi_code.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
class FfiCode extends DiagnosticCode {
3030
/// No parameters.

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
class HintCode extends DiagnosticCode {
3030
/// No parameters.

pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
final fastaAnalyzerErrorCodes = <DiagnosticCode?>[
3030
null,

pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ const List<DiagnosticCode> diagnosticCodeValues = [
958958
ScannerErrorCode.MISSING_QUOTE,
959959
ScannerErrorCode.UNABLE_GET_CONTENT,
960960
ScannerErrorCode.UNEXPECTED_DOLLAR_IN_STRING,
961+
ScannerErrorCode.UNEXPECTED_SEPARATOR_IN_NUMBER,
961962
ScannerErrorCode.UNSUPPORTED_OPERATOR,
962963
ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT,
963964
ScannerErrorCode.UNTERMINATED_STRING_LITERAL,

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
class CompileTimeErrorCode extends DiagnosticCode {
3030
/// No parameters.

pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
library;
2626

27-
import "package:analyzer/error/error.dart";
27+
import "package:_fe_analyzer_shared/src/base/errors.dart";
2828

2929
class ManifestWarningCode extends DiagnosticCode {
3030
/// A code indicating that the camera permissions is not supported on Chrome

0 commit comments

Comments
 (0)