Package org.codehaus.groovy.ast
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 TypeMethodDescriptionReturns the initialization expression for this variable, or null if no initialization is present.intReturns the modifiers (access flags) for this variable as perorg.objectweb.asm.Opcodes.getName()Returns the name of the variable.Returns the original type of this variable before any type wrapping or transformation.getType()Returns the type of the variable.booleanReturns true if this variable has an initialization expression.default booleanReturns true if this variable is shared with and accessed by nested closures.booleanReturns true if this variable has dynamic type information that could not be resolved at compile time.default booleanisFinal()Returns true if this variable is declared with thefinalmodifier.booleanReturns true if this variable is declared or used in a static context.default booleanReturns true if this variable is declared with theprivatemodifier.default booleanReturns true if this variable is declared with theprotectedmodifier.default booleanisPublic()Returns true if this variable is declared with thepublicmodifier.default booleanisStatic()Returns true if this variable is declared with thestaticmodifier.default booleanReturns true if this variable is declared with thevolatilemodifier, indicating that memory visibility is required for multi-threaded access.default voidsetClosureSharedVariable(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
ClassNoderepresenting 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
ClassNodebefore 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
-
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 perorg.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 thefinalmodifier.- Returns:
- true if final
- Since:
- 5.0.0
-
isPrivate
default boolean isPrivate()Returns true if this variable is declared with theprivatemodifier.- Returns:
- true if private
- Since:
- 5.0.0
-
isProtected
default boolean isProtected()Returns true if this variable is declared with theprotectedmodifier.- Returns:
- true if protected
- Since:
- 5.0.0
-
isPublic
default boolean isPublic()Returns true if this variable is declared with thepublicmodifier.- Returns:
- true if public
- Since:
- 5.0.0
-
isStatic
default boolean isStatic()Returns true if this variable is declared with thestaticmodifier.- Returns:
- true if static
- Since:
- 5.0.0
-
isVolatile
default boolean isVolatile()Returns true if this variable is declared with thevolatilemodifier, indicating that memory visibility is required for multi-threaded access.- Returns:
- true if volatile
- Since:
- 5.0.0
-