Interface Variable

All Known Implementing Classes:
DynamicVariable, FieldNode, Parameter, PropertyNode, VariableExpression

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:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the initialization expression for this variable, or null if no initialization is present.
    int
    Returns the modifiers (access flags) for this variable as per org.objectweb.asm.Opcodes.
    Returns the name of the variable.
    Returns the original type of this variable before any type wrapping or transformation.
    Returns the type of the variable.
    boolean
    Returns true if this variable has an initialization expression.
    default boolean
    Returns true if this variable is shared with and accessed by nested closures.
    boolean
    Returns true if this variable has dynamic type information that could not be resolved at compile time.
    default boolean
    Returns true if this variable is declared with the final modifier.
    boolean
    Returns true if this variable is declared or used in a static context.
    default boolean
    Returns true if this variable is declared with the private modifier.
    default boolean
    Returns true if this variable is declared with the protected modifier.
    default boolean
    Returns true if this variable is declared with the public modifier.
    default boolean
    Returns true if this variable is declared with the static modifier.
    default boolean
    Returns true if this variable is declared with the volatile modifier, indicating that memory visibility is required for multi-threaded access.
    default void
    setClosureSharedVariable(boolean inClosure)
    Marks this variable as shared with nested closures.
  • Method Details

    • getName

      String getName()
      Returns the name of the variable.
      Returns:
      the variable name
    • getType

      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
    • getOriginType

      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
    • getInitialExpression

      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
    • hasInitialExpression

      boolean hasInitialExpression()
      Returns true if this variable has an initialization expression.
      Returns:
      true if initialized
    • isClosureSharedVariable

      default 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
    • setClosureSharedVariable

      default 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
    • isInStaticContext

      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
    • isDynamicTyped

      boolean isDynamicTyped()
      Returns true if this variable has dynamic type information that could not be resolved at compile time.
      Returns:
      true if dynamically typed
    • getModifiers

      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:
      • Opcodes
    • isFinal

      default boolean isFinal()
      Returns true if this variable is declared with the final modifier.
      Returns:
      true if final
      Since:
      5.0.0
    • isPrivate

      default boolean isPrivate()
      Returns true if this variable is declared with the private modifier.
      Returns:
      true if private
      Since:
      5.0.0
    • isProtected

      default boolean isProtected()
      Returns true if this variable is declared with the protected modifier.
      Returns:
      true if protected
      Since:
      5.0.0
    • isPublic

      default boolean isPublic()
      Returns true if this variable is declared with the public modifier.
      Returns:
      true if public
      Since:
      5.0.0
    • isStatic

      default boolean isStatic()
      Returns true if this variable is declared with the static modifier.
      Returns:
      true if static
      Since:
      5.0.0
    • isVolatile

      default 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