Update more analyzer error codes to be generated from messages.yaml
Change-Id: I1d8a0db791309ac3551fc1079f91807e6e98dcb2
Reviewed-on: https://dart-review.googlesource.com/75603
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
diff --git a/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart b/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
index b75e8d1..45a79c0 100644
--- a/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
+++ b/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
@@ -449,10 +449,7 @@
correction:
"Try using a generic function type (returnType 'Function(' parameters ')').");
- static const ParserErrorCode INVALID_HEX_ESCAPE = const ParserErrorCode(
- 'INVALID_HEX_ESCAPE',
- "An escape sequence starting with '\\x' "
- "must be followed by 2 hexadecimal digits.");
+ static const ParserErrorCode INVALID_HEX_ESCAPE = _INVALID_HEX_ESCAPE;
static const ParserErrorCode INVALID_LITERAL_IN_CONFIGURATION =
const ParserErrorCode('INVALID_LITERAL_IN_CONFIGURATION',
@@ -463,8 +460,7 @@
* Parameters:
* 0: the operator that is invalid
*/
- static const ParserErrorCode INVALID_OPERATOR = const ParserErrorCode(
- 'INVALID_OPERATOR', "The string '{0}' isn't a user-definable operator.");
+ static const ParserErrorCode INVALID_OPERATOR = _INVALID_OPERATOR;
/**
* Parameters:
@@ -484,16 +480,10 @@
"The modifier 'sync' isn't allowed for an expression function body.",
correction: "Try converting the body to a block.");
- static const ParserErrorCode INVALID_UNICODE_ESCAPE = const ParserErrorCode(
- 'INVALID_UNICODE_ESCAPE',
- "An escape sequence starting with '\\u' must be followed by 4 "
- "hexadecimal digits or from 1 to 6 digits between '{' and '}'.");
+ static const ParserErrorCode INVALID_UNICODE_ESCAPE = _INVALID_UNICODE_ESCAPE;
static const ParserErrorCode LIBRARY_DIRECTIVE_NOT_FIRST =
- const ParserErrorCode('LIBRARY_DIRECTIVE_NOT_FIRST',
- "The library directive must appear before all other directives.",
- correction:
- "Try moving the library directive before any other directives.");
+ _LIBRARY_DIRECTIVE_NOT_FIRST;
static const ParserErrorCode LOCAL_FUNCTION_DECLARATION_MODIFIER =
const ParserErrorCode('LOCAL_FUNCTION_DECLARATION_MODIFIER',
@@ -501,14 +491,10 @@
correction: "Try removing the modifier.");
static const ParserErrorCode MISSING_ASSIGNABLE_SELECTOR =
- const ParserErrorCode('MISSING_ASSIGNABLE_SELECTOR',
- "Missing selector such as '.<identifier>' or '[0]'.",
- correction: "Try adding a selector.");
+ _MISSING_ASSIGNABLE_SELECTOR;
static const ParserErrorCode MISSING_ASSIGNMENT_IN_INITIALIZER =
- const ParserErrorCode('MISSING_ASSIGNMENT_IN_INITIALIZER',
- "Expected an assignment after the field name.",
- correction: "Try adding an assignment to initialize the field.");
+ _MISSING_ASSIGNMENT_IN_INITIALIZER;
static const ParserErrorCode MISSING_CATCH_OR_FINALLY = const ParserErrorCode(
'MISSING_CATCH_OR_FINALLY',
@@ -527,11 +513,8 @@
'MISSING_CLOSING_PARENTHESIS', "The closing parenthesis is missing.",
correction: "Try adding the closing parenthesis.");
- static const ParserErrorCode MISSING_CONST_FINAL_VAR_OR_TYPE = const ParserErrorCode(
- 'MISSING_CONST_FINAL_VAR_OR_TYPE',
- "Variables must be declared using the keywords 'const', 'final', 'var' or a type name.",
- correction:
- "Try adding the name of the type of the variable or the keyword 'var'.");
+ static const ParserErrorCode MISSING_CONST_FINAL_VAR_OR_TYPE =
+ _MISSING_CONST_FINAL_VAR_OR_TYPE;
static const ParserErrorCode MISSING_ENUM_BODY = const ParserErrorCode(
'MISSING_ENUM_BODY',
@@ -545,9 +528,7 @@
"remove the assignment operator.");
static const ParserErrorCode MISSING_EXPRESSION_IN_THROW =
- const ParserErrorCode(
- 'MISSING_EXPRESSION_IN_THROW', "Missing expression after 'throw'.",
- correction: "Try using 'rethrow' to throw the caught exception.");
+ _MISSING_EXPRESSION_IN_THROW;
static const ParserErrorCode MISSING_FUNCTION_BODY = const ParserErrorCode(
'MISSING_FUNCTION_BODY', "A function body must be provided.",
@@ -571,13 +552,10 @@
static const ParserErrorCode MISSING_IDENTIFIER =
const ParserErrorCode('MISSING_IDENTIFIER', "Expected an identifier.");
- static const ParserErrorCode MISSING_INITIALIZER =
- const ParserErrorCode('MISSING_INITIALIZER', "Expected an initializer.");
+ static const ParserErrorCode MISSING_INITIALIZER = _MISSING_INITIALIZER;
- static const ParserErrorCode MISSING_KEYWORD_OPERATOR = const ParserErrorCode(
- 'MISSING_KEYWORD_OPERATOR',
- "Operator declarations must be preceeded by the keyword 'operator'.",
- correction: "Try adding the keyword 'operator'.");
+ static const ParserErrorCode MISSING_KEYWORD_OPERATOR =
+ _MISSING_KEYWORD_OPERATOR;
static const ParserErrorCode MISSING_METHOD_PARAMETERS =
const ParserErrorCode('MISSING_METHOD_PARAMETERS',
diff --git a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
index b2a85e1..ad89d34 100644
--- a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
+++ b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
@@ -38,6 +38,16 @@
_MULTIPLE_EXTENDS_CLAUSES,
_MISSING_STATEMENT,
_MISSING_PREFIX_IN_DEFERRED_IMPORT,
+ _MISSING_KEYWORD_OPERATOR,
+ _MISSING_EXPRESSION_IN_THROW,
+ _MISSING_CONST_FINAL_VAR_OR_TYPE,
+ _MISSING_ASSIGNMENT_IN_INITIALIZER,
+ _MISSING_ASSIGNABLE_SELECTOR,
+ _MISSING_INITIALIZER,
+ _LIBRARY_DIRECTIVE_NOT_FIRST,
+ _INVALID_UNICODE_ESCAPE,
+ _INVALID_OPERATOR,
+ _INVALID_HEX_ESCAPE,
];
const ParserErrorCode _CONTINUE_OUTSIDE_OF_LOOP = const ParserErrorCode(
@@ -74,6 +84,53 @@
r"The keyword 'await' isn't allowed for a normal 'for' statement.",
correction: "Try removing the keyword, or use a for-each statement.");
+const ParserErrorCode _INVALID_HEX_ESCAPE = const ParserErrorCode(
+ 'INVALID_HEX_ESCAPE',
+ r"An escape sequence starting with '\x' must be followed by 2 hexadecimal digits.");
+
+const ParserErrorCode _INVALID_OPERATOR = const ParserErrorCode(
+ 'INVALID_OPERATOR',
+ r"The string '#lexeme' isn't a user-definable operator.");
+
+const ParserErrorCode _INVALID_UNICODE_ESCAPE = const ParserErrorCode(
+ 'INVALID_UNICODE_ESCAPE',
+ r"An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'.");
+
+const ParserErrorCode _LIBRARY_DIRECTIVE_NOT_FIRST = const ParserErrorCode(
+ 'LIBRARY_DIRECTIVE_NOT_FIRST',
+ r"The library directive must appear before all other directives.",
+ correction:
+ "Try moving the library directive before any other directives.");
+
+const ParserErrorCode _MISSING_ASSIGNABLE_SELECTOR = const ParserErrorCode(
+ 'MISSING_ASSIGNABLE_SELECTOR',
+ r"Missing selector such as '.<identifier>' or '[0]'.",
+ correction: "Try adding a selector.");
+
+const ParserErrorCode _MISSING_ASSIGNMENT_IN_INITIALIZER =
+ const ParserErrorCode('MISSING_ASSIGNMENT_IN_INITIALIZER',
+ r"Expected an assignment after the field name.",
+ correction: "To initialize a field, use the syntax 'name = value'.");
+
+const ParserErrorCode _MISSING_CONST_FINAL_VAR_OR_TYPE = const ParserErrorCode(
+ 'MISSING_CONST_FINAL_VAR_OR_TYPE',
+ r"Variables must be declared using the keywords 'const', 'final', 'var' or a type name.",
+ correction:
+ "Try adding the name of the type of the variable or the keyword 'var'.");
+
+const ParserErrorCode _MISSING_EXPRESSION_IN_THROW = const ParserErrorCode(
+ 'MISSING_EXPRESSION_IN_THROW', r"Missing expression after 'throw'.",
+ correction:
+ "Add an expression after 'throw' or use 'rethrow' to throw a caught exception");
+
+const ParserErrorCode _MISSING_INITIALIZER =
+ const ParserErrorCode('MISSING_INITIALIZER', r"Expected an initializer.");
+
+const ParserErrorCode _MISSING_KEYWORD_OPERATOR = const ParserErrorCode(
+ 'MISSING_KEYWORD_OPERATOR',
+ r"Operator declarations must be preceeded by the keyword 'operator'.",
+ correction: "Try adding the keyword 'operator'.");
+
const ParserErrorCode _MISSING_PREFIX_IN_DEFERRED_IMPORT =
const ParserErrorCode('MISSING_PREFIX_IN_DEFERRED_IMPORT',
r"Deferred imports should have a prefix.",
diff --git a/pkg/analyzer/lib/src/fasta/error_converter.dart b/pkg/analyzer/lib/src/fasta/error_converter.dart
index d11fb57..eb12686 100644
--- a/pkg/analyzer/lib/src/fasta/error_converter.dart
+++ b/pkg/analyzer/lib/src/fasta/error_converter.dart
@@ -362,10 +362,6 @@
errorReporter?.reportErrorForOffset(
ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE, offset, length);
return;
- case "INVALID_HEX_ESCAPE":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.INVALID_HEX_ESCAPE, offset, length);
- return;
case "INVALID_METHOD_OVERRIDE":
errorReporter?.reportErrorForOffset(
StrongModeCode.INVALID_METHOD_OVERRIDE, offset, length);
@@ -374,10 +370,6 @@
_reportByCode(CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER, message,
offset, length);
return;
- case "INVALID_OPERATOR":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.INVALID_OPERATOR, offset, length, [lexeme()]);
- return;
case "INVALID_OPERATOR_FOR_SUPER":
_reportByCode(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, message,
offset, length);
@@ -386,22 +378,6 @@
errorReporter?.reportErrorForOffset(
StrongModeCode.INVALID_SUPER_INVOCATION, offset, length);
return;
- case "INVALID_UNICODE_ESCAPE":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.INVALID_UNICODE_ESCAPE, offset, length);
- return;
- case "LIBRARY_DIRECTIVE_NOT_FIRST":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST, offset, length);
- return;
- case "MISSING_ASSIGNABLE_SELECTOR":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, offset, length);
- return;
- case "MISSING_ASSIGNMENT_IN_INITIALIZER":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER, offset, length);
- return;
case "MISSING_CATCH_OR_FINALLY":
errorReporter?.reportErrorForOffset(
ParserErrorCode.MISSING_CATCH_OR_FINALLY, offset, length);
@@ -410,18 +386,10 @@
errorReporter?.reportErrorForOffset(
ParserErrorCode.MISSING_CLASS_BODY, offset, length);
return;
- case "MISSING_CONST_FINAL_VAR_OR_TYPE":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, offset, length);
- return;
case "MISSING_DIGIT":
errorReporter?.reportErrorForOffset(
ScannerErrorCode.MISSING_DIGIT, offset, length);
return;
- case "MISSING_EXPRESSION_IN_THROW":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_EXPRESSION_IN_THROW, offset, length);
- return;
case "MISSING_ENUM_BODY":
errorReporter?.reportErrorForOffset(
ParserErrorCode.MISSING_ENUM_BODY, offset, length);
@@ -442,14 +410,6 @@
errorReporter?.reportErrorForOffset(
ParserErrorCode.MISSING_IDENTIFIER, offset, length);
return;
- case "MISSING_INITIALIZER":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_INITIALIZER, offset, length);
- return;
- case "MISSING_KEYWORD_OPERATOR":
- errorReporter?.reportErrorForOffset(
- ParserErrorCode.MISSING_KEYWORD_OPERATOR, offset, length);
- return;
case "MISSING_METHOD_PARAMETERS":
errorReporter?.reportErrorForOffset(
ParserErrorCode.MISSING_METHOD_PARAMETERS, offset, length);
diff --git a/pkg/analyzer/tool/messages/generate.dart b/pkg/analyzer/tool/messages/generate.dart
index aa7d34c..3e99766 100644
--- a/pkg/analyzer/tool/messages/generate.dart
+++ b/pkg/analyzer/tool/messages/generate.dart
@@ -138,7 +138,7 @@
for (Map entry in translatedEntries) {
final name = nameForEntry(entry);
final errorCode = name[1];
- if (errorConverterSource.contains(errorCode)) {
+ if (errorConverterSource.contains('"$errorCode"')) {
if (converterCount == 0) {
print('');
print('The following ParserErrorCodes could be removed'
diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
index 05c25f4..03735bf 100644
--- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
+++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
@@ -2372,7 +2372,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageExpectedAnInitializer = const MessageCode(
"ExpectedAnInitializer",
- analyzerCode: "MISSING_INITIALIZER",
+ index: 36,
message: r"""Expected an initializer.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -4695,7 +4695,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageInvalidHexEscape = const MessageCode(
"InvalidHexEscape",
- analyzerCode: "INVALID_HEX_ESCAPE",
+ index: 40,
message:
r"""An escape sequence starting with '\x' must be followed by 2 hexadecimal digits.""");
@@ -4733,7 +4733,7 @@
const Code<Message Function(Token token)> codeInvalidOperator =
const Code<Message Function(Token token)>(
"InvalidOperator", templateInvalidOperator,
- analyzerCode: "INVALID_OPERATOR");
+ index: 39);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsInvalidOperator(Token token) {
@@ -4781,7 +4781,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageInvalidUnicodeEscape = const MessageCode(
"InvalidUnicodeEscape",
- analyzerCode: "INVALID_UNICODE_ESCAPE",
+ index: 38,
message:
r"""An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'.""");
@@ -4857,7 +4857,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageLibraryDirectiveNotFirst = const MessageCode(
"LibraryDirectiveNotFirst",
- analyzerCode: "LIBRARY_DIRECTIVE_NOT_FIRST",
+ index: 37,
message:
r"""The library directive must appear before all other directives.""",
tip: r"""Try moving the library directive before any other directives.""");
@@ -5019,7 +5019,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMissingAssignableSelector = const MessageCode(
"MissingAssignableSelector",
- analyzerCode: "MISSING_ASSIGNABLE_SELECTOR",
+ index: 35,
message: r"""Missing selector such as '.<identifier>' or '[0]'.""",
tip: r"""Try adding a selector.""");
@@ -5030,7 +5030,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMissingAssignmentInInitializer = const MessageCode(
"MissingAssignmentInInitializer",
- analyzerCode: "MISSING_ASSIGNMENT_IN_INITIALIZER",
+ index: 34,
message: r"""Expected an assignment after the field name.""",
tip: r"""To initialize a field, use the syntax 'name = value'.""");
@@ -5041,7 +5041,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMissingConstFinalVarOrType = const MessageCode(
"MissingConstFinalVarOrType",
- analyzerCode: "MISSING_CONST_FINAL_VAR_OR_TYPE",
+ index: 33,
message:
r"""Variables must be declared using the keywords 'const', 'final', 'var' or a type name.""",
tip:
@@ -5084,7 +5084,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMissingExpressionInThrow = const MessageCode(
"MissingExpressionInThrow",
- analyzerCode: "MISSING_EXPRESSION_IN_THROW",
+ index: 32,
message: r"""Missing expression after 'throw'.""",
tip:
r"""Add an expression after 'throw' or use 'rethrow' to throw a caught exception""");
@@ -5194,7 +5194,7 @@
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMissingOperatorKeyword = const MessageCode(
"MissingOperatorKeyword",
- analyzerCode: "MISSING_KEYWORD_OPERATOR",
+ index: 31,
message:
r"""Operator declarations must be preceeded by the keyword 'operator'.""",
tip: r"""Try adding the keyword 'operator'.""");
diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml
index 7a5d48c..5504e4b 100644
--- a/pkg/front_end/messages.yaml
+++ b/pkg/front_end/messages.yaml
@@ -385,16 +385,18 @@
analyzerCode: EXPECTED_TYPE_NAME
MissingExpressionInThrow:
+ index: 32
template: "Missing expression after 'throw'."
tip: "Add an expression after 'throw' or use 'rethrow' to throw a caught exception"
- analyzerCode: MISSING_EXPRESSION_IN_THROW
+ analyzerCode: ParserErrorCode.MISSING_EXPRESSION_IN_THROW
statement:
- "throw;"
MissingConstFinalVarOrType:
+ index: 33
template: "Variables must be declared using the keywords 'const', 'final', 'var' or a type name."
tip: "Try adding the name of the type of the variable or the keyword 'var'."
- analyzerCode: MISSING_CONST_FINAL_VAR_OR_TYPE
+ analyzerCode: ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
script:
- "class C { static f; }"
@@ -897,15 +899,17 @@
- "'\\u{110000}'"
InvalidHexEscape:
+ index: 40
template: "An escape sequence starting with '\\x' must be followed by 2 hexadecimal digits."
- analyzerCode: INVALID_HEX_ESCAPE
+ analyzerCode: ParserErrorCode.INVALID_HEX_ESCAPE
expression:
- "'\\x0'"
- "'\\x0y'"
InvalidUnicodeEscape:
+ index: 38
template: "An escape sequence starting with '\\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'."
- analyzerCode: INVALID_UNICODE_ESCAPE
+ analyzerCode: ParserErrorCode.INVALID_UNICODE_ESCAPE
expression:
- "'\\u'"
- "'\\u0F'"
@@ -1884,9 +1888,10 @@
analyzerCode: INVALID_GENERIC_FUNCTION_TYPE
LibraryDirectiveNotFirst:
+ index: 37
template: "The library directive must appear before all other directives."
tip: "Try moving the library directive before any other directives."
- analyzerCode: LIBRARY_DIRECTIVE_NOT_FIRST
+ analyzerCode: ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST
script:
- "class Foo{} library l;"
- "import 'x.dart'; library l;"
@@ -2130,15 +2135,17 @@
analyzerCode: ENUM_CONSTANT_WITH_ENUM_NAME
MissingOperatorKeyword:
+ index: 31
template: "Operator declarations must be preceeded by the keyword 'operator'."
tip: "Try adding the keyword 'operator'."
- analyzerCode: MISSING_KEYWORD_OPERATOR
+ analyzerCode: ParserErrorCode.MISSING_KEYWORD_OPERATOR
script:
- "class C { +(x) {} }"
InvalidOperator:
+ index: 39
template: "The string '#lexeme' isn't a user-definable operator."
- analyzerCode: INVALID_OPERATOR
+ analyzerCode: ParserErrorCode.INVALID_OPERATOR
script:
- "class C { void operator %=(x) {} }"
@@ -2380,15 +2387,17 @@
template: "This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor."
ExpectedAnInitializer:
+ index: 36
template: "Expected an initializer."
- analyzerCode: MISSING_INITIALIZER
+ analyzerCode: ParserErrorCode.MISSING_INITIALIZER
script:
- "class C { C() : {} }"
MissingAssignmentInInitializer:
+ index: 34
template: "Expected an assignment after the field name."
tip: "To initialize a field, use the syntax 'name = value'."
- analyzerCode: MISSING_ASSIGNMENT_IN_INITIALIZER
+ analyzerCode: ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER
script:
- "class C { C() : x(3) {} }"
@@ -2419,9 +2428,10 @@
- "main(){ f()++; }"
MissingAssignableSelector:
+ index: 35
template: "Missing selector such as '.<identifier>' or '[0]'."
tip: "Try adding a selector."
- analyzerCode: MISSING_ASSIGNABLE_SELECTOR
+ analyzerCode: ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR
script:
- "main(){ ++f(); }"