Skip to content

Commit 07c248c

Browse files
stereotype441Commit Queue
authored andcommitted
[front end] Use code... instead of message....
This is part of a series of CLs that will standardize CFE error reporting to always use `codeFoo.withArguments(...)` when reporting errors that take arguments and `codeFoo` when reporting errors that don't take arguments, rather than `templateFoo.withArguments(...)` when reporting errors that take arguments and `messageFoo` when reporting errors that don't take arguments. This change will have two advantages: - It will lend greater consistency to the CFE codebase, by allowing the same `code...` objects to be used both to name error codes (e.g., in test expectations) and to report errors. This will allow everything associated with a certain error code to be found using a single invocation of "Find References" in the editor, rather than having to search separately for uses of the code and the message or template. - It should hopefully make the experience of writing code that reports errors more pleasant, since it will no longer be necessary to look up an error to see whether it takes arguments before using it; instead, the developer will be able to type the name of the message `code...` declaration, and then use autocompletion to see whether `.withArguments(...)` is required. In this CL, references to the `message...` declarations that define errors are changed to the equivalent `code...` declarations. There is no functional change, since these declarations denote the same constant object. In a follow-up CL, the `message...` declarations will be removed. Tested: standard trybots Change-Id: I44d4b3cffb768b908d4341a7851f270db6caa87b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443183 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Jackson Gardner <[email protected]> Reviewed-by: Mayank Patke <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 9157814 commit 07c248c

File tree

67 files changed

+931
-1035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+931
-1035
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/block_kind.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ class BlockKind {
1919

2020
static const BlockKind catchClause = const BlockKind._(
2121
'catch clause',
22-
message: codes.messageExpectedCatchClauseBody,
22+
message: codes.codeExpectedCatchClauseBody,
2323
);
2424
static const BlockKind classDeclaration = const BlockKind._(
2525
'class declaration',
26-
message: codes.messageExpectedClassBody,
26+
message: codes.codeExpectedClassBody,
2727
);
2828
static const BlockKind enumDeclaration = const BlockKind._(
2929
'enum declaration',
3030
template: codes.codeExpectedEnumBody,
3131
);
3232
static const BlockKind extensionDeclaration = const BlockKind._(
3333
'extension declaration',
34-
message: codes.messageExpectedExtensionBody,
34+
message: codes.codeExpectedExtensionBody,
3535
);
3636
static const BlockKind extensionTypeDeclaration = const BlockKind._(
3737
'extension type declaration',
38-
message: codes.messageExpectedExtensionTypeBody,
38+
message: codes.codeExpectedExtensionTypeBody,
3939
);
4040
static const BlockKind finallyClause = const BlockKind._(
4141
'finally clause',
42-
message: codes.messageExpectedFinallyClauseBody,
42+
message: codes.codeExpectedFinallyClauseBody,
4343
);
4444
static const BlockKind functionBody = const BlockKind._(
4545
'function body',
@@ -48,19 +48,19 @@ class BlockKind {
4848
static const BlockKind invalid = const BlockKind._('invalid');
4949
static const BlockKind mixinDeclaration = const BlockKind._(
5050
'mixin declaration',
51-
message: codes.messageExpectedMixinBody,
51+
message: codes.codeExpectedMixinBody,
5252
);
5353
static const BlockKind statement = const BlockKind._('statement');
5454
static const BlockKind switchExpression = const BlockKind._(
5555
'switch expression',
56-
message: codes.messageExpectedSwitchExpressionBody,
56+
message: codes.codeExpectedSwitchExpressionBody,
5757
);
5858
static const BlockKind switchStatement = const BlockKind._(
5959
'switch statement',
60-
message: codes.messageExpectedSwitchStatementBody,
60+
message: codes.codeExpectedSwitchStatementBody,
6161
);
6262
static const BlockKind tryStatement = const BlockKind._(
6363
'try statement',
64-
message: codes.messageExpectedTryStatementBody,
64+
message: codes.codeExpectedTryStatementBody,
6565
);
6666
}

pkg/_fe_analyzer_shared/lib/src/parser/directive_context.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class DirectiveContext {
3838
case DirectiveState.ImportAndExport:
3939
state = DirectiveState.ImportAndExport;
4040
case DirectiveState.Part:
41-
parser.reportRecoverableError(token, messageExportAfterPart);
41+
parser.reportRecoverableError(token, codeExportAfterPart);
4242
case DirectiveState.PartOf:
4343
if (enableFeatureEnhancedParts) {
4444
state = DirectiveState.ImportAndExport;
4545
} else {
46-
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
46+
parser.reportRecoverableError(token, codeNonPartOfDirectiveInPart);
4747
}
4848
case DirectiveState.Declarations:
49-
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
49+
parser.reportRecoverableError(token, codeDirectiveAfterDeclaration);
5050
}
5151
}
5252

@@ -58,15 +58,15 @@ class DirectiveContext {
5858
case DirectiveState.ImportAndExport:
5959
state = DirectiveState.ImportAndExport;
6060
case DirectiveState.Part:
61-
parser.reportRecoverableError(token, messageImportAfterPart);
61+
parser.reportRecoverableError(token, codeImportAfterPart);
6262
case DirectiveState.PartOf:
6363
if (enableFeatureEnhancedParts) {
6464
state = DirectiveState.ImportAndExport;
6565
} else {
66-
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
66+
parser.reportRecoverableError(token, codeNonPartOfDirectiveInPart);
6767
}
6868
case DirectiveState.Declarations:
69-
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
69+
parser.reportRecoverableError(token, codeDirectiveAfterDeclaration);
7070
}
7171
}
7272

