Skip to content

Commit b704bba

Browse files
scheglovCommit Queue
authored andcommitted
Use AstNodeImpl for a few NodeList(s).
Change-Id: I2a078c35458ffc509e93108bd189aa29de7a6b7f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262822 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent d485d1a commit b704bba

File tree

11 files changed

+70
-227
lines changed

11 files changed

+70
-227
lines changed

pkg/analyzer/lib/src/clients/dart_style/rewrite_cascade.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ExpressionStatement fixCascadeByParenthesizingTarget({
1313
required ExpressionStatement expressionStatement,
1414
required CascadeExpression cascadeExpression,
1515
}) {
16+
cascadeExpression as CascadeExpressionImpl;
1617
assert(cascadeExpression.cascadeSections.length == 1);
1718

1819
var newTarget = astFactory.parenthesizedExpression(

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ import 'package:meta/meta.dart';
3636
/// [StringLiteral] [StringLiteral]+
3737
class AdjacentStringsImpl extends StringLiteralImpl implements AdjacentStrings {
3838
/// The strings that are implicitly concatenated.
39-
final NodeListImpl<StringLiteral> _strings = NodeListImpl._();
39+
final NodeListImpl<StringLiteralImpl> _strings = NodeListImpl._();
4040

4141
/// Initialize a newly created list of adjacent strings. To be syntactically
4242
/// valid, the list of [strings] must contain at least two elements.
4343
AdjacentStringsImpl({
44-
required List<StringLiteral> strings,
44+
required List<StringLiteralImpl> strings,
4545
}) {
4646
_strings._initialize(this, strings);
4747
}
@@ -53,7 +53,7 @@ class AdjacentStringsImpl extends StringLiteralImpl implements AdjacentStrings {
5353
Token get endToken => _strings.endToken!;
5454

5555
@override
56-
NodeListImpl<StringLiteral> get strings => _strings;
56+
NodeListImpl<StringLiteralImpl> get strings => _strings;
5757

5858
@override
5959
ChildEntities get _childEntities {
@@ -77,8 +77,7 @@ class AdjacentStringsImpl extends StringLiteralImpl implements AdjacentStrings {
7777
void _appendStringValue(StringBuffer buffer) {
7878
int length = strings.length;
7979
for (int i = 0; i < length; i++) {
80-
var stringLiteral = strings[i] as StringLiteralImpl;
81-
stringLiteral._appendStringValue(buffer);
80+
strings[i]._appendStringValue(buffer);
8281
}
8382
}
8483
}
@@ -342,7 +341,7 @@ class ArgumentListImpl extends AstNodeImpl implements ArgumentList {
342341
Token leftParenthesis;
343342

344343
/// The expressions producing the values of the arguments.
345-
final NodeListImpl<Expression> _arguments = NodeListImpl._();
344+
final NodeListImpl<ExpressionImpl> _arguments = NodeListImpl._();
346345

347346
/// The right parenthesis.
348347
@override
@@ -360,14 +359,14 @@ class ArgumentListImpl extends AstNodeImpl implements ArgumentList {
360359
/// be `null` if there are no arguments.
361360
ArgumentListImpl({
362361
required this.leftParenthesis,
363-
required List<Expression> arguments,
362+
required List<ExpressionImpl> arguments,
364363
required this.rightParenthesis,
365364
}) {
366365
_arguments._initialize(this, arguments);
367366
}
368367

369368
@override
370-
NodeListImpl<Expression> get arguments => _arguments;
369+
NodeListImpl<ExpressionImpl> get arguments => _arguments;
371370

372371
@override
373372
Token get beginToken => leftParenthesis;
@@ -1227,7 +1226,7 @@ class BlockImpl extends StatementImpl implements Block {
12271226
Token leftBracket;
12281227

12291228
/// The statements contained in the block.
1230-
final NodeListImpl<Statement> _statements = NodeListImpl._();
1229+
final NodeListImpl<StatementImpl> _statements = NodeListImpl._();
12311230

12321231
/// The right curly bracket.
12331232
@override
@@ -1236,7 +1235,7 @@ class BlockImpl extends StatementImpl implements Block {
12361235
/// Initialize a newly created block of code.
12371236
BlockImpl({
12381237
required this.leftBracket,
1239-
required List<Statement> statements,
1238+
required List<StatementImpl> statements,
12401239
required this.rightBracket,
12411240
}) {
12421241
_statements._initialize(this, statements);
@@ -1249,7 +1248,7 @@ class BlockImpl extends StatementImpl implements Block {
12491248
Token get endToken => rightBracket;
12501249

12511250
@override
1252-
NodeListImpl<Statement> get statements => _statements;
1251+
NodeListImpl<StatementImpl> get statements => _statements;
12531252

12541253
@override
12551254
ChildEntities get _childEntities => ChildEntities()
@@ -1397,13 +1396,13 @@ class CascadeExpressionImpl extends ExpressionImpl
13971396
ExpressionImpl _target;
13981397

13991398
/// The cascade sections sharing the common target.
1400-
final NodeListImpl<Expression> _cascadeSections = NodeListImpl._();
1399+
final NodeListImpl<ExpressionImpl> _cascadeSections = NodeListImpl._();
14011400

14021401
/// Initialize a newly created cascade expression. The list of
14031402
/// [cascadeSections] must contain at least one element.
14041403
CascadeExpressionImpl({
14051404
required ExpressionImpl target,
1406-
required List<Expression> cascadeSections,
1405+
required List<ExpressionImpl> cascadeSections,
14071406
}) : _target = target {
14081407
_becomeParentOf(_target);
14091408
_cascadeSections._initialize(this, cascadeSections);
@@ -1413,7 +1412,7 @@ class CascadeExpressionImpl extends ExpressionImpl
14131412
Token get beginToken => _target.beginToken;
14141413

14151414
@override
1416-
NodeListImpl<Expression> get cascadeSections => _cascadeSections;
1415+
NodeListImpl<ExpressionImpl> get cascadeSections => _cascadeSections;
14171416

14181417
@override
14191418
Token get endToken => _cascadeSections.endToken!;
@@ -1875,7 +1874,7 @@ class ClassDeclarationImpl extends NamedCompilationUnitMemberImpl
18751874
Token leftBracket;
18761875

18771876
/// The members defined by the class or mixin.
1878-
final NodeListImpl<ClassMember> _members = NodeListImpl._();
1877+
final NodeListImpl<ClassMemberImpl> _members = NodeListImpl._();
18791878

18801879
/// The right curly bracket.
18811880
@override
@@ -1903,7 +1902,7 @@ class ClassDeclarationImpl extends NamedCompilationUnitMemberImpl
19031902
required ImplementsClauseImpl? implementsClause,
19041903
required NativeClauseImpl? nativeClause,
19051904
required this.leftBracket,
1906-
required List<ClassMember> members,
1905+
required List<ClassMemberImpl> members,
19071906
required this.rightBracket,
19081907
}) : _typeParameters = typeParameters,
19091908
_extendsClause = extendsClause,
@@ -1946,7 +1945,7 @@ class ClassDeclarationImpl extends NamedCompilationUnitMemberImpl
19461945
}
19471946

19481947
@override
1949-
NodeListImpl<ClassMember> get members => _members;
1948+
NodeListImpl<ClassMemberImpl> get members => _members;
19501949

19511950
@override
19521951
NativeClauseImpl? get nativeClause => _nativeClause;

pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ class ToSourceVisitor implements AstVisitor<void> {
186186
@override
187187
void visitClassDeclaration(covariant ClassDeclarationImpl node) {
188188
_visitNodeList(node.metadata, separator: ' ', suffix: ' ');
189+
_visitToken(node.augmentKeyword, suffix: ' ');
189190
_visitToken(node.abstractKeyword, suffix: ' ');
190191
_visitToken(node.macroKeyword, suffix: ' ');
191-
_visitToken(node.augmentKeyword, suffix: ' ');
192192
sink.write('class ');
193193
_visitToken(node.name);
194194
_visitNode(node.typeParameters);

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement {
857857
superclassConstructor.isConst && !hasMixinWithInstanceVariables;
858858
List<ParameterElement> superParameters = superclassConstructor.parameters;
859859
int count = superParameters.length;
860-
var argumentsForSuperInvocation = <Expression>[];
860+
var argumentsForSuperInvocation = <ExpressionImpl>[];
861861
if (count > 0) {
862862
var implicitParameters = <ParameterElement>[];
863863
for (int i = 0; i < count; i++) {

pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class InvocationInferrer<Node extends AstNodeImpl> {
492492
Expression value;
493493
ParameterElement? parameter;
494494
Object parameterKey;
495-
if (argument is NamedExpression) {
495+
if (argument is NamedExpressionImpl) {
496496
value = argument.expression;
497497
parameterKey = argument.name.label.name;
498498
} else {

pkg/analyzer/lib/src/fasta/ast_builder.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class AstBuilder extends StackListener {
201201
push(
202202
CascadeExpressionImpl(
203203
target: expression,
204-
cascadeSections: <Expression>[],
204+
cascadeSections: <ExpressionImpl>[],
205205
),
206206
);
207207
}
@@ -656,7 +656,7 @@ class AstBuilder extends StackListener {
656656
assert(optional(')', rightParenthesis));
657657
debugEvent("Arguments");
658658

659-
var expressions = popTypedList2<Expression>(count);
659+
var expressions = popTypedList2<ExpressionImpl>(count);
660660
final arguments = ArgumentListImpl(
661661
leftParenthesis: leftParenthesis,
662662
arguments: expressions,
@@ -707,7 +707,7 @@ class AstBuilder extends StackListener {
707707
case Assert.Expression:
708708
// The parser has already reported an error indicating that assert
709709
// cannot be used in an expression. Insert a placeholder.
710-
List<Expression> arguments = <Expression>[condition];
710+
final arguments = <ExpressionImpl>[condition];
711711
if (message != null) {
712712
arguments.add(message);
713713
}
@@ -821,7 +821,7 @@ class AstBuilder extends StackListener {
821821
assert(optional('}', rightBracket));
822822
debugEvent("Block");
823823

824-
var statements = popTypedList2<Statement>(count);
824+
var statements = popTypedList2<StatementImpl>(count);
825825
push(
826826
BlockImpl(
827827
leftBracket: leftBracket,
@@ -837,7 +837,7 @@ class AstBuilder extends StackListener {
837837
assert(optional('}', rightBracket));
838838
debugEvent("BlockFunctionBody");
839839

840-
var statements = popTypedList2<Statement>(count);
840+
var statements = popTypedList2<StatementImpl>(count);
841841
final block = BlockImpl(
842842
leftBracket: leftBracket,
843843
statements: statements,
@@ -870,13 +870,13 @@ class AstBuilder extends StackListener {
870870
void endCascade() {
871871
debugEvent("Cascade");
872872

873-
var expression = pop() as Expression;
873+
var expression = pop() as ExpressionImpl;
874874
var cascade = pop() as CascadeExpressionImpl;
875875
pop(); // Token.
876876
push(
877877
CascadeExpressionImpl(
878878
target: cascade.target,
879-
cascadeSections: <Expression>[
879+
cascadeSections: <ExpressionImpl>[
880880
...cascade.cascadeSections,
881881
expression,
882882
],
@@ -950,7 +950,7 @@ class AstBuilder extends StackListener {
950950
handleRecoverableError(
951951
messageConstConstructorWithBody, bodyToken, bodyToken);
952952
}
953-
ConstructorDeclaration constructor = ConstructorDeclarationImpl(
953+
var constructor = ConstructorDeclarationImpl(
954954
comment: comment,
955955
metadata: metadata,
956956
externalKeyword: modifiers?.externalKeyword,
@@ -4764,7 +4764,7 @@ class AstBuilder extends StackListener {
47644764
void handleStringJuxtaposition(Token startToken, int literalCount) {
47654765
debugEvent("StringJuxtaposition");
47664766

4767-
var strings = popTypedList2<StringLiteral>(literalCount);
4767+
var strings = popTypedList2<StringLiteralImpl>(literalCount);
47684768
push(AdjacentStringsImpl(strings: strings));
47694769
}
47704770

@@ -5210,7 +5210,7 @@ class _ClassLikeDeclarationBuilder {
52105210
final TypeParameterListImpl? typeParameters;
52115211

52125212
Token leftBracket;
5213-
final List<ClassMember> members = [];
5213+
final List<ClassMemberImpl> members = [];
52145214
Token rightBracket;
52155215

52165216
_ClassLikeDeclarationBuilder({

pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ import 'package:meta/meta.dart';
2424
/// rather than 'integerLiteral'.
2525
@internal
2626
class AstTestFactory {
27-
static ArgumentListImpl argumentList(
28-
[List<Expression> arguments = const []]) =>
29-
ArgumentListImpl(
30-
leftParenthesis: TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
31-
arguments: arguments,
32-
rightParenthesis: TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
33-
);
34-
3527
static AssignmentExpressionImpl assignmentExpression(Expression leftHandSide,
3628
TokenType operator, Expression rightHandSide) =>
3729
AssignmentExpressionImpl(
@@ -40,37 +32,6 @@ class AstTestFactory {
4032
rightHandSide: rightHandSide as ExpressionImpl,
4133
);
4234

43-
static ClassDeclarationImpl classDeclaration(
44-
Keyword? abstractKeyword,
45-
String name,
46-
TypeParameterList? typeParameters,
47-
ExtendsClause? extendsClause,
48-
WithClause? withClause,
49-
ImplementsClause? implementsClause,
50-
{List<ClassMember> members = const [],
51-
bool isMacro = false,
52-
bool isAugmentation = false}) =>
53-
ClassDeclarationImpl(
54-
comment: null,
55-
metadata: null,
56-
abstractKeyword: abstractKeyword == null
57-
? null
58-
: TokenFactory.tokenFromKeyword(abstractKeyword),
59-
macroKeyword: isMacro ? TokenFactory.tokenFromString('macro') : null,
60-
augmentKeyword:
61-
isAugmentation ? TokenFactory.tokenFromString('augment') : null,
62-
classKeyword: TokenFactory.tokenFromKeyword(Keyword.CLASS),
63-
name: TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, name),
64-
typeParameters: typeParameters as TypeParameterListImpl?,
65-
extendsClause: extendsClause as ExtendsClauseImpl?,
66-
withClause: withClause as WithClauseImpl?,
67-
implementsClause: implementsClause as ImplementsClauseImpl?,
68-
nativeClause: null,
69-
leftBracket: TokenFactory.tokenFromType(TokenType.OPEN_CURLY_BRACKET),
70-
members: members,
71-
rightBracket:
72-
TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
73-
7435
static ConstructorDeclarationImpl constructorDeclaration(
7536
Identifier returnType,
7637
String? name,
@@ -223,14 +184,6 @@ class AstTestFactory {
223184
[List<Combinator> combinators = const []]) =>
224185
importDirective([], uri, false, prefix, combinators);
225186

226-
static InstanceCreationExpressionImpl instanceCreationExpression(
227-
Keyword? keyword, ConstructorName name,
228-
[List<Expression> arguments = const []]) =>
229-
astFactory.instanceCreationExpression(
230-
keyword == null ? null : TokenFactory.tokenFromKeyword(keyword),
231-
name,
232-
argumentList(arguments));
233-
234187
static InterpolationExpressionImpl interpolationExpression(
235188
Expression expression) =>
236189
astFactory.interpolationExpression(
@@ -413,19 +366,6 @@ class AstTestFactory {
413366
static SimpleStringLiteralImpl string2(String content) => astFactory
414367
.simpleStringLiteral(TokenFactory.tokenFromString("'$content'"), content);
415368

416-
static SuperConstructorInvocationImpl superConstructorInvocation(
417-
[List<Expression> arguments = const []]) =>
418-
superConstructorInvocation2(null, arguments);
419-
420-
static SuperConstructorInvocationImpl superConstructorInvocation2(
421-
String? name,
422-
[List<Expression> arguments = const []]) =>
423-
astFactory.superConstructorInvocation(
424-
TokenFactory.tokenFromKeyword(Keyword.SUPER),
425-
name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD),
426-
name == null ? null : identifier3(name),
427-
argumentList(arguments));
428-
429369
static SuperExpressionImpl superExpression() =>
430370
astFactory.superExpression(TokenFactory.tokenFromKeyword(Keyword.SUPER));
431371

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class AstBinaryReader {
191191
}
192192

193193
AdjacentStrings _readAdjacentStrings() {
194-
var components = _readNodeList<StringLiteral>();
194+
var components = _readNodeList<StringLiteralImpl>();
195195
var node = AdjacentStringsImpl(strings: components);
196196
_readExpressionResolution(node);
197197
return node;
@@ -215,7 +215,7 @@ class AstBinaryReader {
215215
}
216216

217217
ArgumentList _readArgumentList() {
218-
var arguments = _readNodeList<Expression>();
218+
var arguments = _readNodeList<ExpressionImpl>();
219219

220220
return ArgumentListImpl(
221221
leftParenthesis: Tokens.openParenthesis(),
@@ -306,7 +306,7 @@ class AstBinaryReader {
306306

307307
CascadeExpression _readCascadeExpression() {
308308
var target = readNode() as ExpressionImpl;
309-
var sections = _readNodeList<Expression>();
309+
var sections = _readNodeList<ExpressionImpl>();
310310
var node = CascadeExpressionImpl(
311311
target: target,
312312
cascadeSections: sections,

0 commit comments

Comments
 (0)