Interface marking an AST node as representing a variable in Groovy/Java scope. Typical implementations include org.codehaus.groovy.ast.expr.VariableExpression, FieldNode, PropertyNode, and Parameter. Provides unified access to variable metadata such as type, scope con
| 39 | * @see Parameter |
| 40 | */ |
| 41 | public interface Variable { |
| 42 | |
| 43 | /** |
| 44 | * Returns the name of the variable. |
| 45 | * |
| 46 | * @return the variable name |
| 47 | */ |
| 48 | String getName(); |
| 49 | |
| 50 | /** |
| 51 | * Returns the type of the variable. If the type is not yet determined, |
| 52 | * implementations may return a dynamic or placeholder type. |
| 53 | * |
| 54 | * @return the {@link ClassNode} representing this variable's type |
| 55 | */ |
| 56 | ClassNode getType(); |
| 57 | |
| 58 | /** |
| 59 | * Returns the original type of this variable before any type wrapping or transformation. |
| 60 | * For primitive types, this preserves the distinction between boxed and unboxed forms. |
| 61 | * |
| 62 | * @return the original {@link ClassNode} before transformations |
| 63 | */ |
| 64 | ClassNode getOriginType(); |
| 65 | |
| 66 | /** |
| 67 | * Returns the initialization expression for this variable, or null if no initialization is present. |
| 68 | * For fields and local variables, this may contain the right-hand side of an assignment; |
| 69 | * for parameters, this represents a default value. |
| 70 | * |
| 71 | * @return the initialization {@link Expression}, or null |
| 72 | */ |
| 73 | Expression getInitialExpression(); |
| 74 | |
| 75 | /** |
| 76 | * Returns true if this variable has an initialization expression. |
| 77 | * |
| 78 | * @return true if initialized |
| 79 | */ |
| 80 | boolean hasInitialExpression(); |
| 81 | |
| 82 | /** |
| 83 | * Returns true if this variable is shared with and accessed by nested closures. |
| 84 | * Shared variables require special handling in bytecode generation to ensure proper access semantics. |
| 85 | * |
| 86 | * @return true if shared with closures |
| 87 | */ |
| 88 | default boolean isClosureSharedVariable() { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Marks this variable as shared with nested closures. |
| 94 | * This affects code generation and variable access patterns. |
| 95 | * |
| 96 | * @param inClosure true if shared with closures |
| 97 | */ |
| 98 | default void setClosureSharedVariable(boolean inClosure) { |
no outgoing calls
no test coverage detected