Package: org.codehaus.groovy.ast

## [Java] Class CodeVisitorSupport

- org.codehaus.groovy.ast.CodeVisitorSupport

- All Implemented Interfaces and Traits:
    GroovyCodeVisitor

      public abstract class CodeVisitorSupport
      extends Object
      implements GroovyCodeVisitor

  Abstract base class for implementing the GroovyCodeVisitor interface, providing default implementations for all visit methods that perform depth-first traversal of the AST.

  This class implements the visitor design pattern for Groovy AST nodes. Subclasses may override specific visit methods to perform custom processing, while other visit methods automatically traverse child nodes. Default implementations delegate to child nodes, allowing for simple tree traversal without accumulating logic in each subclass.

  The traversal pattern follows the structure of the AST:

  - Block and control flow statements recursively visit their contained statements
  - Expressions recursively visit their operand expressions
  - Terminal expressions (constants, variables) perform no traversal

  Subclasses typically override `visit*` methods of interest and call `super.visit*(node)` to maintain the default traversal behavior or to perform post-processing after traversing children.

  See Also:
    GroovyCodeVisitor
    for class-level visitor support
    for transforming visitor implementation

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `afterSwitchCaseStatementsVisited(SwitchStatement statement)` Hook method called after all case statements are visited, but before the default statement.
    `` | `protected void` | `afterSwitchConditionExpressionVisited(SwitchStatement statement)` Hook method called after the switch condition expression is visited, but before case statements.
    `` | `public void` | `visitArgumentlistExpression(ArgumentListExpression expression)` Visits an ArgumentListExpression, treating it as a tuple expression.
    `` | `public void` | `visitArrayExpression(ArrayExpression expression)` Visits an ArrayExpression, traversing element expressions and size expressions.
    `` | `public void` | `visitAssertStatement(AssertStatement statement)` Visits an AssertStatement, traversing the assertion condition and optional message expression.
    `` | `public void` | `visitAttributeExpression(AttributeExpression expression)` Visits an AttributeExpression, traversing the object and attribute name expressions.
    `` | `public void` | `visitBinaryExpression(BinaryExpression expression)` Visits a BinaryExpression, traversing left and right operand expressions.
    `` | `public void` | `visitBitwiseNegationExpression(BitwiseNegationExpression expression)` Visits a BitwiseNegationExpression, traversing the operand expression.
    `` | `public void` | `visitBlockStatement(BlockStatement block)` Visits a BlockStatement, traversing each contained statement in order.
    `` | `public void` | `visitBooleanExpression(BooleanExpression expression)` Visits a BooleanExpression, traversing the contained expression.
    `` | `public void` | `visitBreakStatement(BreakStatement statement)` Visits a BreakStatement.
    `` | `public void` | `visitBytecodeExpression(BytecodeExpression expression)` Visits a BytecodeExpression.
    `` | `public void` | `visitCaseStatement(CaseStatement statement)` Visits a CaseStatement, traversing the case expression and code block.
    `` | `public void` | `visitCastExpression(CastExpression expression)` Visits a CastExpression, traversing the operand expression.
    `` | `public void` | `visitCatchStatement(CatchStatement statement)` Visits a CatchStatement, traversing the catch block code.
    `` | `public void` | `visitClassExpression(ClassExpression expression)` Visits a ClassExpression.
    `` | `public void` | `visitClosureExpression(ClosureExpression expression)` Visits a ClosureExpression, traversing parameter initializers and the closure code block.
    `` | `public void` | `visitClosureListExpression(ClosureListExpression expression)` Visits a ClosureListExpression, traversing all contained expressions.
    `` | `public void` | `visitConstantExpression(ConstantExpression expression)` Visits a ConstantExpression.
    `` | `public void` | `visitConstructorCallExpression(ConstructorCallExpression call)` Visits a ConstructorCallExpression, traversing its argument list.
    `` | `public void` | `visitContinueStatement(ContinueStatement statement)` Visits a ContinueStatement.
    `` | `public void` | `visitDeclarationExpression(DeclarationExpression expression)` Visits a DeclarationExpression, treating it as a binary expression.
    `` | `public void` | `visitDoWhileLoop(DoWhileStatement statement)` Visits a DoWhileStatement, traversing the loop body before the boolean condition.
    `` | `public void` | `visitEmptyStatement(EmptyStatement statement)` Visits an EmptyStatement.
    `` | `public void` | `visitExpressionStatement(ExpressionStatement statement)` Visits an ExpressionStatement, traversing its contained expression.
    `` | `public void` | `visitFieldExpression(FieldExpression expression)` Visits a FieldExpression.
    `` | `public void` | `visitForLoop(ForStatement statement)` Visits a ForStatement, traversing the collection expression and loop body.
    `` | `public void` | `visitGStringExpression(GStringExpression expression)` Visits a GStringExpression, traversing string parts and interpolated value expressions.
    `` | `public void` | `visitIfElse(IfStatement statement)` Visits an IfStatement, traversing the condition, if-block, and optional else-block.
    `` | `public void` | `visitLambdaExpression(LambdaExpression expression)` Visits a LambdaExpression, treating it as a closure expression.
    `` | `public void` | `visitListExpression(ListExpression expression)` Visits a ListExpression, traversing all contained expressions.
    `` | `public void` | `visitMapEntryExpression(MapEntryExpression expression)` Visits a MapEntryExpression, traversing key and value expressions.
    `` | `public void` | `visitMapExpression(MapExpression expression)` Visits a MapExpression, traversing all map entry expressions.
    `` | `public void` | `visitMethodCallExpression(MethodCallExpression call)` Visits a MethodCallExpression, traversing the object expression, method expression, and argument list.
    `` | `public void` | `visitMethodPointerExpression(MethodPointerExpression expression)` Visits a MethodPointerExpression, traversing the object and method name expressions.
    `` | `public void` | `visitMethodReferenceExpression(MethodReferenceExpression expression)` Visits a MethodReferenceExpression, treating it as a method pointer.
    `` | `public void` | `visitNotExpression(NotExpression expression)` Visits a NotExpression, traversing the operand expression.
    `` | `public void` | `visitPostfixExpression(PostfixExpression expression)` Visits a PostfixExpression, traversing the operand expression.
    `` | `public void` | `visitPrefixExpression(PrefixExpression expression)` Visits a PrefixExpression, traversing the operand expression.
    `` | `public void` | `visitPropertyExpression(PropertyExpression expression)` Visits a PropertyExpression, traversing the object and property name expressions.
    `` | `public void` | `visitRangeExpression(RangeExpression expression)` Visits a RangeExpression, traversing from and to boundary expressions.
    `` | `public void` | `visitReturnStatement(ReturnStatement statement)` Visits a ReturnStatement, traversing its return expression.
    `` | `public void` | `visitShortTernaryExpression(ElvisOperatorExpression expression)` Visits a ElvisOperatorExpression, treating it as a ternary expression.
    `` | `public void` | `visitSpreadExpression(SpreadExpression expression)` Visits a SpreadExpression, traversing the operand expression.
    `` | `public void` | `visitSpreadMapExpression(SpreadMapExpression expression)` Visits a SpreadMapExpression, traversing the operand expression.
    `` | `public void` | `visitStaticMethodCallExpression(StaticMethodCallExpression call)` Visits a StaticMethodCallExpression, traversing its argument list.
    `` | `public void` | `visitSwitch(SwitchStatement statement)` Visits a SwitchStatement, traversing the switch expression, case statements, and default statement.
    `` | `public void` | `visitSynchronizedStatement(SynchronizedStatement statement)` Visits a SynchronizedStatement, traversing the synchronization expression and code block.
    `` | `public void` | `visitTernaryExpression(TernaryExpression expression)` Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions.
    `` | `public void` | `visitThrowStatement(ThrowStatement statement)` Visits a ThrowStatement, traversing the exception expression.
    `` | `public void` | `visitTryCatchFinally(TryCatchStatement statement)` Visits a TryCatchStatement, traversing resource statements, try block, catch statements, and finally block.
    `` | `public void` | `visitTupleExpression(TupleExpression expression)` Visits a TupleExpression, traversing all contained expressions.
    `` | `public void` | `visitUnaryMinusExpression(UnaryMinusExpression expression)` Visits a UnaryMinusExpression, traversing the operand expression.
    `` | `public void` | `visitUnaryPlusExpression(UnaryPlusExpression expression)` Visits a UnaryPlusExpression, traversing the operand expression.
    `` | `public void` | `visitVariableExpression(VariableExpression expression)` Visits a VariableExpression.
    `` | `public void` | `visitWhileLoop(WhileStatement statement)` Visits a WhileStatement, traversing the boolean condition and loop body.

  - ### Inherited Methods Summary

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

