Package: groovy.console.ui

## [Groovy] Class AstNodeToScriptVisitor

- groovy.console.ui.AstNodeToScriptVisitor

- All Implemented Interfaces and Traits:
    GroovyClassVisitor, GroovyCodeVisitor, IPrimaryClassNodeOperation

      @AutoFinal
      @CompileStatic
      class AstNodeToScriptVisitor
      extends Object
      implements GroovyClassVisitor, GroovyCodeVisitor, IPrimaryClassNodeOperation

  An adapter from ASTNode tree to source code.

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `String` | `_indent` Current indentation prefix.
    `Stack<String>` | `classNameStack` Stack of nested class names used while rendering constructors.
    `boolean` | `readyToIndent` Indicates whether the next write should emit indentation first.
    `boolean` | `scriptHasBeenVisited` Tracks whether the free-form script body has already been emitted.
    `boolean` | `showScriptClass` Whether the generated script class should be rendered.
    `boolean` | `showScriptFreeForm` Whether free-form script statements should be rendered.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `AstNodeToScriptVisitor(Writer writer, boolean showScriptFreeForm, boolean showScriptClass)` Creates a visitor that renders AST nodes as Groovy source.

  - ### Methods Summary

    Methods
    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` | `visitSwitchExpression(SwitchExpression expression)` Renders a first-class switch expression (GROOVY-12255).
    `` | `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.
    `` | `void` | `visitYieldStatement(YieldStatement statement)` Renders a yield statement (GROOVY-12255).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Property Detail

    - #### String _indent

      Current indentation prefix.

    - #### Stack<String> classNameStack

      Stack of nested class names used while rendering constructors.

    - #### boolean readyToIndent

      Indicates whether the next write should emit indentation first.

    - #### boolean scriptHasBeenVisited

      Tracks whether the free-form script body has already been emitted.

    - #### boolean showScriptClass

      Whether the generated script class should be rendered.

    - #### boolean showScriptFreeForm

      Whether free-form script statements should be rendered.

  - ### Constructor Detail

    - #### AstNodeToScriptVisitor(Writer writer, boolean showScriptFreeForm, boolean showScriptClass)

      Creates a visitor that renders AST nodes as Groovy source.

      Parameters:
        `writer` - target writer
        `showScriptFreeForm` - whether free-form script statements should be rendered
        `showScriptClass` - whether the generated script class should be rendered

  - ### Method Detail

    - #### @Override
      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.

      Parameters:
        `block` - block to execute while indented

    - #### void print(Object parameter)

      Writes text, applying the current indentation rules.

      Parameters:
        `parameter` - value to append to the output

    - #### 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.

      Parameters:
        `parameter` - ignored output parameter

    - #### void visitAnnotationNode(AnnotationNode node)

      Renders an annotation and its members.

    - #### @Deprecated
      void visitArgumentlistExpression(ArgumentListExpression expression, boolean showTypesIgnored)

      Retained for compatibility; delegates to visitArgumentlistExpression(ArgumentListExpression).

    - #### @Override
      void visitArgumentlistExpression(ArgumentListExpression expression)

      Renders an argument list expression.

    - #### @Override
      void visitArrayExpression(ArrayExpression expression)

      Renders an array expression.

    - #### @Override
      void visitAssertStatement(AssertStatement statement)

      Renders an assert statement.

    - #### @Override
      void visitAttributeExpression(AttributeExpression attributeExpression)

      Renders an attribute access expression.

    - #### @Override
      void visitBinaryExpression(BinaryExpression expression)

      Renders a binary or assignment expression.

    - #### @Override
      void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

      Renders a bitwise negation expression.

    - #### @Override
      void visitBlockStatement(BlockStatement block)

      Renders a block statement.

    - #### @Override
      void visitBooleanExpression(BooleanExpression expression)

      Renders a boolean expression.

    - #### @Override
      void visitBreakStatement(BreakStatement statement)

      Renders a break statement.

    - #### @Override
      void visitBytecodeExpression(BytecodeExpression expression)

      Emits a placeholder for a bytecode expression.

    - #### @Override
      void visitCaseStatement(CaseStatement statement)

      Renders a switch case.

    - #### @Override
      void visitCastExpression(CastExpression expression)

      Renders a cast or coercion expression.

    - #### @Override
      void visitCatchStatement(CatchStatement statement)

      Renders a catch clause.

    - #### @Override
      void visitClass(ClassNode node)

      Renders a class or interface declaration.

    - #### @Override
      void visitClassExpression(ClassExpression expression)

      Renders a class literal expression.

    - #### @Override
      void visitClosureExpression(ClosureExpression expression)

      Renders a closure expression.

    - #### @Override
      void visitClosureListExpression(ClosureListExpression expression)

      Renders a closure list expression.

    - #### @Override
      void visitConstantExpression(ConstantExpression expression, boolean unwrapQuotes)

      Renders a constant expression.

    - #### @Override
      void visitConstructor(ConstructorNode node)

      Renders a constructor declaration.

    - #### @Override
      void visitConstructorCallExpression(ConstructorCallExpression expression)

      Renders a constructor invocation expression.

    - #### @Override
      void visitContinueStatement(ContinueStatement statement)

      Renders a continue statement.

    - #### @Override
      void visitDeclarationExpression(DeclarationExpression expression)

      Renders a declaration expression.

    - #### @Override
      void visitDoWhileLoop(DoWhileStatement statement)

      Renders a do/while-loop statement.

    - #### @Override
      void visitExpressionStatement(ExpressionStatement statement)

      Renders a standalone expression statement.

    - #### @Override
      void visitField(FieldNode node)

      Renders a field declaration.

    - #### @Override
      void visitFieldExpression(FieldExpression expression)

      Renders a field reference expression.

    - #### @Override
      void visitForLoop(ForStatement statement)

      Renders a for-loop statement.

    - #### @Override
      void visitGStringExpression(GStringExpression expression)

      Renders a GString expression.

    - #### @Override
      void visitIfElse(IfStatement ifElse)

      Renders an if/else statement.

    - #### void visitImport(ImportNode node)

      Writes an import declaration.

      Parameters:
        `node` - import node to render

    - #### @Override
      void visitLambdaExpression(LambdaExpression expression)

      Renders a lambda expression.

    - #### @Override
      void visitListExpression(ListExpression expression)

      Renders a list expression.

    - #### @Override
      void visitMapEntryExpression(MapEntryExpression expression)

      Renders a map entry expression.

    - #### @Override
      void visitMapExpression(MapExpression expression)

      Renders a map expression.

    - #### @Override
      void visitMethod(MethodNode node)

      Renders a method or initializer declaration.

    - #### @Override
      void visitMethodCallExpression(MethodCallExpression expression)

      Renders a method call expression.

    - #### @Override
      void visitMethodPointerExpression(MethodPointerExpression expression)

      Renders a method pointer expression.

    - #### @Override
      void visitMethodReferenceExpression(MethodReferenceExpression expression)

      Renders a method reference expression.

    - #### @Override
      void visitNotExpression(NotExpression expression)

      Renders a logical negation expression.

    - #### void visitPackage(PackageNode packageNode)

      Writes the package declaration for the current source unit.

      Parameters:
        `packageNode` - package node to render

    - #### @Override
      void visitPostfixExpression(PostfixExpression expression)

      Renders a postfix expression.

    - #### @Override
      void visitPrefixExpression(PrefixExpression expression)

      Renders a prefix expression.

    - #### @Override
      void visitProperty(PropertyNode node)

      Skips property rendering because fields already emit the corresponding output.

    - #### @Override
      void visitPropertyExpression(PropertyExpression expression)

      Renders a property access expression.

    - #### @Override
      void visitRangeExpression(RangeExpression expression)

      Renders a range expression.

    - #### @Override
      void visitReturnStatement(ReturnStatement statement)

      Renders a return statement.

    - #### @Override
      void visitShortTernaryExpression(ElvisOperatorExpression expression)

      Renders an Elvis expression.

    - #### @Override
      void visitSpreadExpression(SpreadExpression expression)

      Renders a spread expression.

    - #### @Override
      void visitSpreadMapExpression(SpreadMapExpression expression)

      Renders a spread-map expression.

    - #### @Override
      void visitStaticMethodCallExpression(StaticMethodCallExpression expression)

      Renders a static method call expression.

    - #### @Override
      void visitSwitch(SwitchStatement statement)

      Renders a switch statement.

    - #### @Override
      void visitSwitchExpression(SwitchExpression expression)

      Renders a first-class switch expression (GROOVY-12255).

    - #### @Override
      void visitSynchronizedStatement(SynchronizedStatement statement)

      Renders a synchronized statement.

    - #### @Override
      void visitTernaryExpression(TernaryExpression expression)

      Renders a ternary expression.

    - #### @Override
      void visitThrowStatement(ThrowStatement statement)

      Renders a throw statement.

    - #### @Override
      void visitTryCatchFinally(TryCatchStatement statement)

      Renders a try/catch/finally statement.

    - #### @Override
      void visitTupleExpression(TupleExpression expression)

      Renders a tuple expression.

    - #### void visitType(ClassNode classNode)

      Prints out the type, safely handling arrays.

      Parameters:
        `classNode` - type to render

    - #### @Override
      void visitUnaryMinusExpression(UnaryMinusExpression expression)

      Renders a unary minus expression.

    - #### @Override
      void visitUnaryPlusExpression(UnaryPlusExpression expression)

      Renders a unary plus expression.

    - #### @Override
      void visitVariableExpression(VariableExpression expression, boolean spacePad)

      Renders a variable reference.

    - #### @Override
      void visitWhileLoop(WhileStatement statement)

      Renders a while-loop statement.

    - #### @Override
      void visitYieldStatement(YieldStatement statement)

      Renders a yield statement (GROOVY-12255).