CompilationUnit class abstract final

A compilation unit.

While the grammar restricts the order of the directives and declarations within a compilation unit, this class doesn't enforce those restrictions. In particular, the children of a compilation unit are visited in lexical order even if lexical order doesn't conform to the restrictions of the grammar.

compilationUnit ::= directives declarations

directives ::= ScriptTag? LibraryDirective? namespaceDirective* PartDirective* | PartOfDirective

namespaceDirective ::= ImportDirective | ExportDirective

declarations ::= CompilationUnitMember*

Implemented types

Constructors

CompilationUnit()

Properties

beginToken Token
The first (non-EOF) token in the token stream that was parsed to form this compilation unit.
no setteroverride
childEntities Iterable<SyntacticEntity>
An iterator that can be used to iterate through all the entities (either AST nodes or tokens) that make up the contents of this node, including doc comments but excluding other comments.
no setterinherited
declarations NodeList<CompilationUnitMember>
The declarations contained in this compilation unit.
no setter
declaredElement CompilationUnitElement?
The element associated with this compilation unit, or null if the AST structure hasn't been resolved.
no setter
directives NodeList<Directive>
The directives contained in this compilation unit.
no setter
end int
The offset of the character immediately following the last character of this node's source range.
no setterinherited
endToken Token
The last token in the token stream that was parsed to form this compilation unit.
no setteroverride
featureSet FeatureSet
The set of features available to this compilation unit.
no setter
hashCode int
The hash code for this object.
no setterinherited
isSynthetic bool
Whether this node is a synthetic node.
no setterinherited
languageVersionToken LanguageVersionToken?
The language version override specified for this compilation unit using a token like '// @dart = 2.7', or null if no override is specified.
no setter
length int
Return the number of characters in the syntactic entity's source range.
no setterinherited
lineInfo LineInfo
The line information for this compilation unit.
no setter
offset int
Return the offset from the beginning of the file to the first character in the syntactic entity.
no setterinherited
parent AstNode?
Returns this node's parent node, or null if this node is the root of an AST structure.
no setterinherited
root AstNode
The node at the root of this node's AST structure.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scriptTag ScriptTag?
The script tag at the beginning of the compilation unit, or null if there's no script tag in this compilation unit.
no setter
sortedDirectivesAndDeclarations List<AstNode>
A list containing all of the directives and declarations in this compilation unit, sorted in lexical order.
no setter

Methods

accept<E>(AstVisitor<E> visitor) → E?
Use the given visitor to visit this node.
inherited
findPrevious(Token target) Token?
Returns the token before target, or null if it can't be found.
inherited
getProperty<E>(String name) → E?
Returns the value of the property with the given name, or null if this node doesn't have a property with the given name.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setProperty(String name, Object? value) → void
Set the value of the property with the given name to the given value.
inherited
thisOrAncestorMatching<E extends AstNode>(bool predicate(AstNode)) → E?
Returns either this node or the most immediate ancestor of this node for which the predicate returns true, or null if there's no such node.
inherited
thisOrAncestorOfType<E extends AstNode>() → E?
Returns either this node or the most immediate ancestor of this node that has the given type, or null if there's no such node.
inherited
toSource() String
Returns a textual description of this node in a form approximating valid source.
inherited
toString() String
A string representation of this object.
inherited
visitChildren(AstVisitor visitor) → void
Use the given visitor to visit all of the children of this node.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited