dart/ast/ast library

Defines the AST model. The AST (Abstract Syntax Tree) model describes the syntactic (as opposed to semantic) structure of Dart code. The semantic structure of the code is modeled by the element model.

An AST consists of nodes (instances of a subclass of AstNode). The nodes are organized in a tree structure in which the children of a node are the smaller syntactic units from which the node is composed. For example, a binary expression consists of two sub-expressions (the operands) and an operator. The two expressions are represented as nodes. The operator is not represented as a node.

The AST is constructed by the parser based on the sequence of tokens produced by the scanner. Most nodes provide direct access to the tokens used to build the node. For example, the token for the operator in a binary expression can be accessed from the node representing the binary expression.

While any node can theoretically be the root of an AST structure, almost all of the AST structures known to the analyzer have a CompilationUnit as the root of the structure. A compilation unit represents all of the Dart code in a single file.

An AST can be either unresolved or resolved. When an AST is unresolved certain properties will not have been computed and the accessors for those properties will return null. The documentation for those getters should describe that this is a possibility.

When an AST is resolved, the identifiers in the AST will be associated with the elements that they refer to and every expression in the AST will have a type associated with it.

Classes

AdjacentStrings
Two or more string literals that are implicitly concatenated because of being adjacent (separated only by whitespace).
AnnotatedNode
An AST node that can be annotated with either a documentation comment, a list of annotations (metadata), or both.
Annotation
An annotation that can be associated with a declaration.
AnonymousBlockBody
The body of an anonymous method invocation with a block.
AnonymousExpressionBody
The body of an anonymous method invocation with an arrow.
AnonymousMethodBody
The body of an anonymous method invocation.
AnonymousMethodInvocation
The invocation of an anonymous block method of an object.
Argument
A node that can occur in an ArgumentList.
ArgumentList
A list of arguments in the invocation of an executable element (that is, a function, method, or constructor).
AsExpression
An as expression.
AssertInitializer
An assert in the initializer list of a constructor.
Assertion
An assertion, either in a block or in the initializer list of a constructor.
AssertStatement
An assert statement.
AssignedVariablePattern
A variable pattern in PatternAssignment.
AssignmentExpression
An assignment expression.
AssignmentExpression2
The common interface for canonical V2 assignment expressions.
AssignmentTarget
An AST node that denotes the destination of an assignment.
AstNode
A node in the AST structure for a Dart program.
AstVisitor<R>
An object that can be used to visit an AST structure.
AstVisitor2<R>
An object that can be used to visit an AST structure.
AwaitExpression
An await expression.
BinaryExpression
A binary (infix) expression.
BinaryOperatorInvocation
An invocation of an overloadable binary operator.
Block
A sequence of statements.
BlockClassBody
The class body with members.
BlockEnumBody
The enum declaration body, with constants and members.
BlockFunctionBody
A function body that consists of a block of statements.
BooleanLiteral
A boolean literal expression.
BreakStatement
A break statement.
CascadeExpression
A sequence of cascaded expressions: expressions that share a common target.
CascadeIndexAssignmentTarget
An indexed location at the start of a cascade section.
CascadeIndexExpression
A value produced by indexing the target at the start of a cascade section.
CascadePropertyAssignmentTarget
A property at the start of a cascade section used as an assignment destination.
CascadePropertyExtraction
A property value selected at the start of a cascade section.
CascadeSection
One section of a CascadeExpression.
CaseClause
The case clause that can optionally appear in an if statement.
CastPattern
A cast pattern.
CatchClause
A catch clause within a try statement.
CatchClauseParameter
An 'exception' or 'stackTrace' parameter in CatchClause.
ClassBody
The body of a class declaration.
ClassDeclaration
The declaration of a class.
ClassMember
A node that declares a name within the scope of a class, enum, extension, extension type, or mixin declaration.
ClassNamePart
The name of a class, enum, or extension type declaration.
ClassTypeAlias
A class type alias.
CollectionElement
Combinator
A combinator associated with an import or export directive.
CombinatorName
A name in a Combinator.
Comment
A comment within the source code.
CommentReferableExpression
An interface for an Expression which can make up a CommentReference.
CommentReference
A reference to a Dart element that is found within a documentation comment.
CompilationUnit
A compilation unit.
CompilationUnitMember
A node that declares one or more names within the scope of a compilation unit.
CompoundAssignment
A compound assignment using an overloadable binary operator.
CompoundAssignmentExpression
A potentially compound assignment.
ConditionalExpression
A conditional expression.
Configuration
A configuration in either an import or export directive.
ConstantPattern
A constant expression being used as a pattern.
ConstructorDeclaration
A constructor declaration.
ConstructorFieldInitializer
The initialization of a field within a constructor's initialization list.
ConstructorInitializer
A node that can occur in the initializer list of a constructor declaration.
ConstructorInvocation
An invocation of a constructor.
ConstructorName
The name of a constructor.
ConstructorReference
An expression representing a reference to a constructor.
ConstructorReference2
A source-level reference to a constructor.
ConstructorReferenceNode
An AST node that makes reference to a constructor.
ConstructorSelector
The name of a constructor being invoked.
ConstructorTearOff
An expression representing a constructor tear-off.
ConstructorTypeReference
A reference to the type defining a constructor.
ContinueStatement
A continue statement.
DartPattern
A pattern.
Declaration
A node that represents the declaration of one or more names.
DeclaredIdentifier
The declaration of a single identifier.
DeclaredVariablePattern
A variable pattern that declares a variable.
DelimitedFormalParameters
Formal parameters enclosed in square or curly brackets.
DirectAssignment
An assignment of the form target = value.
Directive
A node that represents a directive.
DoStatement
A do statement.
DotShorthandConstructorInvocation
A node that represents a dot shorthand constructor invocation.
DotShorthandInvocation
A node that represents a dot shorthand static method or constructor invocation.
DotShorthandPropertyAccess
A node that represents a dot shorthand property access of a field or a static getter.
DottedName
A dotted name, used in a configuration within an import or export directive.
DoubleLiteral
A floating point literal expression.
DynamicIndexReadResolution
An index read whose operator [] is selected dynamically at runtime.
DynamicIndexWriteResolution
An index write whose operator []= is selected dynamically at runtime.
DynamicPropertyReadResolution
A property read whose getter is selected dynamically at runtime.
DynamicPropertyWriteResolution
A property write whose setter is selected dynamically at runtime.
EmptyClassBody
The empty class body.
EmptyEnumBody
The empty enum body.
EmptyFunctionBody
An empty function body.
EmptyStatement
An empty statement.
EnumBody
The body of an enum declaration.
EnumConstantArguments
The arguments part of an enum constant.
EnumConstantDeclaration
The declaration of an enum constant.
EnumDeclaration
The declaration of an enumeration.
ExecutableTearOffResolution
A read that produces the tear-off of an executable declaration.
ExportDirective
An export directive.
Expression
A node that represents an expression.
ExpressionFunctionBody
A function body consisting of a single expression.
ExpressionStatement
An expression used as a statement.
ExtendsClause
The "extends" clause in a class declaration.
ExtensionDeclaration
The declaration of an extension of a type.
ExtensionOnClause
The on clause in an extension declaration.
ExtensionOverride
An override to force resolution to choose a member from a specific extension.
ExtensionTypeDeclaration
The declaration of an extension type.
FieldDeclaration
The declaration of one or more fields of the same type.
FieldFormalParameter
A field formal parameter.
ForEachParts
The parts of a for-each loop that control the iteration.
ForEachPartsWithDeclaration
The parts of a for-each loop that control the iteration when the loop variable is declared as part of the for loop.
ForEachPartsWithIdentifier
The parts of a for-each loop that control the iteration when the loop variable is declared outside of the for loop.
ForEachPartsWithPattern
A for-loop part with a pattern.
ForElement
The basic structure of a for element.
ForLoop<Body extends AstNode>
A for or for-each statement or collection element.
ForLoopParts
The parts of a for or for-each loop that control the iteration.
FormalParameter
A node representing a parameter to a function.
FormalParameterDefaultClause
A default value clause for a formal parameter.
FormalParameterList
The formal parameter list of a method declaration, function declaration, or function type alias.
ForParts
The parts of a for loop that control the iteration.
ForPartsWithDeclarations
The parts of a for loop that control the iteration when there are one or more variable declarations as part of the for loop.
ForPartsWithExpression
The parts of a for loop that control the iteration when there are no variable declarations as part of the for loop.
ForPartsWithPattern
The parts of a for loop that control the iteration when there's a pattern declaration as part of the for loop.
ForStatement
A for or for-each statement.
FragmentDeclaringNode
An AST node that can be associated with a declared Fragment.
FunctionBody
A node representing the body of a function or method.
FunctionCallTearOffResolution
A tear-off of the language-defined call method of a function-typed value.
FunctionDeclaration
A function declaration.
FunctionDeclarationStatement
A FunctionDeclaration used as a statement.
FunctionExpression
A function expression.
FunctionExpressionInvocation
The invocation of a function resulting from evaluating an expression.
FunctionInterfaceCallTearOffResolution
A tear-off of call through the core Function interface.
FunctionReference
An expression representing a reference to a function, possibly with type arguments applied to it.
FunctionTypeAlias
A function type alias.
FunctionTypedFormalParameterSuffix
The function-typed suffix of a formal parameter.
GenericFunctionType
An anonymous function type.
GenericTypeAlias
A generic type alias.
GetterDeclaration
A getter declaration in an instance declaration body.
GetterInvocationResolution
A read that invokes a getter.
GuardedPattern
The pattern with an optional WhenClause.
HideCombinator
A combinator that restricts the names being imported to those that aren't in a given list.
Identifier
A node that represents an identifier.
IfElement
The basic structure of an if element.
IfNull
An if-null expression.
IfNullAssignment
An if-null assignment using ??=.
IfStatement
An if statement.
ImplementsClause
The "implements" clause in an class declaration.
ImplicitCallReference
An expression representing an implicit 'call' method reference.
ImportDirective
An import directive.
ImportPrefixReference
Reference to an import prefix name.
IncrementOrDecrementExpression
A prefix or postfix increment or decrement expression.
IndexAssignmentTarget
An indexed location used as an assignment destination.
IndexExpression
An index expression.
IndexExpression2
A value produced by invoking operator [] on an explicitly written expression receiver.
IndexReadResolution
The result of an indexed read operation.
IndexWriteResolution
The result of writing an indexed assignment target.
InstanceCreationExpression
An instance creation expression.
InstanceDeclaration
A top-level V2 declaration that contributes an InstanceFragment.
InstanceDeclarationBody
The normalized body of an InstanceDeclaration.
InstanceReceiver
An expression or non-value form that can receive an instance operation.
IntegerLiteral
An integer literal expression.
InterpolationElement
A node within a StringInterpolation.
InterpolationExpression
An expression embedded in a string interpolation.
InterpolationString
A non-empty substring of an interpolated string.
InvalidAssignmentTarget
An assignment target whose source cannot denote a storage location.
InvalidExpressionAssignmentTarget
An invalid assignment target whose source is an ordinary value expression.
InvalidIndexReadResolution
An unsuccessful index read resolution.
InvalidIndexWriteResolution
An unsuccessful index write resolution.
InvalidNamedReadResolution
An unsuccessful named read resolution.
InvalidNamedWriteResolution
An unsuccessful named write resolution.
InvocationExpression
The invocation of a function or method.
IsExpression
An is expression.
Label
A label on a LabeledStatement or a switch member.
LabeledStatement
A statement that has a label associated with them.
LabelReference
A reference to a label.
LibraryDirective
A library directive.
ListLiteral
A list literal.
ListPattern
A list pattern.
ListPatternElement
An element of a list pattern.
Literal
A node that represents a literal expression.
LogicalAnd
A logical-and expression.
LogicalAndPattern
A logical-and pattern.
LogicalNot
A logical not expression.
LogicalOr
A logical-or expression.
LogicalOrPattern
A logical-or pattern.
MapLiteralEntry
A single key/value pair in a map literal.
MapPattern
A map pattern.
MapPatternElement
An element of a map pattern.
MapPatternEntry
An entry in a map pattern.
MemberDeclaration
A declaration occupying a member position in an instance declaration body.
MethodDeclaration
A method declaration.
MethodDeclaration2
A method declaration in an instance declaration body.
MethodIndexReadResolution
An index read resolved to a statically selected operator [] method.
MethodIndexWriteResolution
An index write resolved to a statically selected operator []= method.
MethodInvocation
The invocation of either a function or a method.
MethodReferenceExpression
An expression that implicitly makes reference to a method.
MixinDeclaration
The declaration of a mixin.
MixinOnClause
The "on" clause in a mixin declaration.
NamedArgument
An argument that has a name associated with it.
NamedReadResolution
The resolution of a named read.
NamedReadResolutionWithElement
A named read that was resolved to an element.
NamedType
A named type, which can optionally include type arguments.
NamedWriteResolution
The result of writing a named assignment target.
NamedWriteResolutionWithElement
A named write that was resolved to an element.
NamespaceDirective
A node that represents a directive that impacts the namespace of a library.
NameWithTypeParameters
The type name with optional type parameters.
NativeClause
The "native" clause in an class declaration.
NativeFunctionBody
A function body that consists of a native keyword followed by a string literal.
NodeList<E extends AstNode>
A list of AST nodes that have a common parent.
NullAssertionExpression
A postfix null assertion expression.
NullAssertPattern
A null-assert pattern.
NullAwareElement
A null-aware element in a list or set literal.
NullCheckPattern
A null-check pattern.
NullLiteral
A null literal expression.
ObjectPattern
An object pattern.
OperatorDeclaration
An operator declaration in an instance declaration body.
ParenthesizedExpression
A parenthesized expression.
ParenthesizedPattern
A parenthesized pattern.
PartDirective
A part directive.
PartOfDirective
A part-of directive.
PatternAssignment
A pattern assignment.
PatternField
A field in an object or record pattern.
PatternFieldName
A field name in an object or record pattern field.
PatternVariableDeclaration
A pattern variable declaration.
PatternVariableDeclarationStatement
A pattern variable declaration statement.
PostfixDecrement
A postfix decrement expression.
PostfixExpression
A postfix unary expression.
PostfixIncrement
A postfix increment expression.
PrefixDecrement
A prefix decrement expression.
PrefixedIdentifier
An identifier that is prefixed or an access to an object property where the target of the property access is a simple identifier.
PrefixExpression
A prefix unary expression.
PrefixIncrement
A prefix increment expression.
PrimaryConstructorBody
The body of a primary constructor.
PrimaryConstructorDeclaration
The declaration of a primary constructor.
PrimaryConstructorName
The name of a primary constructor.
PropertyAccess
The access of a property of an object.
PropertyAssignmentTarget
A property used as an assignment destination.
PropertyExtraction
A property value selected from a receiver.
ReceiverPropertyAssignmentTarget
A property selected on an explicitly written expression receiver and used as an assignment destination.
ReceiverPropertyExtraction
A property value selected on an explicitly written expression receiver.
RecordFieldReadResolution
A read of a field from a record value.
RecordLiteral
A record literal.
RecordLiteralField
A node that can occur in a RecordLiteral.
RecordLiteralNamedField
A named field in a RecordLiteral.
RecordPattern
A record pattern.
RecordTypeAnnotation
A record type.
RecordTypeAnnotationField
A field in a RecordTypeAnnotation.
RecordTypeAnnotationNamedField
A named field in a RecordTypeAnnotation.
RecordTypeAnnotationNamedFields
The portion of a RecordTypeAnnotation with named fields.
RecordTypeAnnotationPositionalField
A positional field in a RecordTypeAnnotation.
RedirectingConstructorInvocation
The invocation of a constructor in the same class from within a constructor's initialization list.
RegularFormalParameter
A regular formal parameter.
RelationalPattern
A relational pattern.
RestPatternElement
A rest pattern element.
RethrowExpression
A rethrow expression.
ReturnStatement
A return statement.
ScriptTag
A script tag that can optionally occur at the beginning of a compilation unit.
SetOrMapLiteral
A set or map literal.
SetterDeclaration
A setter declaration in an instance declaration body.
SetterInvocationResolution
An invocation of a setter selected for a named write.
ShowCombinator
A combinator that restricts the names being imported to those in a given list.
SimpleIdentifier
A simple identifier.
SimpleStringLiteral
A string literal expression that doesn't contain any interpolations.
SingleStringLiteral
A single string literal expression.
SpreadElement
A spread element.
Statement
A node that represents a statement.
StringInterpolation
A string interpolation literal.
StringLiteral
A string literal expression.
SuperConstructorInvocation
The invocation of a superclass' constructor from within a constructor's initialization list.
SuperExpression
A super expression.
SuperFormalParameter
A super-initializer formal parameter.
SwitchCase
A case in a switch statement.
SwitchDefault
The default case in a switch statement.
SwitchExpression
A switch expression.
SwitchExpressionCase
A case in a switch expression.
SwitchMember
An element within a switch statement.
SwitchPatternCase
A pattern-based case in a switch statement.
SwitchStatement
A switch statement.
SymbolLiteral
A symbol literal expression.
ThisExpression
A this expression.
ThrowExpression
A throw expression.
TopLevelDeclaration
A declaration that can appear directly in a compilation unit in V2.
TopLevelGetterDeclaration
A top-level getter declaration.
TopLevelVariableDeclaration
The declaration of one or more top-level variables of the same type.
TryStatement
A try statement.
TypeAlias
The declaration of a type alias.
TypeAnnotation
A type annotation.
TypeArgumentList
A list of type arguments.
TypedLiteral
A literal that has a type associated with it.
TypeLiteral
An expression representing a type, such as the expression int in var x = int;.
TypeParameter
A type parameter.
TypeParameterList
Type parameters within a declaration.
UnaryOperatorInvocation
An invocation of an overloadable unary operator.
UnqualifiedNameAssignmentTarget
An assignment target consisting of one unqualified name.
UriBasedDirective
A directive that references a URI.
ValidIndexReadResolution
A successful index read resolution.
ValidIndexWriteResolution
A successful index write resolution.
VariableDeclaration
An identifier that has an initial value associated with it.
VariableDeclarationList
The declaration of one or more variables of the same type.
VariableDeclarationStatement
A list of variables that are being declared in a context where a statement is required.
VariablePattern
The shared interface of AssignedVariablePattern and DeclaredVariablePattern.
VariableReadResolution
A direct read of a local variable or formal parameter.
VariableWriteResolution
A direct write to a variable.
WhenClause
A guard in a pattern-based case in a switch statement, switch expression, if statement, or if element.
WhileStatement
A while statement.
WildcardPattern
A wildcard pattern.
WithClause
The with clause in a class declaration.
YieldStatement
A yield statement.

Enums

BinaryOperator
The semantic operation selected by a BinaryOperatorInvocation.
UnaryOperator
The semantic operation selected by a UnaryOperatorInvocation.