@@ -77,11 +77,11 @@ class DirectiveContext {
7777
}
7878
// Recovery
7979
if (state == DirectiveState.Library) {
80-
parser.reportRecoverableError(token, messageMultipleLibraryDirectives);
80+
parser.reportRecoverableError(token, codeMultipleLibraryDirectives);
8181
} else if (state == DirectiveState.PartOf) {
82-
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
82+
parser.reportRecoverableError(token, codeNonPartOfDirectiveInPart);
8383
} else {
84-
parser.reportRecoverableError(token, messageLibraryDirectiveNotFirst);
84+
parser.reportRecoverableError(token, codeLibraryDirectiveNotFirst);
8585
}
8686
}
8787

@@ -97,10 +97,10 @@ class DirectiveContext {
9797
if (enableFeatureEnhancedParts) {
9898
state = DirectiveState.ImportAndExport;
9999
} else {
100-
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
100+
parser.reportRecoverableError(token, codeNonPartOfDirectiveInPart);
101101
}
102102
case DirectiveState.Declarations:
103-
parser.reportRecoverableError(token, messageDirectiveAfterDeclaration);
103+
parser.reportRecoverableError(token, codeDirectiveAfterDeclaration);
104104
}
105105
}
106106

@@ -111,9 +111,9 @@ class DirectiveContext {
111111
}
112112
// Recovery
113113
if (state == DirectiveState.PartOf) {
114-
parser.reportRecoverableError(token, messagePartOfTwice);
114+
parser.reportRecoverableError(token, codePartOfTwice);
115115
} else {
116-
parser.reportRecoverableError(token, messageNonPartOfDirectiveInPart);
116+
parser.reportRecoverableError(token, codeNonPartOfDirectiveInPart);
117117
}
118118
}
119119

pkg/_fe_analyzer_shared/lib/src/parser/identifier_context_impl.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CatchParameterIdentifierContext extends IdentifierContext {
3131
}
3232

