Skip to content

Commit cfba919

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[analyzer] Dot Shorthands: Change DotShorthandPropertyAccess Token to SimpleIdentifier.
This CL changes `propertyName` to be a `SimpleIdentifier` instead of `Token` because we need to resolve and store the resolved element in the `SimpleIdentifier`. Note that the corresponding class `PropertyAccess` represents its `propertyName` as a `SimpleIdentifier` for the same reason. Bug: #59835 Change-Id: I934f66f914b061b8593399c79a0f7b590b84cc12 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419584 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 6253555 commit cfba919

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

pkg/analyzer/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ package:analyzer/dart/ast/ast.dart:
740740
period (getter: Token)
741741
DotShorthandPropertyAccess (class extends Expression, experimental):
742742
period (getter: Token)
743-
propertyName (getter: Token)
743+
propertyName (getter: SimpleIdentifier)
744744
DottedName (class extends Object implements AstNode):
745745
components (getter: NodeList<SimpleIdentifier>)
746746
DoubleLiteral (class extends Object implements Literal):

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,36 +5479,44 @@ abstract final class DotShorthandPropertyAccess extends Expression {
54795479
Token get period;
54805480

54815481
/// The name of the property being accessed.
5482-
Token get propertyName;
5482+
SimpleIdentifier get propertyName;
54835483
}
54845484

54855485
final class DotShorthandPropertyAccessImpl extends ExpressionImpl
54865486
implements DotShorthandPropertyAccess {
54875487
@override
54885488
final Token period;
54895489

5490-
@override
5491-
final Token propertyName;
5490+
SimpleIdentifierImpl _propertyName;
54925491

54935492
/// Initializes a newly created dot shorthand property access.
54945493
DotShorthandPropertyAccessImpl({
54955494
required this.period,
5496-
required this.propertyName,
5497-
});
5495+
required SimpleIdentifierImpl propertyName,
5496+
}) : _propertyName = propertyName {
5497+
_becomeParentOf(_propertyName);
5498+
}
54985499

54995500
@override
55005501
Token get beginToken => period;
55015502

55025503
@override
5503-
Token get endToken => propertyName;
5504+
Token get endToken => propertyName.endToken;
55045505

55055506
@override
55065507
Precedence get precedence => Precedence.postfix;
55075508

5509+
@override
5510+
SimpleIdentifierImpl get propertyName => _propertyName;
5511+
5512+
set propertyName(SimpleIdentifierImpl identifier) {
5513+
_propertyName = _becomeParentOf(identifier);
5514+
}
5515+
55085516
@override
55095517
ChildEntities get _childEntities => ChildEntities()
55105518
..addToken('period', period)
5511-
..addToken('propertyName', propertyName);
5519+
..addNode('propertyName', propertyName);
55125520

55135521
@override
55145522
E? accept<E>(AstVisitor<E> visitor) =>
@@ -5520,7 +5528,9 @@ final class DotShorthandPropertyAccessImpl extends ExpressionImpl
55205528
}
55215529

55225530
@override
5523-
void visitChildren(AstVisitor visitor) {}
5531+
void visitChildren(AstVisitor visitor) {
5532+
propertyName.accept(visitor);
5533+
}
55245534
}
55255535

55265536
/// A dotted name, used in a configuration within an import or export directive.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class ToSourceVisitor implements AstVisitor<void> {
359359
@override
360360
void visitDotShorthandPropertyAccess(DotShorthandPropertyAccess node) {
361361
_visitToken(node.period);
362-
_visitToken(node.propertyName);
362+
_visitNode(node.propertyName);
363363
}
364364

365365
@override

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,13 @@ class NodeReplacer extends ThrowingAstVisitor<bool> {
725725

726726
@override
727727
bool? visitDotShorthandPropertyAccess(
728-
covariant DotShorthandPropertyAccessImpl node) =>
729-
visitNode(node);
728+
covariant DotShorthandPropertyAccessImpl node) {
729+
if (identical(node.propertyName, _oldNode)) {
730+
node.propertyName = _newNode as SimpleIdentifierImpl;
731+
return true;
732+
}
733+
return visitNode(node);
734+
}
730735

731736
@override
732737
bool visitDottedName(covariant DottedNameImpl node) {

0 commit comments

Comments
 (0)