@AutoFinal
@CompileStatic
class AstNodeToScriptVisitor
extends Object
implements GroovyClassVisitor, GroovyCodeVisitor, IPrimaryClassNodeOperation
An adapter from ASTNode tree to source code.
| Type | Name and description |
|---|---|
String |
_indentCurrent indentation prefix. |
Stack<String> |
classNameStackStack of nested class names used while rendering constructors. |
boolean |
readyToIndentIndicates whether the next write should emit indentation first. |
boolean |
scriptHasBeenVisitedTracks whether the free-form script body has already been emitted. |
boolean |
showScriptClassWhether the generated script class should be rendered. |
boolean |
showScriptFreeFormWhether free-form script statements should be rendered. |
| Constructor and description |
|---|
AstNodeToScriptVisitor(Writer writer, boolean showScriptFreeForm, boolean showScriptClass)Creates a visitor that renders AST nodes as Groovy source. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
call(SourceUnit source, GeneratorContext context, ClassNode classNode)Renders the supplied primary class node and optional script body. |
|
Object |
indented(Closure block)Executes the supplied block one indentation level deeper. |
|
void |
print(Object parameter)Writes text, applying the current indentation rules. |
|
Object |
printDoubleBreak()Ensures the output ends with a blank line. |
|
Object |
printLineBreak()Ensures the output ends with a single line break. |
|
Object |
println(Object parameter)This visitor writes directly to its target and does not support println-style output. |
|
void |
visitAnnotationNode(AnnotationNode node)Renders an annotation and its members. |
|
void |
visitArgumentlistExpression(ArgumentListExpression expression, boolean showTypesIgnored)Retained for compatibility; delegates to visitArgumentlistExpression(ArgumentListExpression). |
|
void |
visitArgumentlistExpression(ArgumentListExpression expression)Renders an argument list expression. |
|
void |
visitArrayExpression(ArrayExpression expression)Renders an array expression. |
|
void |
visitAssertStatement(AssertStatement statement)Renders an assert statement. |
|
void |
visitAttributeExpression(AttributeExpression attributeExpression)Renders an attribute access expression. |
|
void |
visitBinaryExpression(BinaryExpression expression)Renders a binary or assignment expression. |
|
void |
visitBitwiseNegationExpression(BitwiseNegationExpression expression)Renders a bitwise negation expression. |
|
void |
visitBlockStatement(BlockStatement block)Renders a block statement. |
|
void |
visitBooleanExpression(BooleanExpression expression)Renders a boolean expression. |
|
void |
visitBreakStatement(BreakStatement statement)Renders a break statement. |
|
void |
visitBytecodeExpression(BytecodeExpression expression)Emits a placeholder for a bytecode expression. |
|
void |
visitCaseStatement(CaseStatement statement)Renders a switch case. |
|
void |
visitCastExpression(CastExpression expression)Renders a cast or coercion expression. |
|
void |
visitCatchStatement(CatchStatement statement)Renders a catch clause. |
|
void |
visitClass(ClassNode node)Renders a class or interface declaration. |
|
void |
visitClassExpression(ClassExpression expression)Renders a class literal expression. |
|
void |
visitClosureExpression(ClosureExpression expression)Renders a closure expression. |
|
void |
visitClosureListExpression(ClosureListExpression expression)Renders a closure list expression. |
|
void |
visitConstantExpression(ConstantExpression expression, boolean unwrapQuotes)Renders a constant expression. |
|
void |
visitConstructor(ConstructorNode node)Renders a constructor declaration. |
|
void |
visitConstructorCallExpression(ConstructorCallExpression expression)Renders a constructor invocation expression. |
|
void |
visitContinueStatement(ContinueStatement statement)Renders a continue statement. |
|
void |
visitDeclarationExpression(DeclarationExpression expression)Renders a declaration expression. |
|
void |
visitDoWhileLoop(DoWhileStatement statement)Renders a do/while-loop statement. |
|
void |
visitExpressionStatement(ExpressionStatement statement)Renders a standalone expression statement. |
|
void |
visitField(FieldNode node)Renders a field declaration. |
|
void |
visitFieldExpression(FieldExpression expression)Renders a field reference expression. |
|
void |
visitForLoop(ForStatement statement)Renders a for-loop statement. |
|
void |
visitGStringExpression(GStringExpression expression)Renders a GString expression. |
|
void |
visitIfElse(IfStatement ifElse)Renders an if/else statement. |
|
void |
visitImport(ImportNode node)Writes an import declaration. |
|
void |
visitLambdaExpression(LambdaExpression expression)Renders a lambda expression. |
|
void |
visitListExpression(ListExpression expression)Renders a list expression. |
|
void |
visitMapEntryExpression(MapEntryExpression expression)Renders a map entry expression. |
|
void |
visitMapExpression(MapExpression expression)Renders a map expression. |
|
void |
visitMethod(MethodNode node)Renders a method or initializer declaration. |
|
void |
visitMethodCallExpression(MethodCallExpression expression)Renders a method call expression. |
|
void |
visitMethodPointerExpression(MethodPointerExpression expression)Renders a method pointer expression. |
|
void |
visitMethodReferenceExpression(MethodReferenceExpression expression)Renders a method reference expression. |
|
void |
visitNotExpression(NotExpression expression)Renders a logical negation expression. |
|
void |
visitPackage(PackageNode packageNode)Writes the package declaration for the current source unit. |
|
void |
visitPostfixExpression(PostfixExpression expression)Renders a postfix expression. |
|
void |
visitPrefixExpression(PrefixExpression expression)Renders a prefix expression. |
|
void |
visitProperty(PropertyNode node)Skips property rendering because fields already emit the corresponding output. |
|
void |
visitPropertyExpression(PropertyExpression expression)Renders a property access expression. |
|
void |
visitRangeExpression(RangeExpression expression)Renders a range expression. |
|
void |
visitReturnStatement(ReturnStatement statement)Renders a return statement. |
|
void |
visitShortTernaryExpression(ElvisOperatorExpression expression)Renders an Elvis expression. |
|
void |
visitSpreadExpression(SpreadExpression expression)Renders a spread expression. |
|
void |
visitSpreadMapExpression(SpreadMapExpression expression)Renders a spread-map expression. |
|
void |
visitStaticMethodCallExpression(StaticMethodCallExpression expression)Renders a static method call expression. |
|
void |
visitSwitch(SwitchStatement statement)Renders a switch statement. |
|
void |
visitSynchronizedStatement(SynchronizedStatement statement)Renders a synchronized statement. |
|
void |
visitTernaryExpression(TernaryExpression expression)Renders a ternary expression. |
|
void |
visitThrowStatement(ThrowStatement statement)Renders a throw statement. |
|
void |
visitTryCatchFinally(TryCatchStatement statement)Renders a try/catch/finally statement. |
|
void |
visitTupleExpression(TupleExpression expression)Renders a tuple expression. |
|
void |
visitType(ClassNode classNode)Prints out the type, safely handling arrays. |
|
void |
visitUnaryMinusExpression(UnaryMinusExpression expression)Renders a unary minus expression. |
|
void |
visitUnaryPlusExpression(UnaryPlusExpression expression)Renders a unary plus expression. |
|
void |
visitVariableExpression(VariableExpression expression, boolean spacePad)Renders a variable reference. |
|
void |
visitWhileLoop(WhileStatement statement)Renders a while-loop statement. |
Current indentation prefix.
Indicates whether the next write should emit indentation first.
Tracks whether the free-form script body has already been emitted.
Whether the generated script class should be rendered.
Whether free-form script statements should be rendered.
Creates a visitor that renders AST nodes as Groovy source.
writer - target writershowScriptFreeForm - whether free-form script statements should be renderedshowScriptClass - whether the generated script class should be renderedRenders the supplied primary class node and optional script body.
Executes the supplied block one indentation level deeper.
block - block to execute while indentedWrites text, applying the current indentation rules.
parameter - value to append to the outputEnsures the output ends with a blank line.
Ensures the output ends with a single line break.
This visitor writes directly to its target and does not support println-style output.
parameter - ignored output parameterRenders an annotation and its members.
Retained for compatibility; delegates to visitArgumentlistExpression(ArgumentListExpression).
Renders an argument list expression.
Renders an array expression.
Renders an assert statement.
Renders an attribute access expression.
Renders a binary or assignment expression.
Renders a bitwise negation expression.
Renders a block statement.
Renders a boolean expression.
Renders a break statement.
Emits a placeholder for a bytecode expression.
Renders a switch case.
Renders a cast or coercion expression.
Renders a catch clause.
Renders a class literal expression.
Renders a closure expression.
Renders a closure list expression.
Renders a constant expression.
Renders a constructor declaration.
Renders a constructor invocation expression.
Renders a continue statement.
Renders a declaration expression.
Renders a do/while-loop statement.
Renders a standalone expression statement.
Renders a field reference expression.
Renders a for-loop statement.
Renders a GString expression.
Renders an if/else statement.
Writes an import declaration.
node - import node to renderRenders a lambda expression.
Renders a list expression.
Renders a map entry expression.
Renders a map expression.
Renders a method or initializer declaration.
Renders a method call expression.
Renders a method pointer expression.
Renders a method reference expression.
Renders a logical negation expression.
Writes the package declaration for the current source unit.
packageNode - package node to renderRenders a postfix expression.
Renders a prefix expression.
Skips property rendering because fields already emit the corresponding output.
Renders a property access expression.
Renders a range expression.
Renders a return statement.
Renders an Elvis expression.
Renders a spread expression.
Renders a spread-map expression.
Renders a static method call expression.
Renders a switch statement.
Renders a synchronized statement.
Renders a ternary expression.
Renders a throw statement.
Renders a try/catch/finally statement.
Renders a tuple expression.
Prints out the type, safely handling arrays.
classNode - type to renderRenders a unary minus expression.
Renders a unary plus expression.
Renders a variable reference.
Renders a while-loop statement.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.