public class AstBuilder
extends GroovyParserBaseVisitor
Builds the AST from the parse tree generated by Antlr4.
| Constructor and description |
|---|
AstBuilder(SourceUnit sourceUnit, boolean groovydocEnabled, boolean runtimeGroovydocEnabled)Creates a builder for sourceUnit and allocates its ModuleNode. |
Creates a builder for sourceUnit and allocates its ModuleNode. The lexer
and parser read that source unit. Error recovery follows the compiler configuration, and
the parser uses a descriptive error strategy for that mode. Groovydoc handling is created
from groovydocEnabled and runtimeGroovydocEnabled, and a
try-with-resources transform is attached to this builder.
Adds statements to bs and returns that same block. Each
DeclarationListStatement is flattened into its declaration statements; every other
statement is added as itself.
Builds the ModuleNode by visiting the concrete syntax tree from buildCST.
A failure is converted to a CompilationFailedException. The partial
moduleNode is returned when shouldReturnPartialModuleOnFailure() is true;
otherwise the exception is rethrown. The finally block releases the lexer and
parser and clears the parameter maps kept for this parse.
Visit tree safely, no NPE occurred when the tree is null.
tree - an AST node Builds an additive BinaryExpression (+ or -). The operands go
through createBinaryExpression, which reassociates a repaired parenthesized-name
+ or - so the textual left-to-right grouping is kept. When the expression
is marked as inside a conditional, the node is positioned on the operator token; otherwise
the position is the whole context.
Builds a bitwise BinaryExpression for &.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. When the expression is marked
as inside a conditional, the node is positioned on the operator token;
otherwise the position is the whole context.
Returns the ClassNode for a qualified class name and adds the type annotations
from ctx.
Builds an AnnotationNode for the annotation's class name, positioned on
ctx. The class node itself is positioned on the annotation name. Each element
value is added as a member. A method-pointer value is rewritten to a closure that calls
this.withMethodClosure with that pointer.
Returns the annotation class name by visiting the qualified class name and reading that node's name.
Returns the AnnotationNodes. When none are written the result is an empty list; otherwise each annotation is visited.
Builds the anonymous InnerClassNode. The superclass is the node stored on
ctx, and the outer class is the class being built or, at the top level, the script
class dummy. The generated name is the outer name plus the next anonymous index.
An enum-constant body (ctx.t of 1) is an EnumConstantClassNode;
any other body is an InnerClassNode of the superclass. The class is anonymous,
does not use generics, and is pushed while its body is visited. When that leaves the class
stack empty, the anonymous class is appended to the module's class list.
Returns the argument Expression. A comma with no argument is rejected. An absent
context yields an unpositioned empty ArgumentListExpression. An empty ()
yields an empty argument list positioned on ctx. Otherwise the enhanced argument
list is visited and positioned on ctx.
Returns the initializer Expressions. An absent context yields an empty list.
visitingArrayInitializerCount is raised for the walk, so a command chain inside
the initializer is rejected, and lowered afterwards.
A nested initializer becomes an ArrayExpression of the component type, and that expression's type is then set to the enclosing element type. A variable-initializer child is visited as one; other children are skipped.
Builds an AssertStatement whose condition is a BooleanExpression. An
assignment used as the condition is rejected. visitingAssertStatementCount is
raised before the condition is visited, so a postfix operator inside the assertion is
positioned on the operator, and is lowered on the path that also visits the message
expression.
Builds an assignment BinaryExpression positioned on ctx. A built-in type
name on the left is rejected. A variable wrapped in exactly one set of parentheses becomes
a one-element TupleExpression; deeper parentheses are rejected.
Any other left side must be a variable that is not parenthesized, a property, or an index expression. The right side is the visited expression.
Returns the expression produced by AsyncTransformHelper.transformAsyncClosure,
positioned on ctx. nextClosureIsAsync is set before the closure or lambda
is visited, so that visit records the closure as the body of an async expression.
Returns the expression produced by AsyncTransformHelper.buildAwaitCall for an
unparenthesized await, positioned on ctx.
Returns the expression produced by AsyncTransformHelper.buildAwaitCall for a
parenthesized await, positioned on ctx. As a primary, a following method
call, property or index applies to the awaited value.
Returns the block Statement. An absent context yields an empty block; otherwise
visitBlockStatementsOpt is positioned on ctx.
Returns the nested Statement, or null when the visit returns null.
A MethodNode and an ImportNode are rejected, as is any other non-statement
result.
Builds a BlockStatement of the block's statements, positioned on ctx. A
statement whose visit returns null is dropped.
Returns a BlockStatement positioned on ctx. When statements are present
they are visited; otherwise the block is empty.
Returns a ConstantExpression for true or false, positioned on
ctx.
Builds a BreakStatement. A break whose innermost breakable construct is a
switch expression that produces a value is rejected. The label is the identifier when one
is present, otherwise null.
Returns a VariableExpression of void or a built-in primitive, marked as a
built-in type and positioned on ctx. Any other form is rejected.
Builds the cast Expression, including the parenthesized-name repairs. A bare name
whose final segment does not start with an uppercase letter, followed by unary +
or -, becomes a binary expression marked as a repaired parenthesized-name binary.
A bare name followed by in and a list or map subscript is rebuilt as a binary
in when that shape matches.
super as the operand is rejected. An operand that is the identifier in or
as becomes a CastExpression marked so the command-expression visitor can
restore the binary reading. A repaired parenthesized-name binary is cast on its leading
operand only. Any other operand becomes a CastExpression, and an ambiguous operand
(a unary sign, a prefix, a list, a map, a closure, a method call, or a parenthesized
expression) stores a resolve hint on the cast.
Returns the cast or coercion ClassNode by delegating to visitIntersectionType.
Multi-catch(1..*) clause will be unpacked to several normal catch clauses, so the return type is List
ctx - the parse tree Returns the exception types of a catch. An absent context yields a single dynamic
type; otherwise each qualified class name is visited.
Attaches the enum constants and class-body declarations to the class node stored on
ctx, passing that node down in node metadata. Returns null; the members
are recorded on the class as a side effect.
Adds one class-body member and returns null. A member declaration is visited with
the enclosing class node. A static block is added as a static initializer; an
instance block is added as an object initializer wrapped in a block statement.
Builds the ClassNode for a class, interface, trait, enum, record, or annotation,
positioned on ctx. An enum is built with EnumHelper, including a nested
enum. A nested non-enum type is an InnerClassNode. A top-level non-enum type uses
the package plus the identifier. var, and val when that spelling is
enabled, are rejected as type names.
Annotation, enum, interface, and record declarations reject the clauses and modifiers the
grammar still allows them to carry (type parameters, extends, implements,
sealed, non-sealed, or a header that is not a record header).
sealed together with non-sealed or final is rejected, and
permits is rejected on a type that is not sealed.
The synthetic-public bit is stripped from the modifiers and recorded with
setSyntheticPublic. Generics are applied. Sealed, non-sealed, trait, and record
markers are added as annotations, along with the annotations carried by the modifiers. A
sealed type's permitted subclasses are a list of class expressions when a permits
clause is present. Classes and traits take a single superclass and their interfaces.
Interfaces and annotations receive the interface and abstract modifiers (and static when
nested) and their mixin list is cleared; an annotation also receives the annotation
modifier and the annotation interface. Records turn the header into properties.
The class is pushed while its body is visited. A record is then rejected if it still has an instance field that the header did not generate, or an instance initializer. A top-level class, followed by its inner classes, is appended to the module's class list. Groovydoc is attached, and the class node is returned.
Returns the class-name text of ctx.
Returns one class or interface ModifierNode, positioned on ctx. An
annotation modifier carries the visited annotation node. A keyword modifier carries the
keyword's token type and text. Any other form is rejected.
Returns every class or interface ModifierNode, in source order.
Returns the class or interface ModifierNodes. When none are written the result is an empty list; otherwise each modifier is visited.
Builds a ClosureExpression positioned on ctx. The closure is pushed as a
switch and closure frame, nextClosureIsAsync is recorded on that frame and then
cleared, and visitingClosureCount is raised so this and super
calls inside stay method calls. All three are restored when the visit finishes.
Parameters come from the formal parameter list. Without an arrow they are replaced by
Parameter.EMPTY_ARRAY, and an empty body is positioned on ctx.
Returns a ClosureExpression positioned on ctx. A closure and a lambda are
each visited by their own method; a lambda is a LambdaExpression. Any other form
is rejected.
Returns the coercion ClassNode. A parenthesized cast type is visited as a cast; otherwise the type is visited directly.
Builds the next Expression of a command chain from the base expression stored on
ctx.
An argument list becomes a MethodCallExpression with implicit this turned
off, using the primary as the method name. A property-expression base in that form is
rejected. A path element becomes a property of the base, then the remaining path.
Otherwise the result is a PropertyExpression, and a variable primary is turned
into a constant name.
Returns an ExpressionStatement for a command expression, positioned on
ctx. A SwitchExpression that is the whole statement and either has an
incomplete arrow arm or whose value is unused is rewritten to a SwitchStatement
first, so statement position does not produce a value.
Builds the Expression for a command expression. A command chain inside an array
initializer is rejected. A cast of the identifier in or as followed only
by an argument list is rewritten by repairBinaryKeywordCast when that rewrite
succeeds; otherwise the cast is kept and a resolve hint is attached.
A binary base that is not a subscript and not parenthesized is rejected. When that binary
is < between two type-like operands and an argument list follows, the error is a
missing > anchored on the argument list.
An argument list turns a property into a method call, keeps an existing method call, turns
a variable, a gstring, or a string constant into a method call after rejecting a call that
looks like a method definition, and otherwise calls call. The call is marked as a
command expression. Further command arguments are folded by visitCommandArgument,
each receiving the expression so far as its base.
Stores a record's compact-constructor body as the pre closure of its
TupleConstructor annotation and returns null. The declaration is rejected
outside a record, when a modifier is val or var, or when the name differs
from the record name.
The body is walked, and a property expression whose receiver text is this and
whose property names a record component is rejected. An existing tuple-constructor
annotation is reused; otherwise a new one is added.
Builds the ModuleNode for a compilation unit. The package declaration is visited, then each script statement is added as a statement (a declaration list is flattened into its statements) or as a method, and every class collected during the walk is added.
A package-info.groovy source gains a package-info class when the module
does not already contain one. A module with no classes, methods, or statements receives
ReturnStatement.RETURN_NULL_OR_VOID. The script class dummy, when present, takes
its source position from the first and last statements. A number-format error recorded
while visiting literals is thrown after the module is assembled.
Builds a conditional Expression. ?: becomes an
ElvisOperatorExpression. The false branch is marked as inside a
conditional before it is visited.
A ? : expression is a TernaryExpression whose condition is a
BooleanExpression. Both the true and false branches are marked as inside a
conditional before they are visited, which makes a shift or arithmetic operator inside
them take the operator's source position.
Returns the Statement for an if/else or a switch,
positioned on ctx. Any other conditional form is rejected.
Builds a ContinueStatement. A continue whose innermost breakable construct
is a switch expression that produces a value is rejected. The label is the identifier when
one is present, otherwise null.
Returns the created ClassNode, with the type annotations from ctx added. A
primitive name is visited as a primitive. Any other name is the parameterized class type
from visitParameterizedClassType (type arguments or a diamond, without forcing a
raw enclosing type). An unrecognised name is rejected.
Builds a creation Expression positioned on ctx. With arguments, the result
is a ConstructorCallExpression. An enclosing instance is inserted as the first
positional argument and is rejected for named arguments. When that instance is itself a
constructor call and the created name contains no dot, the created name is prefixed with
the instance's type name. An anonymous body is visited with the created type as its
superclass, recorded when the creation is inside a method, and the call is marked as using
an anonymous inner class. Constructor type arguments stored on ctx are set on the
call.
A sized array is an ArrayExpression of the given sizes, with an empty expression for each unsized dimension, and dimension annotations are applied from the array type down through its array components. An initializer form wraps the element type for the inner dimensions, visits the initializer with that element type, and puts the outermost dimension's annotations on the expression's array type.
Builds an ExpressionStatement whose expression is the call produced by
AsyncTransformHelper.buildDeferCall. defer is rejected unless the
innermost closure or lambda frame is the closure of an async expression; a nested
closure inside that frame gets a distinct error.
A closure expression is passed through as the action. Any other statement expression is wrapped in a closure whose body is that statement and whose source position is the statement.
Builds a DoWhileStatement from the parenthesized condition and the unpacked body,
adds any statement annotations, and positions the node on ctx.
Returns the dynamic member Expression, positioned on ctx: a parenthesized
expression or a gstring. Any other form is rejected.
Returns one annotation value Expression, positioned on ctx: a visited
expression, an AnnotationConstantExpression for a nested annotation, or the list
from an array initializer. Any other form is rejected.
Builds a ListExpression of the element values, positioned on ctx.
Returns the member name paired with its Expression. The name is the pair-name text, and the value is visitElementValue.
Returns the annotation members as a map from name to Expression, in source order. A duplicate name is rejected.
Returns the annotation member names paired with their Expressions. An absent
context yields an empty list. Named pairs are visited as pairs. A single unnamed value is
stored under the name value.
Returns one argument Expression, positioned on ctx: an expression-list
element, a lambda, or a map entry. Any other form is rejected.
Returns the argument Expression, or null when ctx is absent.
Positional arguments become an ArgumentListExpression. Named arguments alone
become a TupleExpression holding a NamedArgumentListExpression. A mix
becomes an argument list whose first expression is a MapExpression of the named
arguments. A duplicated named argument is rejected unless its key is parenthesized.
Returns an Expression positioned on ctx. An expression child is visited as
an expression, and a lambda is visited as a lambda. Any other form is rejected.
Returns a Function that builds a for-each ForStatement. The optional index parameter and the value parameter (type, name, and modifiers) are captured now. The collection expression is visited only when that function is applied.
Returns an Expression positioned on ctx. A statement expression is visited
and unwrapped from its ExpressionStatement. A lambda is visited as a lambda. Any
other form is rejected.
Builds the enum-constant FieldNode and adds it to the enum class. An anonymous
body is visited with the enum as its superclass and becomes part of the constant's
initializer. Annotations and groovydoc are attached, and the field is positioned on
ctx.
Returns the FieldNodes of the enum constants. The enclosing class node is copied onto each constant context before it is visited.
Builds an equality BinaryExpression (==, !=, ===,
!==, or <=>). The operands are combined by
createBinaryExpression. No regrouping applies to this operator.
The source position is the whole context.
Builds a bitwise BinaryExpression for ^.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. When the expression is marked
as inside a conditional, the node is positioned on the operator token;
otherwise the position is the whole context.
Returns the Expression inside parentheses by delegating to visitEnhancedStatementExpression. This method does not itself set a source position.
Returns the list's Expressions. An absent context yields an empty list; otherwise each element is visited.
Returns one list Expression, positioned on ctx. A command call with
implicit this whose name is a primitive or starts with an uppercase letter is
rejected as a method declaration. A * wraps the expression in a
SpreadExpression when spreading is allowed here, and is rejected otherwise.
Adds the variable declaration as a field or property of the enclosing class and returns
null. The class node is stored on the variable-declaration context before
visitVariableDeclaration runs.
Returns the finally Statement. An absent context yields
EmptyStatement.INSTANCE; otherwise the block is wrapped in a block statement and
positioned on ctx.
Returns a numeric ConstantExpression for the floating-point literal, remembering
the original text. A parse failure is stored in numberFormatError and the
constant's value is left null; the failure is reported later from the compilation unit.
The constant is positioned on ctx.
Returns the Function that builds a ForStatement from a loop body. An enhanced for-control and a classic for-control are dispatched to their own visitors; any other form is rejected.
Returns the init Expression of a classic for. An absent context yields
EmptyExpression.INSTANCE. A local-variable declaration becomes that single
declaration, or a ClosureListExpression when several are declared together. An
expression list becomes one expression, or a ClosureListExpression when it has
more than one element.
Builds a ForStatement from visitForControl applied to the unpacked body,
then adds any statement annotations. When await is present the statement is
wrapped by AsyncTransformHelper.wrapForAwaitLoop and positioned on ctx.
Returns the update Expression of a classic for. An absent context yields
EmptyExpression.INSTANCE; otherwise the expression list becomes one expression, or
a ClosureListExpression when it has more than one element.
Returns one Parameter by delegating to processFormalParameter. The type is
visited, a var-arg type becomes an array type, modifiers are applied, and a default
expression is set when present. The parameter and its modifier manager are kept in the
builder's parameter maps rather than on the parameter.
Returns the Parameters. An absent context yields Parameter.EMPTY_ARRAY. A
receiver (this) parameter is first when present, then each formal parameter. A
var-arg parameter that is not last is rejected, and a duplicated name is rejected; the
name _ is not compared.
Returns the Parameters. An absent context yields Parameter.EMPTY_ARRAY; otherwise the formal parameter list is visited.
Builds a GStringExpression positioned on ctx. The begin, each part, and
the end are parsed as string constants by restoring the opening quotation around each
fragment. The values are the visited gstring values.
The verbatim text interleaves those strings and values. A variable value is appended as
$name; any other value is appended inside braces after $. An empty value
is skipped.
Returns the Expression for a $name or $name.prop path, positioned
on ctx. The identifier is a VariableExpression. Each following path part,
with its leading character removed, becomes a constant property folded onto that variable.
Returns one gstring value Expression. A path is visited as a gstring path.
A closure with no arrow contributes its single expression when the body is one expression
statement that is not a declaration, a null constant when the body is empty, and otherwise
a call of the closure with implicit this. A closure that has an arrow is
returned as the closure.
Returns the identifier text of ctx.
Returns a primary Expression positioned on ctx. With type arguments the
identifier is a ClassExpression whose generics are those arguments. Without them
it is a VariableExpression of the identifier.
Builds an IfStatement. The parenthesized condition becomes a
BooleanExpression. The then and else statements are unpacked, and a missing
else is EmptyStatement.INSTANCE.
Builds an implication BinaryExpression for ==>.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. The source position is the whole context.
Returns the ImportNode just added to the module, positioned on ctx.
Annotations are collected first. A module import is expanded by
expandModuleImport.
A static star import, a static member import, a type star import, or a single-type import is recorded on the module. An alias, when present, is the simple name; otherwise the simple name is the member or the last name element. For a static member import the imported type's end position stops before the member name.
Builds a bitwise BinaryExpression for |.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. When the expression is marked
as inside a conditional, the node is positioned on the operator token;
otherwise the position is the whole context.
Returns the index token (the bracket or the safe-index symbol) paired with the index
Expression. One element is that expression, unless it is a spread, in which case
it is an unwrapped one-element list. Several elements become a wrapped
ListExpression positioned on ctx.
Builds the index Parameter of a for-each loop. A built-in primitive whose spelling
is not three characters is rejected. The parameter type is int, the name is the
identifier, and the parameter is final.
Returns a numeric ConstantExpression for the integer literal, remembering the
original text. A parse failure is stored in numberFormatError and the constant's
value is left null; the failure is reported later from the compilation unit. The constant
is positioned on ctx.
Returns the cast type. A single component is that type unchanged. Several components
become an IntersectionTypeClassNode positioned on ctx, and a repeated
component name is rejected.
Builds the VariableExpression for a map-style multi-assignment target
(key: name), positioned on ctx. def, val, and var
produce the dynamic type; a written type is visited. val adds the final modifier,
and the key identifier is stored as the map-key metadata.
Returns a ConstantExpression of the keyword text, positioned on ctx.
Returns the nested Statement after adding the identifier as a statement label. The statement node itself is not rebuilt.
Returns the lambda body Statement, positioned on ctx. A block is visited
as a block; otherwise the statement expression is visited as a statement and is not
unwrapped.
Builds a ListExpression from the expression list, positioned on ctx. A
comma in an otherwise empty list is rejected.
Returns the declaration-list statement from visitVariableDeclaration, positioned
on ctx.
Builds a logical BinaryExpression for &&.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. The source position is the whole context.
Builds a logical BinaryExpression for ||.
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. The source position is the whole context.
Returns the loop Statement, positioned on ctx. The loop context is pushed
as the innermost breakable construct while its statement is visited, then popped.
Builds a MapExpression from visitMapEntryList, positioned on ctx.
Builds a MapEntryExpression positioned on ctx. A * key is a
SpreadMapExpression of the value. Otherwise the key is visitMapEntryLabel
and the value is the enhanced expression.
Returns the key Expression, positioned on ctx. A keyword is a constant of
its text. A primary is visited, and a VariableExpression that is not parenthesized
is replaced by a ConstantExpression of its name, so a bare map key is a constant.
Returns the MapEntryExpressions. An absent context yields an empty list; otherwise each map entry is visited.
Returns a ClassExpression for the plain type on the right of instanceof,
positioned on ctx. When the context is marked as inside instanceof, that
flag is copied onto the type before it is visited. A pattern on the right is built
elsewhere.
Dispatches one member and returns null. A method, field, or compact constructor is
visited with the enclosing class node; the compact constructor also receives the member's
modifiers. A nested type declaration receives those modifiers and is positioned on
ctx.
Returns the method body Statement. An absent context yields null;
otherwise the block is visited and positioned on ctx.
Builds the MethodNode or constructor for a class member or a script method. The return type, parameters, and exceptions are visited, and anonymous classes created while the body is visited are given this method as their enclosing method.
A declaration whose context carries a class node is added to that class, after interface
parameters are checked for default values. A script declaration is public unless the
private modifier is present, and the modifier manager then processes the node. Generics
are set from the type parameters, synthetic-public is set from isSyntheticPublic,
and a static method marks its parameters and variable scope as static. The node is
positioned on ctx, validated, and given groovydoc.
Returns the method name. An identifier is visited as an identifier, and a string literal contributes its parsed text. Any other form is rejected.
Returns one ModifierNode, positioned on ctx. A class or interface modifier
is visited as one. A keyword modifier carries the keyword's token type and text. Any other
form is rejected.
Returns every ModifierNode, in source order.
Returns the ModifierNodes. When none are written the result is an empty list; otherwise visitModifiers is used.
Builds a multiple-assignment BinaryExpression positioned on ctx. The left
side is the tuple from visitVariableNames. The right side is visited as a
statement and unwrapped to its expression.
Builds a multiplicative BinaryExpression (*, /, or %). The
operands go through createBinaryExpression, which reassociates a repaired
parenthesized-name + or - so the textual left-to-right grouping is kept.
When the expression is marked as inside a conditional, the node is positioned on the
operator token; otherwise the position is the whole context.
Returns the name Expression, positioned on ctx. An identifier or a keyword
becomes a ConstantExpression of its text, a string literal is parsed as a string,
and a dynamic member name is visited as one. Any other form is rejected.
Returns the MapEntryExpressions of a named bracket argument by delegating to visitMapEntryList.
Returns the creator Expression, positioned on ctx. Explicit constructor
type arguments, when present, are stored on the creator context before
visitCreator runs.
Returns the explicit type arguments as GenericsTypes. An absent context yields
null; otherwise each type in the list is wrapped as a generics type.
Returns a ConstantExpression whose value is null, positioned on ctx.
Returns a Function that builds a classic ForStatement. Init, condition, and update are visited immediately and stored in a ClosureListExpression; a missing condition is EmptyExpression.INSTANCE. That list is positioned on the for-control, including the semicolons, and the function only attaches the body.
Returns the module's PackageNode. The qualified name plus a trailing dot is set as
the package name, annotations from the declaration are copied onto the node, and the node
is positioned on ctx.
Returns the parenthesized Expression, positioned on the parentheses. The inside-parentheses level stored on the inner expression is incremented first.
Builds one step of a path Expression from the base expression stored on
ctx.
A name part with ., ?., or ??. becomes an
AttributeExpression when @ is present and a PropertyExpression
otherwise. Safe-chain (??.) also marks the result so a later element stays safe.
.& is a MethodPointerExpression, :: is a
MethodReferenceExpression, and a spread dot sets the spread-safe flag. A creator
is visited with the base as its enclosing instance and with any explicit type arguments
stored for the constructor.
An index becomes a subscript BinaryExpression, safe when the base is a safe chain
or the index itself is safe. A named bracket argument becomes a subscript whose right side
is an empty spread map, a single spread-map key, or a wrapped list of entries. An argument
list on a property becomes a method call of that property. A parenthesized base, an
attribute, void, or any other base that is not a name calls call; an
attribute call clears spread-safe and uses implicit this. A primitive type name is
rejected. this or super is a constructor call unless it is inside a
closure, where it stays a method call. A variable, gstring, or string constant is a method
call of that name. A trailing closure is appended to an existing argument list, or starts
a call, and named arguments are rewritten as a map expression plus that closure.
Returns the path Expression. The keyword static becomes a
VariableExpression of that text; otherwise the primary is visited.
createPathExpression then folds each path element, threading the expression so far
and copying a safe-chain flag forward.
Returns the path Expression, or a PostfixExpression when an operator is
present. Inside an assertion the postfix node is positioned on the operator token;
otherwise it is positioned on ctx.
Builds a power BinaryExpression (**). The operands go through
createBinaryExpression, which reassociates a repaired parenthesized-name +
or - so the textual left-to-right grouping is kept. When the expression is marked
as inside a conditional, the node is positioned on the operator token; otherwise the
position is the whole context.
Returns a plain ClassNode for the primitive named by ctx, positioned on
ctx.
Returns the ClassNode for a qualified class name from createClassNode.
Inside instanceof the node is not given a redirect; otherwise a generics-using
name is proxied. The node is positioned on ctx.
Returns the ClassNodes of an annotated qualified-name list. An absent context yields ClassNode.EMPTY_ARRAY; otherwise each annotated name is visited.
Returns the qualified name formed by joining each name element with a dot.
Returns the ClassNode for a qualified standard class name from
createClassNode. Inside instanceof the node is not given a redirect;
otherwise a generics-using name is proxied. The node is positioned on ctx.
Returns the reference ClassNode from visitParameterizedClassType,
positioned on ctx. A raw enclosing type is recorded when type arguments follow a
qualified name.
Builds a regex BinaryExpression (=~ or ==~).
The operands are combined by createBinaryExpression.
No regrouping applies to this operator. The source position is the whole context.
Builds the relational Expression. as is a coercion, and coercing
super is rejected. instanceof is a BinaryExpression whose
right side comes from visitMatchingType: a type with a binding is a
declaration of that name, and a plain type is a class expression. The type context
is marked as inside instanceof before it is visited.
!instanceof of a matching type is also a binary expression, with the same
right-hand side rules. !instanceof of a parenthesized intersection is
rejected, and a parenthesized type is marked as inside instanceof before
it is visited and used as a class expression. Comparisons and in / !in
are binary expressions built like the other arithmetic operators, including the
conditional source-position rule.
Returns the ExpressionStatement for one try-with-resources resource. A local-variable declaration is used as-is and must declare exactly one variable.
An expression must be an assignment to a variable or a bare variable. A bare variable is
rewritten by the try-with-resources transform. Either form is then rebuilt as a
DeclarationExpression whose left side is a VariableExpression of the
assignment's left text, and that declaration is wrapped in an ExpressionStatement
positioned on ctx.
Returns one ExpressionStatement per resource, in source order, by visiting each
resource child.
Returns the resource ExpressionStatements of a try-with-resources header by delegating to visitResourceList.
Builds a ReturnStatement. A return inside a switch expression that
produces a value is rejected. A missing expression is
ConstantExpression.EMPTY_EXPRESSION.
Returns the method's return ClassNode. An absent context yields the dynamic type.
A type is visited as a type. void is a plain void node positioned on the keyword,
and is rejected for an annotation element. Any other form is rejected.
Returns the script's top-level ASTNodes. An absent context yields an empty list;
otherwise each scriptStatement child is visited.
Builds a shift or range Expression. A range operator becomes a
RangeExpression whose left endpoint is exclusive when the operator text starts
with < and whose right endpoint is exclusive when it ends with <.
<<, >>, and >>> become a BinaryExpression whose operator
text is the bracket repeated two or three times. When the expression is marked as inside a
conditional, that binary is positioned on the operator token; otherwise it is positioned
on ctx.
Builds a LambdaExpression positioned on ctx. The lambda is pushed as a
switch and closure frame, and nextClosureIsAsync is recorded on that frame and
then cleared, so a nested closure is not itself async. Both frames are popped when the
visit finishes.
Returns the lambda's Parameters. A single variable name becomes one dynamic-typed
parameter positioned on that name. A formal parameter list is visited, and an empty list
is returned as null rather than an empty array.
Returns a ConstantExpression for the parsed string contents, marked as a string
and positioned on ctx. Quotation marks are stripped, multiline text loses carriage
returns, and escapes are decoded for the literal's slashy kind.
Returns a VariableExpression of the super keyword, positioned on
ctx. Explicit type arguments, when present, are stored on that variable for a
later constructor call.
Returns the case and default Statements of one switch-expression group. The group must have a label, and an arrow label cannot share the group with another label.
The arm is built by switchExpressionArm: an arrow arm must be a single statement,
an expression statement becomes a YieldStatement, and an empty arrow arm is kept
only when the enclosing switch is in statement position. Only the last label receives that
arm; earlier labels in the group get an empty statement. A default arm is marked
as the switch default.
Returns the Statements for one switch group, one per label. The last case
label carries the group body when a body is present; earlier case labels get
EmptyStatement.INSTANCE and are positioned on the group's first case
token.
A default label is the group body, or a fresh empty statement positioned on the
default token when the group has no body. That statement is marked as the switch
default and remembers the keyword token.
Returns the SwitchExpression from visitSwitchExpression, positioned on
ctx.
Builds a SwitchExpression as specified by JEP 361.
Arrow arms that are a single expression become YieldStatements;
colon arms use explicit yield.
Returns the label descriptor from switchExpressionLabel: the case or
default keyword, the label expressions, and the colon or arrow separator.
A pattern label is visited as a pattern expression and must use the arrow form. A colon
label that is a zero-argument call, or a list or map literal that is not pattern-shaped,
is rebuilt as that legacy expression; a when guard on such a list or map is
rejected. A plain case uses the expression list, and default uses an empty
expression.
Returns the keyword Token paired with its label Expression. case
visits the expression; default uses EmptyExpression.INSTANCE. Any other
label is rejected.
Builds a SwitchStatement whose selector is the parenthesized expression. The switch context is pushed while the groups are visited. Each group is flattened into case statements and at most one default statement.
A second default is rejected, and a default that is not the last branch is rejected. The error is anchored on the default keyword when that token was recorded. A missing default is EmptyStatement.INSTANCE.
Builds a SynchronizedStatement from the parenthesized expression and the block,
positioned on ctx.
Returns the receiver Parameter: the visited type with the name this,
positioned on ctx. Modifiers and a default value are not applied.
Returns a VariableExpression of the this keyword, positioned on
ctx. Explicit type arguments, when present, are stored on that variable for a
later constructor call.
Builds a ThrowStatement for the visited expression, positioned on ctx.
Builds a TryCatchStatement. A try with neither resources, a catch,
nor a finally is rejected. Resources and every catch clause are added (multi-catch
clauses are flattened into one list), a missing finally is empty, and the node is
positioned on ctx, the try-with-resources transform is applied, and the result is
positioned on ctx again.
Returns the ClassNode for a type. An absent context yields the dynamic type, and
void is rejected. A primitive or a reference type is visited, type annotations are
added, and each array dimension wraps the type and contributes its annotations.
When the type is inside instanceof, that flag is copied onto the reference type
and a non-reifiable result is rejected. The node is positioned on ctx.
Builds one GenericsType positioned on ctx. A ? is a wildcard whose
base type carries the annotations written on the question mark; extends sets the
upper bound and super sets the lower bound. A plain type is wrapped as a
non-wildcard generics type. Any other form is rejected.
Returns one GenericsType per type argument, in source order.
Returns the GenericsTypes of a type-argument list or a diamond. Written arguments
are visited. A diamond (<>) yields GenericsType.EMPTY_ARRAY. Any other
form is rejected.
Returns the upper-bound ClassNodes of a type parameter. An absent context yields
null; otherwise each bound type is visited.
Returns the ClassNode for a class, interface, trait, enum, record, or annotation
declaration. The class-or-interface modifiers are stored on the class-declaration context
before it is visited, and the result is positioned on ctx. Any other type
declaration is rejected.
Returns the ClassNodes of a type list. An absent context yields ClassNode.EMPTY_ARRAY; otherwise each type is visited.
Builds the VariableExpression for one multi-assignment target, positioned on
ctx. def, val, and var produce the dynamic type; a written
type is visited. val adds the final modifier. A * marks the variable as a
rest binding.
Returns the target Expressions of a multi-assignment. Keyed pairs are visited as
keyed pairs. Otherwise each type-name pair is visited, and a second rest binding
(*) is rejected.
Builds one GenericsType. The parameter's class node carries the annotations
written on the name, and its bounds are the types from visitTypeBound. The
generics type is positioned on ctx.
Returns the declared GenericsTypes. An absent context yields null rather
than an empty array; otherwise each type parameter is visited.
Builds the unary Expression for +, -, ++, or --.
When the operand is a repaired parenthesized-name + or - that is not
itself parenthesized, only that binary's leading operand is wrapped.
Unary + on a non-string constant that is not parenthesized returns that constant,
positioned on ctx, instead of a UnaryPlusExpression. Unary - on
such a constant parses the negated integer or decimal text, clears
numberFormatError when that parse succeeds, and returns the resulting constant; a
missing original literal text is a failure. ++ and -- are a
PrefixExpression.
Builds a NotExpression for ! or a BitwiseNegationExpression for
~, positioned on ctx. When the operand is a repaired parenthesized-name
+ or - that is not itself parenthesized, only that binary's leading
operand is wrapped and the binary is returned.
Returns a declaration-list statement for a local declaration, or null when the
declaration is a field or property of a class. Modifiers are collected first. A
parenthesized type-name or keyed list is a multi-assignment declaration.
Otherwise the shared variable type is stored on the declarator list and each declarator is
visited. For a class, the resulting declarations are added as fields or properties. For a
local declaration, modifiers and annotations are applied to each variable, the
single-declarator form is positioned on ctx, and the first of several declarators
has its start moved to the start of ctx.
Builds a DeclarationExpression positioned on ctx. The variable's name and
the shared type make a VariableExpression positioned on the declarator id. The
operator is the written =, or a synthetic assign token when no initializer is
written. The right side is visitVariableInitializer.
Returns a VariableExpression of the identifier, positioned on ctx. A
built-in type name used as the identifier is rejected.
Returns one DeclarationExpression per declarator. The shared variable type stored
on ctx is copied onto each declarator before it is visited.
Returns the initializer Expression. An absent context yields
EmptyExpression.INSTANCE; otherwise the enhanced statement expression is visited
and positioned on ctx.
Returns one variable ModifierNode, positioned on ctx. An annotation
modifier carries the visited annotation node. A keyword modifier carries the keyword's
token type and text. Any other form is rejected.
Returns every variable ModifierNode, in source order.
Returns the variable ModifierNodes. When none are written the result is an empty list; otherwise each modifier is visited.
Builds a TupleExpression of the variable names, positioned on ctx. Each
name is a VariableExpression from visitVariableDeclaratorId.
Builds a WhileStatement from the parenthesized condition and the unpacked body,
adds any statement annotations, and positions the node on ctx.
Builds an ExpressionStatement whose expression is the call produced by
AsyncTransformHelper.buildYieldReturnCall for the visited expression.
Builds a YieldStatement for the visited expression, positioned on ctx.
Returns the YieldStatement from visitYieldStatement, positioned on
ctx.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.