3333
// Recovery
34-
parser.reportRecoverableError(identifier, codes.messageCatchSyntax);
34+
parser.reportRecoverableError(identifier, codes.codeCatchSyntax);
3535
if (looksLikeStatementStart(identifier) ||
3636
identifier.isA(TokenType.COMMA) ||
3737
identifier.isA(TokenType.CLOSE_PAREN) ||
@@ -1156,7 +1156,7 @@ class MethodDeclarationIdentifierContext extends IdentifierContext {
11561156
return parser.insertSyntheticIdentifier(
11571157
identifier,
11581158
this,
1159-
message: codes.messageMissingOperatorKeyword,
1159+
message: codes.codeMissingOperatorKeyword,
11601160
messageOnToken: identifier,
11611161
);
11621162
} else if (identifier.isA(TokenType.PERIOD) ||
@@ -1518,7 +1518,7 @@ class TypeReferenceIdentifierContext extends IdentifierContext {
15181518
return next;
15191519
} else if (next.isKeywordOrIdentifier) {
15201520
if (next.isA(Keyword.VOID)) {
1521-
parser.reportRecoverableError(next, codes.messageInvalidVoid);
1521+
parser.reportRecoverableError(next, codes.codeInvalidVoid);
15221522
} else if (next.type.isBuiltIn) {
15231523
if (!isBuiltInIdentifierAllowed) {
15241524
parser.reportRecoverableErrorWithToken(
@@ -1527,7 +1527,7 @@ class TypeReferenceIdentifierContext extends IdentifierContext {
15271527
);
15281528
}
15291529
} else if (next.isA(Keyword.VAR)) {
1530-
parser.reportRecoverableError(next, codes.messageVarAsTypeName);
1530+
parser.reportRecoverableError(next, codes.codeVarAsTypeName);
15311531
} else {
15321532
parser.reportRecoverableErrorWithToken(next, codes.codeExpectedType);
15331533
}
@@ -1634,9 +1634,9 @@ class TypeVariableDeclarationIdentifierContext extends IdentifierContext {
16341634
void checkAsyncAwaitYieldAsIdentifier(Token identifier, Parser parser) {
16351635
if (!parser.inPlainSync && identifier.type.isPseudo) {
16361636
if (identifier.isA(Keyword.AWAIT)) {
1637-
parser.reportRecoverableError(identifier, codes.messageAwaitAsIdentifier);
1637+
parser.reportRecoverableError(identifier, codes.codeAwaitAsIdentifier);
16381638
} else if (identifier.isA(Keyword.YIELD)) {
1639-
parser.reportRecoverableError(identifier, codes.messageYieldAsIdentifier);
1639+
parser.reportRecoverableError(identifier, codes.codeYieldAsIdentifier);
16401640
}
16411641
}
16421642
}

pkg/_fe_analyzer_shared/lib/src/parser/modifier_context.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class ModifierContext {
241241
if (varFinalOrConst != null) {
242242
parser.reportRecoverableError(
243243
varFinalOrConst!,
244-
codes.messageFunctionTypedParameterVar,
244+
codes.codeFunctionTypedParameterVar,
245245
);
246246
}
247247
}
@@ -274,7 +274,7 @@ class ModifierContext {
274274
if (abstractToken != null) {
275275
parser.reportRecoverableError(
276276
abstractToken!,
277-
codes.messageAbstractClassMember,
277+
codes.codeAbstractClassMember,
278278
);
279279
}
280280
reportExtraneousModifier(lateToken);
@@ -445,7 +445,7 @@ class ModifierContext {
445445
} else if (covariantToken != null) {
446446
reportConflictingModifiers(next, covariantToken!);
447447
} else if (finalToken != null) {
448-
parser.reportRecoverableError(next, codes.messageConstAndFinal);
448+
parser.reportRecoverableError(next, codes.codeConstAndFinal);
449449
} else if (varToken != null) {
450450
reportConflictingModifiers(next, varToken!);
451451
} else {
@@ -484,7 +484,7 @@ class ModifierContext {
484484
} else if (constToken != null) {
485485
reportConflictingModifiers(next, constToken!);
486486
} else if (staticToken != null) {
487-
parser.reportRecoverableError(next, codes.messageCovariantAndStatic);
487+
parser.reportRecoverableError(next, codes.codeCovariantAndStatic);
488488
} else {
489489
throw 'Internal Error: Unhandled recovery: $next';
490490
}
@@ -537,9 +537,9 @@ class ModifierContext {
537537
} else if (_afterFactory) {
538538
reportExtraneousModifier(next);
539539
} else if (constToken != null) {
540-
parser.reportRecoverableError(next, codes.messageConstAndFinal);
540+
parser.reportRecoverableError(next, codes.codeConstAndFinal);
541541
} else if (varToken != null) {
542-
parser.reportRecoverableError(next, codes.messageFinalAndVar);
542+
parser.reportRecoverableError(next, codes.codeFinalAndVar);
543543
} else if (lateToken != null) {
544544
reportModifierOutOfOrder(next, lateToken!.lexeme);
545545
} else {
@@ -612,7 +612,7 @@ class ModifierContext {
612612

613613
// Recovery
614614
if (covariantToken != null) {
615-
parser.reportRecoverableError(next, codes.messageCovariantAndStatic);
615+
parser.reportRecoverableError(next, codes.codeCovariantAndStatic);
616616
} else if (staticToken != null) {
617617
parser.reportRecoverableErrorWithToken(
618618
next,
@@ -645,7 +645,7 @@ class ModifierContext {
645645
} else if (constToken != null) {
646646
reportConflictingModifiers(next, constToken!);
647647
} else if (finalToken != null) {
648-
parser.reportRecoverableError(next, codes.messageFinalAndVar);
648+
parser.reportRecoverableError(next, codes.codeFinalAndVar);
649649
} else {
650650
throw 'Internal Error: Unexpected varFinalOrConst: $varFinalOrConst';
651651
}
@@ -676,14 +676,14 @@ class ModifierContext {
676676
void reportTopLevelModifierError(Token? modifier, Token afterModifiers) {
677677
if (modifier != null) {
678678
if (modifier.isA(Keyword.CONST) && afterModifiers.isA(Keyword.CLASS)) {
679-
parser.reportRecoverableError(modifier, codes.messageConstClass);
679+
parser.reportRecoverableError(modifier, codes.codeConstClass);
680680
} else if (modifier.isA(Keyword.EXTERNAL)) {
681681
if (afterModifiers.isA(Keyword.CLASS)) {
682-
parser.reportRecoverableError(modifier, codes.messageExternalClass);
682+
parser.reportRecoverableError(modifier, codes.codeExternalClass);
683683
} else if (afterModifiers.isA(Keyword.ENUM)) {
684-
parser.reportRecoverableError(modifier, codes.messageExternalEnum);
684+
parser.reportRecoverableError(modifier, codes.codeExternalEnum);
685685
} else if (afterModifiers.isA(Keyword.TYPEDEF)) {
686-
parser.reportRecoverableError(modifier, codes.messageExternalTypedef);
686+
parser.reportRecoverableError(modifier, codes.codeExternalTypedef);
687687
} else {
688688
parser.reportRecoverableErrorWithToken(
689689
modifier,

pkg/_fe_analyzer_shared/lib/src/parser/parser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'parser_impl.dart' show Parser;
1313
import 'parser_error.dart' show ParserError;
1414

1515
import '../messages/codes.dart'
16-
show Message, messageNativeClauseShouldBeAnnotation;
16+
show Message, codeNativeClauseShouldBeAnnotation;
1717

1818
export 'assert.dart' show Assert;
1919

@@ -61,7 +61,7 @@ class ErrorCollectingListener extends Listener {
6161
Token endToken,
6262
) {
6363
/// TODO(danrubel): Ignore this error until we deprecate `native` support.
64-
if (message == messageNativeClauseShouldBeAnnotation) {
64+
if (message == codeNativeClauseShouldBeAnnotation) {
6565
return;
6666
}
6767
recoverableErrors.add(

0 commit comments

Comments
 (0)