Package: org.codehaus.groovy.ast

## [Java] Interface GroovyCodeVisitor

-     public interface GroovyCodeVisitor

  Defines the visitor interface for traversing and processing Groovy AST nodes using the visitor pattern. Implementations can perform compilation, transformation, code generation, or analysis by implementing visit methods for specific statement and expression types. The interface provides both required abstract methods and default convenience methods for handling generic collections and null values.

  See Also:
    Statement
    Expression
    ClassCodeVisitorSupport
    CodeVisitorSupport

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `visit(Statement statement)` Convenience method to visit a statement if it is not null.
    `` | `public void` | `visit(Expression expression)` Convenience method to visit an expression if it is not null.
    `` | `public void` | `visitArgumentlistExpression(ArgumentListExpression expression)` Visits an argument list expression (method arguments).
    `` | `public void` | `visitArrayExpression(ArrayExpression expression)` Visits an array expression.
    `` | `public void` | `visitAssertStatement(AssertStatement statement)` Visits an assert statement.
    `` | `public void` | `visitAttributeExpression(AttributeExpression expression)` Visits an attribute expression (object@property, accessing direct field without getters).
    `` | `public void` | `visitBinaryExpression(BinaryExpression expression)` Visits a binary expression (left op right).
    `` | `public void` | `visitBitwiseNegationExpression(BitwiseNegationExpression expression)` Visits a bitwise negation expression (~expr).
    `` | `public void` | `visitBlockStatement(BlockStatement statement)` Visits a block statement (list of statements enclosed in braces).
    `` | `public void` | `visitBooleanExpression(BooleanExpression expression)` Visits a boolean expression.
    `` | `public void` | `visitBreakStatement(BreakStatement statement)` Visits a break statement.
    `` | `public void` | `visitBytecodeExpression(BytecodeExpression expression)` Visits a bytecode expression (direct JVM bytecode instructions).
    `` | `public void` | `visitCaseStatement(CaseStatement statement)` Visits a case clause within a switch statement.
    `` | `public void` | `visitCastExpression(CastExpression expression)` Visits a cast expression ((Type) expr).
    `` | `public void` | `visitCatchStatement(CatchStatement statement)` Visits a catch clause within a try-catch statement.
    `` | `public void` | `visitClassExpression(ClassExpression expression)` Visits a class expression.
    `` | `public void` | `visitClosureExpression(ClosureExpression expression)` Visits a closure expression.
    `` | `public void` | `visitClosureListExpression(ClosureListExpression expression)` Visits a closure list expression.
    `` | `public void` | `visitConstantExpression(ConstantExpression expression)` Visits a constant expression (literal value).
    `` | `public void` | `visitConstructorCallExpression(ConstructorCallExpression expression)` Visits a constructor call expression.
    `` | `public void` | `visitContinueStatement(ContinueStatement statement)` Visits a continue statement.
    `` | `public void` | `visitDeclarationExpression(DeclarationExpression expression)` Visits a declaration expression (variable declaration with initialization).
    `` | `public void` | `visitDoWhileLoop(DoWhileStatement statement)` Visits a do-while loop statement.
    `` | `public void` | `visitEmptyExpression(EmptyExpression expression)` Visits an empty expression.
    `` | `public void` | `visitEmptyStatement(EmptyStatement statement)` Visits an empty statement.
    `` | `public void` | `visitExpressionStatement(ExpressionStatement statement)` Visits an expression statement (an expression used as a statement).
    `` | `public void` | `visitFieldExpression(FieldExpression expression)` Visits a field expression.
    `` | `public void` | `visitForLoop(ForStatement statement)` Visits a for loop statement.
    `` | `public void` | `visitGStringExpression(GStringExpression expression)` Visits a GString expression (string with interpolations).
    `` | `public void` | `visitIfElse(IfStatement statement)` Visits an if-else statement.
    `` | `public void` | `visitLambdaExpression(LambdaExpression expression)` Visits a lambda expression.
    `` | `public void` | `visitListExpression(ListExpression expression)` Visits a list expression.
    `` | `public void` | `visitListOfExpressions(List<? extends Expression> list)` Convenience method to visit a list of expressions.
    `` | `public void` | `visitMapEntryExpression(MapEntryExpression expression)` Visits a map entry expression (key: value pair within a map).
    `` | `public void` | `visitMapExpression(MapExpression expression)` Visits a map expression.
    `` | `public void` | `visitMethodCallExpression(MethodCallExpression expression)` Visits a method call expression.
    `` | `public void` | `visitMethodPointerExpression(MethodPointerExpression expression)` Visits a method pointer expression ({@code object.
    `` | `public void` | `visitMethodReferenceExpression(MethodReferenceExpression expression)` Visits a method reference expression (obj::method).
    `` | `public void` | `visitNotExpression(NotExpression expression)` Visits a not expression (!
    `` | `public void` | `visitPostfixExpression(PostfixExpression expression)` Visits a postfix expression (expr op).
    `` | `public void` | `visitPrefixExpression(PrefixExpression expression)` Visits a prefix expression (op expr).
    `` | `public void` | `visitPropertyExpression(PropertyExpression expression)` Visits a property expression (object.property).
    `` | `public void` | `visitRangeExpression(RangeExpression expression)` Visits a range expression.
    `` | `public void` | `visitReturnStatement(ReturnStatement statement)` Visits a return statement.
    `` | `public void` | `visitShortTernaryExpression(ElvisOperatorExpression expression)` Visits an Elvis operator expression (shorthand ternary with implicit condition check).
    `` | `public void` | `visitSpreadExpression(SpreadExpression expression)` Visits a spread expression (*expr, spreading collection elements).
    `` | `public void` | `visitSpreadMapExpression(SpreadMapExpression expression)` Visits a spread map expression (*:map, spreading map entries).
    `` | `public void` | `visitStaticMethodCallExpression(StaticMethodCallExpression expression)` Visits a static method call expression.
    `` | `public void` | `visitSwitch(SwitchStatement statement)` Visits a switch statement.
    `` | `public void` | `visitSwitchExpression(SwitchExpression expression)` Visits a first-class switch expression (JEP 361).
    `` | `public void` | `visitSynchronizedStatement(SynchronizedStatement statement)` Visits a synchronized statement.
    `` | `public void` | `visitTernaryExpression(TernaryExpression expression)` Visits a ternary expression (condition ?
    `` | `public void` | `visitThrowStatement(ThrowStatement statement)` Visits a throw statement.
    `` | `public void` | `visitTryCatchFinally(TryCatchStatement statement)` Visits a try-catch-finally statement.
    `` | `public void` | `visitTupleExpression(TupleExpression expression)` Visits a tuple expression (comma-separated expressions grouped in parentheses).
    `` | `public void` | `visitUnaryMinusExpression(UnaryMinusExpression expression)` Visits a unary minus expression (-expr).
    `` | `public void` | `visitUnaryPlusExpression(UnaryPlusExpression expression)` Visits a unary plus expression (+expr).
    `` | `public void` | `visitVariableExpression(VariableExpression expression)` Visits a variable expression.
    `` | `public void` | `visitWhileLoop(WhileStatement statement)` Visits a while loop statement.
    `` | `public void` | `visitYieldStatement(YieldStatement statement)` Visits a `yield` statement that produces the value of an enclosing SwitchExpression.

- - ### Method Detail

    - #### public void visit(Statement statement)

      Convenience method to visit a statement if it is not null. Delegates to the statement's visit method.

      Parameters:
        `statement` - the Statement to process, or null to do nothing

    - #### public void visit(Expression expression)

      Convenience method to visit an expression if it is not null. Delegates to the expression's visit method.

      Parameters:
        `expression` - the Expression to process, or null to do nothing

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

      Visits an argument list expression (method arguments).

      Parameters:
        `expression` - the ArgumentListExpression to process

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

      Visits an array expression.

      Parameters:
        `expression` - the ArrayExpression to process

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

      Visits an assert statement.

      Parameters:
        `statement` - the AssertStatement to process

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

      Visits an attribute expression (object@property, accessing direct field without getters).

      Parameters:
        `expression` - the AttributeExpression to process

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

      Visits a binary expression (left op right).

      Parameters:
        `expression` - the BinaryExpression to process

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

      Visits a bitwise negation expression (~expr).

      Parameters:
        `expression` - the BitwiseNegationExpression to process

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

      Visits a block statement (list of statements enclosed in braces).

      Parameters:
        `statement` - the BlockStatement to process

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

      Visits a boolean expression.

      Parameters:
        `expression` - the BooleanExpression to process

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

      Visits a break statement.

      Parameters:
        `statement` - the BreakStatement to process

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

      Visits a bytecode expression (direct JVM bytecode instructions).

      Parameters:
        `expression` - the BytecodeExpression to process

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

      Visits a case clause within a switch statement.

      Parameters:
        `statement` - the CaseStatement to process

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

      Visits a cast expression ((Type) expr).

      Parameters:
        `expression` - the CastExpression to process

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

      Visits a catch clause within a try-catch statement.

      Parameters:
        `statement` - the CatchStatement to process

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

      Visits a class expression.

      Parameters:
        `expression` - the ClassExpression to process

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

      Visits a closure expression.

      Parameters:
        `expression` - the ClosureExpression to process

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

      Visits a closure list expression.

      Parameters:
        `expression` - the ClosureListExpression to process

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

      Visits a constant expression (literal value).

      Parameters:
        `expression` - the ConstantExpression to process

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

      Visits a constructor call expression.

      Parameters:
        `expression` - the ConstructorCallExpression to process

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

      Visits a continue statement.

      Parameters:
        `statement` - the ContinueStatement to process

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

      Visits a declaration expression (variable declaration with initialization).

      Parameters:
        `expression` - the DeclarationExpression to process

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

      Visits a do-while loop statement.

      Parameters:
        `statement` - the DoWhileStatement to process

    - #### public void visitEmptyExpression(EmptyExpression expression)

      Visits an empty expression. Default implementation does nothing.

      Parameters:
        `expression` - the EmptyExpression to process

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

      Visits an empty statement. Default implementation does nothing.

      Parameters:
        `statement` - the EmptyStatement to process

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

      Visits an expression statement (an expression used as a statement).

      Parameters:
        `statement` - the ExpressionStatement to process

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

      Visits a field expression.

      Parameters:
        `expression` - the FieldExpression to process

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

      Visits a for loop statement.

      Parameters:
        `statement` - the ForStatement to process

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

      Visits a GString expression (string with interpolations).

      Parameters:
        `expression` - the GStringExpression to process

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

      Visits an if-else statement.

      Parameters:
        `statement` - the IfStatement to process

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

      Visits a lambda expression.

      Parameters:
        `expression` - the LambdaExpression to process

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

      Visits a list expression.

      Parameters:
        `expression` - the ListExpression to process

    - #### public void visitListOfExpressions(List<? extends Expression> list)

      Convenience method to visit a list of expressions. Iterates through the list and calls the visit method on each non-null expression.

      Parameters:
        `list` - the list of Expressions to process, or null to do nothing

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

      Visits a map entry expression (key: value pair within a map).

      Parameters:
        `expression` - the MapEntryExpression to process

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

      Visits a map expression.

      Parameters:
        `expression` - the MapExpression to process

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

      Visits a method call expression.

      Parameters:
        `expression` - the MethodCallExpression to process

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

      Visits a method pointer expression (`object.&methodName`).

      Parameters:
        `expression` - the MethodPointerExpression to process

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

      Visits a method reference expression (obj::method).

      Parameters:
        `expression` - the MethodReferenceExpression to process

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

      Visits a not expression (!expr).

      Parameters:
        `expression` - the NotExpression to process

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

      Visits a postfix expression (expr op).

      Parameters:
        `expression` - the PostfixExpression to process

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

      Visits a prefix expression (op expr).

      Parameters:
        `expression` - the PrefixExpression to process

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

      Visits a property expression (object.property).

      Parameters:
        `expression` - the PropertyExpression to process

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

      Visits a range expression.

      Parameters:
        `expression` - the RangeExpression to process

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

      Visits a return statement.

      Parameters:
        `statement` - the ReturnStatement to process

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

      Visits an Elvis operator expression (shorthand ternary with implicit condition check).

      Parameters:
        `expression` - the ElvisOperatorExpression to process

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

      Visits a spread expression (*expr, spreading collection elements).

      Parameters:
        `expression` - the SpreadExpression to process

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

      Visits a spread map expression (*:map, spreading map entries).

      Parameters:
        `expression` - the SpreadMapExpression to process

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

      Visits a static method call expression.

      Parameters:
        `expression` - the StaticMethodCallExpression to process

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

      Visits a switch statement.

      Parameters:
        `statement` - the SwitchStatement to process

    - #### public void visitSwitchExpression(SwitchExpression expression)

      Visits a first-class switch expression (JEP 361). The default implementation visits the selector, each case, and the default arm so existing visitors keep traversing without a source change.

      Parameters:
        `expression` - the SwitchExpression to process
      Since:
        6.0.0

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

      Visits a synchronized statement.

      Parameters:
        `statement` - the SynchronizedStatement to process

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

      Visits a ternary expression (condition ? trueExpr : falseExpr).

      Parameters:
        `expression` - the TernaryExpression to process

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

      Visits a throw statement.

      Parameters:
        `statement` - the ThrowStatement to process

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

      Visits a try-catch-finally statement.

      Parameters:
        `statement` - the TryCatchStatement to process

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

      Visits a tuple expression (comma-separated expressions grouped in parentheses).

      Parameters:
        `expression` - the TupleExpression to process

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

      Visits a unary minus expression (-expr).

      Parameters:
        `expression` - the UnaryMinusExpression to process

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

      Visits a unary plus expression (+expr).

      Parameters:
        `expression` - the UnaryPlusExpression to process

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

      Visits a variable expression.

      Parameters:
        `expression` - the VariableExpression to process

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

      Visits a while loop statement.

      Parameters:
        `statement` - the WhileStatement to process

    - #### public void visitYieldStatement(YieldStatement statement)

      Visits a `yield` statement that produces the value of an enclosing SwitchExpression. The default implementation visits the yielded expression so existing visitors keep traversing without a source change.

      Parameters:
        `statement` - the YieldStatement to process
      Since:
        6.0.0