- - ### Method Detail

    - #### protected void afterSwitchCaseStatementsVisited(SwitchStatement statement)

      Hook method called after all case statements are visited, but before the default statement. Subclasses may override to perform processing between cases and default.

      Parameters:
        `statement` - the switch statement being visited
      Since:
        5.0.0

    - #### protected void afterSwitchConditionExpressionVisited(SwitchStatement statement)

      Hook method called after the switch condition expression is visited, but before case statements. Subclasses may override to perform processing between condition and cases.

      Parameters:
        `statement` - the switch statement being visited
      Since:
        3.0.0

    - #### public void visitArgumentlistExpression(ArgumentListExpression expression)

      Visits an ArgumentListExpression, treating it as a tuple expression.

      Parameters:
        `expression` - the argument list expression

    - #### public void visitArrayExpression(ArrayExpression expression)

      Visits an ArrayExpression, traversing element expressions and size expressions.

      Parameters:
        `expression` - the array expression

    - #### public void visitAssertStatement(AssertStatement statement)

      Visits an AssertStatement, traversing the assertion condition and optional message expression.

      Parameters:
        `statement` - the assert statement

    - #### public void visitAttributeExpression(AttributeExpression expression)

      Visits an AttributeExpression, traversing the object and attribute name expressions.

      Parameters:
        `expression` - the attribute expression

    - #### public void visitBinaryExpression(BinaryExpression expression)

      Visits a BinaryExpression, traversing left and right operand expressions.

      Parameters:
        `expression` - the binary expression

    - #### public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

      Visits a BitwiseNegationExpression, traversing the operand expression.

      Parameters:
        `expression` - the bitwise negation expression

    - #### public void visitBlockStatement(BlockStatement block)

      Visits a BlockStatement, traversing each contained statement in order.

      Parameters:
        `block` - the block statement to visit, may contain multiple statements
      See Also:
        visitForLoop(ForStatement)
        visitWhileLoop(WhileStatement)

    - #### public void visitBooleanExpression(BooleanExpression expression)

      Visits a BooleanExpression, traversing the contained expression.

      Parameters:
        `expression` - the boolean expression

    - #### public void visitBreakStatement(BreakStatement statement)

      Visits a BreakStatement. No traversal is performed as break statements contain no child nodes.

      Parameters:
        `statement` - the break statement

    - #### public void visitBytecodeExpression(BytecodeExpression expression)

      Visits a BytecodeExpression. No traversal is performed as bytecode expressions are terminal.

      Parameters:
        `expression` - the bytecode expression

    - #### public void visitCaseStatement(CaseStatement statement)

      Visits a CaseStatement, traversing the case expression and code block.

      Parameters:
        `statement` - the case statement

    - #### public void visitCastExpression(CastExpression expression)

      Visits a CastExpression, traversing the operand expression.

      Parameters:
        `expression` - the cast expression

    - #### public void visitCatchStatement(CatchStatement statement)

      Visits a CatchStatement, traversing the catch block code.

      Parameters:
        `statement` - the catch statement

    - #### public void visitClassExpression(ClassExpression expression)

      Visits a ClassExpression. No traversal is performed as class expressions contain no child expressions.

      Parameters:
        `expression` - the class expression

    - #### public void visitClosureExpression(ClosureExpression expression)

      Visits a ClosureExpression, traversing parameter initializers and the closure code block.

      Parameters:
        `expression` - the closure expression

    - #### public void visitClosureListExpression(ClosureListExpression expression)

      Visits a ClosureListExpression, traversing all contained expressions.

      Parameters:
        `expression` - the closure list expression

    - #### public void visitConstantExpression(ConstantExpression expression)

      Visits a ConstantExpression. No traversal is performed as constants contain no child expressions.

      Parameters:
        `expression` - the constant expression

    - #### public void visitConstructorCallExpression(ConstructorCallExpression call)

      Visits a ConstructorCallExpression, traversing its argument list.

      Parameters:
        `call` - the constructor call expression

    - #### public void visitContinueStatement(ContinueStatement statement)

      Visits a ContinueStatement. No traversal is performed as continue statements contain no child nodes.

      Parameters:
        `statement` - the continue statement

    - #### public void visitDeclarationExpression(DeclarationExpression expression)

      Visits a DeclarationExpression, treating it as a binary expression.

      Parameters:
        `expression` - the declaration expression

    - #### public void visitDoWhileLoop(DoWhileStatement statement)

      Visits a DoWhileStatement, traversing the loop body before the boolean condition.

      Parameters:
        `statement` - the do-while loop statement

    - #### public void visitEmptyStatement(EmptyStatement statement)

      Visits an EmptyStatement. No traversal is performed as empty statements contain no child nodes.

      Parameters:
        `statement` - the empty statement

    - #### public void visitExpressionStatement(ExpressionStatement statement)

      Visits an ExpressionStatement, traversing its contained expression.

      Parameters:
        `statement` - the expression statement

    - #### public void visitFieldExpression(FieldExpression expression)

      Visits a FieldExpression. No traversal is performed as field expressions contain no child expressions.

      Parameters:
        `expression` - the field expression

    - #### public void visitForLoop(ForStatement statement)

      Visits a ForStatement, traversing the collection expression and loop body.

      Parameters:
        `statement` - the for loop statement

    - #### public void visitGStringExpression(GStringExpression expression)

      Visits a GStringExpression, traversing string parts and interpolated value expressions.

      Parameters:
        `expression` - the GString expression

    - #### public void visitIfElse(IfStatement statement)

      Visits an IfStatement, traversing the condition, if-block, and optional else-block.

      Parameters:
        `statement` - the if-else statement

    - #### public void visitLambdaExpression(LambdaExpression expression)

      Visits a LambdaExpression, treating it as a closure expression.

      Parameters:
        `expression` - the lambda expression

    - #### public void visitListExpression(ListExpression expression)

      Visits a ListExpression, traversing all contained expressions.

      Parameters:
        `expression` - the list expression

    - #### public void visitMapEntryExpression(MapEntryExpression expression)

      Visits a MapEntryExpression, traversing key and value expressions.

      Parameters:
        `expression` - the map entry expression

    - #### public void visitMapExpression(MapExpression expression)

      Visits a MapExpression, traversing all map entry expressions.

      Parameters:
        `expression` - the map expression

    - #### public void visitMethodCallExpression(MethodCallExpression call)

      Visits a MethodCallExpression, traversing the object expression, method expression, and argument list.

      Parameters:
        `call` - the method call expression

    - #### public void visitMethodPointerExpression(MethodPointerExpression expression)

      Visits a MethodPointerExpression, traversing the object and method name expressions.

      Parameters:
        `expression` - the method pointer expression

    - #### public void visitMethodReferenceExpression(MethodReferenceExpression expression)

      Visits a MethodReferenceExpression, treating it as a method pointer.

      Parameters:
        `expression` - the method reference expression

    - #### public void visitNotExpression(NotExpression expression)

      Visits a NotExpression, traversing the operand expression.

      Parameters:
        `expression` - the not expression

    - #### public void visitPostfixExpression(PostfixExpression expression)

      Visits a PostfixExpression, traversing the operand expression.

      Parameters:
        `expression` - the postfix expression

    - #### public void visitPrefixExpression(PrefixExpression expression)

      Visits a PrefixExpression, traversing the operand expression.

      Parameters:
        `expression` - the prefix expression

    - #### public void visitPropertyExpression(PropertyExpression expression)

      Visits a PropertyExpression, traversing the object and property name expressions.

      Parameters:
        `expression` - the property expression

    - #### public void visitRangeExpression(RangeExpression expression)

      Visits a RangeExpression, traversing from and to boundary expressions.

      Parameters:
        `expression` - the range expression

    - #### public void visitReturnStatement(ReturnStatement statement)

      Visits a ReturnStatement, traversing its return expression.

      Parameters:
        `statement` - the return statement

    - #### public void visitShortTernaryExpression(ElvisOperatorExpression expression)

      Visits a ElvisOperatorExpression, treating it as a ternary expression.

      Parameters:
        `expression` - the elvis operator expression

    - #### public void visitSpreadExpression(SpreadExpression expression)

      Visits a SpreadExpression, traversing the operand expression.

      Parameters:
        `expression` - the spread expression

    - #### public void visitSpreadMapExpression(SpreadMapExpression expression)

      Visits a SpreadMapExpression, traversing the operand expression.

      Parameters:
        `expression` - the spread map expression

    - #### public void visitStaticMethodCallExpression(StaticMethodCallExpression call)

      Visits a StaticMethodCallExpression, traversing its argument list.

      Parameters:
        `call` - the static method call expression

    - #### public void visitSwitch(SwitchStatement statement)

      Visits a SwitchStatement, traversing the switch expression, case statements, and default statement.

      Parameters:
        `statement` - the switch statement

    - #### public void visitSynchronizedStatement(SynchronizedStatement statement)

      Visits a SynchronizedStatement, traversing the synchronization expression and code block.

      Parameters:
        `statement` - the synchronized statement

    - #### public void visitTernaryExpression(TernaryExpression expression)

      Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions.

      Parameters:
        `expression` - the ternary expression

    - #### public void visitThrowStatement(ThrowStatement statement)

      Visits a ThrowStatement, traversing the exception expression.

      Parameters:
        `statement` - the throw statement

    - #### public void visitTryCatchFinally(TryCatchStatement statement)

      Visits a TryCatchStatement, traversing resource statements, try block, catch statements, and finally block.

      Parameters:
        `statement` - the try-catch-finally statement

    - #### public void visitTupleExpression(TupleExpression expression)

      Visits a TupleExpression, traversing all contained expressions.

      Parameters:
        `expression` - the tuple expression

    - #### public void visitUnaryMinusExpression(UnaryMinusExpression expression)

      Visits a UnaryMinusExpression, traversing the operand expression.

      Parameters:
        `expression` - the unary minus expression

    - #### public void visitUnaryPlusExpression(UnaryPlusExpression expression)

      Visits a UnaryPlusExpression, traversing the operand expression.

      Parameters:
        `expression` - the unary plus expression

    - #### public void visitVariableExpression(VariableExpression expression)

      Visits a VariableExpression. No traversal is performed as variable expressions contain no child expressions.

      Parameters:
        `expression` - the variable expression

    - #### public void visitWhileLoop(WhileStatement statement)

      Visits a WhileStatement, traversing the boolean condition and loop body.

      Parameters:
        `statement` - the while loop statement