Package: org.codehaus.groovy.classgen

## [Java] Class VariableScopeVisitor

- org.codehaus.groovy.classgen.VariableScopeVisitor

-     public class VariableScopeVisitor
      extends ClassCodeVisitorSupport

  Initializes the variable scopes for an AST.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `VariableScopeVisitor(SourceUnit source, boolean recurseInnerClasses)` Creates a new variable scope visitor with optional recursion into inner classes.
    `VariableScopeVisitor(SourceUnit source)` Creates a new variable scope visitor that does not recurse into inner classes.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected SourceUnit` | `getSourceUnit()` * Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * * Returns: the source unit for this visitor
    `` | `public void` | `prepareVisit(ClassNode node)` Sets the current class node context.
    `` | `protected void` | `visitAnnotation(AnnotationNode node)` * Visits an individual AnnotationNode, traversing all member expression values. * Subclasses may override to perform custom annotation processing. * * Parameters: `node` - the annotation node to visit
    `` | `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, invoking the statement hook before parent traversal. * * Parameters: `statement` - the assert statement to visit
    `` | `public void` | `visitBinaryExpression(BinaryExpression expression)` * Visits a BinaryExpression, traversing left and right operand expressions. * * Parameters: `expression` - the binary expression
    `` | `public void` | `visitBlockStatement(BlockStatement statement)` * Visits a BlockStatement, invoking the statement hook before parent traversal. * * Parameters: `statement` - the block statement to visit
    `` | `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, processing variable annotations and invoking the statement hook. * * Parameters: `statement` - the catch statement to visit
    `` | `public void` | `visitClass(ClassNode node)` * Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * * Parameters: `node` - the class node to visit
    `` | `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 with annotation processing, traversing parameter annotations * before delegating to parent traversal. * * Parameters: `expression` - the closure expression to visit
    `` | `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 expression)` * Visits a ConstructorCallExpression, traversing its argument list. * * Parameters: `call` - the constructor call expression
    `` | `protected void` | `visitConstructorOrMethod(MethodNode node, boolean isConstructor)` * Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * * Parameters: `node` - the method or constructor node * `isConstructor` - true if node is a constructor, false if it is a method
    `` | `public void` | `visitDeclarationExpression(DeclarationExpression expression)` * Visits a DeclarationExpression with annotation processing, traversing expression annotations * before delegating to parent traversal. * * Parameters: `expression` - the declaration expression to visit
    `` | `public void` | `visitDoWhileLoop(DoWhileStatement statement)` * Visits a DoWhileStatement, invoking statement hooks before parent traversal. * * Parameters: `statement` - the do-while statement to visit
    `` | `public void` | `visitExpressionStatement(ExpressionStatement statement)` * Visits an ExpressionStatement, invoking the statement hook before parent traversal. * * Parameters: `statement` - the expression statement to visit
    `` | `public void` | `visitField(FieldNode node)` * Visits a FieldNode, processing its annotations and initial value expression if present. * * Parameters: `node` - the field node to visit
    `` | `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, invoking statement hooks and processing loop variable annotations. * * Parameters: `statement` - the for statement to visit
    `` | `public void` | `visitIfElse(IfStatement statement)` * Visits an IfStatement, invoking the statement hook before parent traversal. * * Parameters: `statement` - the if statement to visit
    `` | `public void` | `visitMethodCallExpression(MethodCallExpression expression)` * Visits a MethodCallExpression, traversing the object expression, * method expression, and argument list. * * Parameters: `call` - the method call expression
    `` | `public void` | `visitProperty(PropertyNode node)` * Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * * Parameters: `node` - the property node to visit
    `` | `public void` | `visitPropertyExpression(PropertyExpression expression)` * Visits a PropertyExpression, traversing the object and property name expressions. * * Parameters: `expression` - the property expression
    `` | `public void` | `visitReturnStatement(ReturnStatement statement)` * Visits a ReturnStatement, invoking the statement hook before parent traversal. * * Parameters: `statement` - the return statement to visit
    `` | `public void` | `visitSwitch(SwitchStatement statement)` * Visits a SwitchStatement, invoking the statement hook before parent traversal. * * Parameters: `statement` - the switch statement to visit
    `` | `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, invoking statement hooks before parent traversal. * * Parameters: `statement` - the while statement to visit

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

- - ### Constructor Detail

    - #### public VariableScopeVisitor(SourceUnit source, boolean recurseInnerClasses)

      Creates a new variable scope visitor with optional recursion into inner classes.

      Parameters:
        `source` - the source unit being processed
        `recurseInnerClasses` - whether to recurse into inner classes

    - #### public VariableScopeVisitor(SourceUnit source)

      Creates a new variable scope visitor that does not recurse into inner classes.

      Parameters:
        `source` - the source unit being processed

  - ### Method Detail

    - #### protected SourceUnit getSourceUnit()

      * Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * *

      Returns:
        the source unit for this visitor

    - #### public void prepareVisit(ClassNode node)

      Sets the current class node context.

    - #### protected void visitAnnotation(AnnotationNode node)

      * Visits an individual AnnotationNode, traversing all member expression values. * Subclasses may override to perform custom annotation processing. * *

      Parameters:
        `node` - the annotation node to visit

    - #### 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, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the assert statement to visit

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

      * Visits a BinaryExpression, traversing left and right operand expressions. * *

      Parameters:
        `expression` - the binary expression

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

      * Visits a BlockStatement, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the block statement to visit

    - #### 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, processing variable annotations and invoking the statement hook. * *

      Parameters:
        `statement` - the catch statement to visit

    - #### public void visitClass(ClassNode node)

      * Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * *

      Parameters:
        `node` - the class node to visit

    - #### 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 with annotation processing, traversing parameter annotations * before delegating to parent traversal. * *

      Parameters:
        `expression` - the closure expression to visit

    - #### 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 expression)

      * Visits a ConstructorCallExpression, traversing its argument list. * *

      Parameters:
        `call` - the constructor call expression

    - #### protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

      * Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * *

      Parameters:
        `node` - the method or constructor node *
        `isConstructor` - true if node is a constructor, false if it is a method

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

      * Visits a DeclarationExpression with annotation processing, traversing expression annotations * before delegating to parent traversal. * *

      Parameters:
        `expression` - the declaration expression to visit

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

      * Visits a DoWhileStatement, invoking statement hooks before parent traversal. * *

      Parameters:
        `statement` - the do-while statement to visit

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

      * Visits an ExpressionStatement, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the expression statement to visit

    - #### public void visitField(FieldNode node)

      * Visits a FieldNode, processing its annotations and initial value expression if present. * *

      Parameters:
        `node` - the field node to visit

    - #### 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, invoking statement hooks and processing loop variable annotations. * *

      Parameters:
        `statement` - the for statement to visit

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

      * Visits an IfStatement, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the if statement to visit

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

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

      Parameters:
        `call` - the method call expression

    - #### public void visitProperty(PropertyNode node)

      * Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * *

      Parameters:
        `node` - the property node to visit

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

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

      Parameters:
        `expression` - the property expression

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

      * Visits a ReturnStatement, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the return statement to visit

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

      * Visits a SwitchStatement, invoking the statement hook before parent traversal. * *

      Parameters:
        `statement` - the switch statement to visit

    - #### 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, invoking statement hooks before parent traversal. * *

      Parameters:
        `statement` - the while statement to visit