Add AST representation of the late keyword
Change-Id: I0475065506488a0313c0aa6bc7f30d16f95d1405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99730
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/dart/ast/ast.dart b/pkg/analyzer/lib/dart/ast/ast.dart
index bce36d6..72e85e0 100644
--- a/pkg/analyzer/lib/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/dart/ast/ast.dart
@@ -5227,6 +5227,9 @@
/// even though they are implicitly final.
bool get isFinal;
+ /// Return `true` if this variable was declared with the 'late' modifier.
+ bool get isLate;
+
/// Return the name of the variable being declared.
SimpleIdentifier get name;
@@ -5240,10 +5243,10 @@
/// finalConstVarOrType [VariableDeclaration] (',' [VariableDeclaration])*
///
/// finalConstVarOrType ::=
-/// | 'final' [TypeAnnotation]?
+/// 'final' 'late'? [TypeAnnotation]?
/// | 'const' [TypeAnnotation]?
/// | 'var'
-/// | [TypeAnnotation]
+/// | 'late'? [TypeAnnotation]
///
/// Clients may not extend, implement or mix-in this class.
abstract class VariableDeclarationList implements AnnotatedNode {
@@ -5257,6 +5260,10 @@
/// this is a syntactic check rather than a semantic check.)
bool get isFinal;
+ /// Return `true` if the variables in this list were declared with the 'late'
+ /// modifier.
+ bool get isLate;
+
/// Return the token representing the 'final', 'const' or 'var' keyword, or
/// `null` if no keyword was included.
Token get keyword;
@@ -5265,6 +5272,10 @@
/// given [token].
void set keyword(Token token);
+ /// Return the token representing the 'late' keyword, or `null` if the late
+ /// modifier was not included.
+ Token get lateKeyword;
+
/// Return the type of the variables being declared, or `null` if no type was
/// provided.
TypeAnnotation get type;
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index 676b8dc..8797967 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -10381,6 +10381,12 @@
}
@override
+ bool get isLate {
+ AstNode parent = this.parent;
+ return parent is VariableDeclarationList && parent.isLate;
+ }
+
+ @override
SimpleIdentifier get name => _name;
@override
@@ -10406,16 +10412,20 @@
/// (',' [VariableDeclaration])*
///
/// finalConstVarOrType ::=
-/// | 'final' [TypeName]?
-/// | 'const' [TypeName]?
+/// 'final' 'late'? [TypeAnnotation]?
+/// | 'const' [TypeAnnotation]?
/// | 'var'
-/// | [TypeName]
+/// | 'late'? [TypeAnnotation]
class VariableDeclarationListImpl extends AnnotatedNodeImpl
implements VariableDeclarationList {
/// The token representing the 'final', 'const' or 'var' keyword, or `null` if
/// no keyword was included.
Token keyword;
+ /// The token representing the 'late' keyword, or `null` if the late modifier
+ /// was not included.
+ Token lateKeyword;
+
/// The type of the variables being declared, or `null` if no type was
/// provided.
TypeAnnotationImpl _type;
@@ -10465,6 +10475,9 @@
bool get isFinal => keyword?.keyword == Keyword.FINAL;
@override
+ bool get isLate => lateKeyword != null;
+
+ @override
TypeAnnotation get type => _type;
@override