Skip to content

Commit dbdfb1e

Browse files
stereotype441Commit Queue
authored andcommitted
[front_end] Add withArguments to Template class.
The CFE `Template` class now exposes a `withArguments` method, which behaves the same as `withArgumetsOld` method, but accepts named arguments rather than positional arguments. In follow-up CLs, I will adjust the names of these positional parameters to be more descriptive, and update call sites to use `withArguments` rather than `withArgumentsOld`. This should make the call sites clearer and easier to understand. Change-Id: I6a6a6964638e0312003aa622c5e0fef782b8d979 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447963 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 8e608e8 commit dbdfb1e

File tree

14 files changed

+5612
-4002
lines changed

14 files changed

+5612
-4002
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,23 @@ class MessageCode extends Code implements Message {
107107
}
108108
}
109109

110-
class Template<T> extends Code {
110+
class Template<TOld extends Function, T extends Function> extends Code {
111111
String get messageCode => name;
112112

113113
final String problemMessageTemplate;
114114

115115
final String? correctionMessageTemplate;
116116

117-
final T withArgumentsOld;
117+
final TOld withArgumentsOld;
118+
119+
final T withArguments;
118120

119121
const Template(
120122
super.name, {
121123
this.correctionMessageTemplate,
122124
required this.problemMessageTemplate,
123125
required this.withArgumentsOld,
126+
required this.withArguments,
124127
super.index = -1,
125128
super.analyzerCodes,
126129
super.severity = CfeSeverity.error,

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 4066 additions & 2829 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BlockKind {
1010

1111
final codes.Message? message;
1212

13-
final codes.Template<codes.Message Function(Token token)>? template;
13+
final codes.Template<codes.Message Function(Token token), Function>? template;
1414

1515
const BlockKind._(this.name, {this.template, this.message});
1616

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ abstract class IdentifierContext {
289289
/// expressions are required.
290290
final bool allowedInConstantExpression;
291291

292-
final Template<_MessageWithArgument<Token>> recoveryTemplate;
292+
final Template<_MessageWithArgument<Token>, Function> recoveryTemplate;
293293

294294
const IdentifierContext(
295295
this._name, {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,7 +4609,7 @@ class Parser {
46094609
Token ensureBlock(Token token, BlockKind? missingBlockKind) {
46104610
Token next = token.next!;
46114611
if (next.isA(TokenType.OPEN_CURLY_BRACKET)) return next;
4612-
codes.Template<codes.Message Function(Token token)>? template =
4612+
codes.Template<codes.Message Function(Token token), Function>? template =
46134613
missingBlockKind?.template;
46144614
if (template == null) {
46154615
codes.Message? message = missingBlockKind?.message;
@@ -10795,7 +10795,7 @@ class Parser {
1079510795

1079610796
void reportRecoverableErrorWithToken(
1079710797
Token token,
10798-
codes.Template<_MessageWithArgument<Token>> template,
10798+
codes.Template<_MessageWithArgument<Token>, Function> template,
1079910799
) {
1080010800
// Find a non-synthetic token on which to report the error.
1080110801
token = findNonZeroLengthToken(token);

pkg/front_end/lib/src/builder/named_type_builder.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ abstract class NamedTypeBuilderImpl extends NamedTypeBuilder {
303303
if (member is TypeDeclarationBuilder) {
304304
bind(problemReporting, member);
305305
} else {
306-
Template<Message Function(String name)> template = member == null
307-
? codeTypeNotFound
308-
: codeNotAType;
306+
Template<Message Function(String name), Function> template =
307+
member == null ? codeTypeNotFound : codeNotAType;
309308
String nameText = typeName.fullName;
310309
int nameOffset = typeName.fullNameOffset;
311310
int nameLength = typeName.fullNameLength;
@@ -459,7 +458,7 @@ abstract class NamedTypeBuilderImpl extends NamedTypeBuilder {
459458
}
460459

461460
Supertype? _handleInvalidSupertype(LibraryBuilder library) {
462-
Template<Message Function(String name)> template =
461+
Template<Message Function(String name), Function> template =
463462
declaration.isTypeParameter
464463
? codeSupertypeIsTypeParameter
465464
: codeSupertypeIsIllegal;

0 commit comments

Comments
 (0)