Package: org.codehaus.groovy.ast

## [Java] Interface Variable

-     public interface Variable

  Interface marking an AST node as representing a variable in Groovy/Java scope. Typical implementations include VariableExpression, FieldNode, PropertyNode, and Parameter. Provides unified access to variable metadata such as type, scope context, and modifiers.

  See Also:
    VariableExpression
    FieldNode
    PropertyNode
    Parameter

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Expression` | `getInitialExpression()` Returns the initialization expression for this variable, or null if no initialization is present.
    `` | `public int` | `getModifiers()` Returns the modifiers (access flags) for this variable as per `org.objectweb.asm.Opcodes`.
    `` | `public String` | `getName()` Returns the name of the variable.
    `` | `public ClassNode` | `getOriginType()` Returns the original type of this variable before any type wrapping or transformation.
    `` | `public ClassNode` | `getType()` Returns the type of the variable.
    `` | `public boolean` | `hasInitialExpression()` Returns true if this variable has an initialization expression.
    `` | `public boolean` | `isClosureSharedVariable()` Returns true if this variable is shared with and accessed by nested closures.
    `` | `public boolean` | `isDynamicTyped()` Returns true if this variable has dynamic type information that could not be resolved at compile time.
    `` | `public boolean` | `isFinal()` Returns true if this variable is declared with the `final` modifier.
    `` | `public boolean` | `isInStaticContext()` Returns true if this variable is declared or used in a static context.
    `` | `public boolean` | `isPrivate()` Returns true if this variable is declared with the `private` modifier.
    `` | `public boolean` | `isProtected()` Returns true if this variable is declared with the `protected` modifier.
    `` | `public boolean` | `isPublic()` Returns true if this variable is declared with the `public` modifier.
    `` | `public boolean` | `isStatic()` Returns true if this variable is declared with the `static` modifier.
    `` | `public boolean` | `isVolatile()` Returns true if this variable is declared with the `volatile` modifier, indicating that memory visibility is required for multi-threaded access.
    `` | `public void` | `setClosureSharedVariable(boolean inClosure)` Marks this variable as shared with nested closures.

- - ### Method Detail

    - #### public Expression getInitialExpression()

      Returns the initialization expression for this variable, or null if no initialization is present. For fields and local variables, this may contain the right-hand side of an assignment; for parameters, this represents a default value.

      Returns:
        the initialization Expression, or null

    - #### public int getModifiers()

      Returns the modifiers (access flags) for this variable as per `org.objectweb.asm.Opcodes`. May include visibility modifiers (public, protected, private), `static`, `final`, etc.

      Returns:
        the modifier flags
      See Also:
        org.objectweb.asm.Opcodes

    - #### public String getName()

      Returns the name of the variable.

      Returns:
        the variable name

    - #### public ClassNode getOriginType()

      Returns the original type of this variable before any type wrapping or transformation. For primitive types, this preserves the distinction between boxed and unboxed forms.

      Returns:
        the original ClassNode before transformations

    - #### public ClassNode getType()

      Returns the type of the variable. If the type is not yet determined, implementations may return a dynamic or placeholder type.

      Returns:
        the ClassNode representing this variable's type

    - #### public boolean hasInitialExpression()

      Returns true if this variable has an initialization expression.

      Returns:
        true if initialized

    - #### public boolean isClosureSharedVariable()

      Returns true if this variable is shared with and accessed by nested closures. Shared variables require special handling in bytecode generation to ensure proper access semantics.

      Returns:
        true if shared with closures

    - #### public boolean isDynamicTyped()

      Returns true if this variable has dynamic type information that could not be resolved at compile time.

      Returns:
        true if dynamically typed

    - #### public boolean isFinal()

      Returns true if this variable is declared with the `final` modifier.

      Returns:
        true if final
      Since:
        5.0.0

    - #### public boolean isInStaticContext()

      Returns true if this variable is declared or used in a static context. A static context includes static initializers, static field declarations, static method bodies, and class-level code without instance access.

      Returns:
        true if in a static context

    - #### public boolean isPrivate()

      Returns true if this variable is declared with the `private` modifier.

      Returns:
        true if private
      Since:
        5.0.0

    - #### public boolean isProtected()

      Returns true if this variable is declared with the `protected` modifier.

      Returns:
        true if protected
      Since:
        5.0.0

    - #### public boolean isPublic()

      Returns true if this variable is declared with the `public` modifier.

      Returns:
        true if public
      Since:
        5.0.0

    - #### public boolean isStatic()

      Returns true if this variable is declared with the `static` modifier.

      Returns:
        true if static
      Since:
        5.0.0

    - #### public boolean isVolatile()

      Returns true if this variable is declared with the `volatile` modifier, indicating that memory visibility is required for multi-threaded access.

      Returns:
        true if volatile
      Since:
        5.0.0

    - #### public void setClosureSharedVariable(boolean inClosure)

      Marks this variable as shared with nested closures. This affects code generation and variable access patterns.

      Parameters:
        `inClosure` - true if shared with closures