public class VariableExpression extends Expression
Represents a local variable name, the simplest form of expression. e.g. "foo".
| Modifiers | Name | Description | 
|---|---|---|
| static VariableExpression | SUPER_EXPRESSION | |
| static VariableExpression | THIS_EXPRESSION | 
| Type | Name and description | 
|---|---|
| Variable | accessedVariable | 
| boolean | closureSharedVariable | 
| boolean | inStaticContext | 
| int | modifiers | 
| ClassNode | type | 
| boolean | useReferenceDirectly | 
| Constructor and description | 
|---|
| VariableExpression
                                (String name, ClassNode type) | 
| VariableExpression
                                (String variable) | 
| VariableExpression
                                (Variable variable) | 
| Type Params | Return Type | Name and description | 
|---|---|---|
|  | Variable | getAccessedVariable() | 
|  | Expression | getInitialExpression() | 
|  | int | getModifiers() | 
|  | String | getName() | 
|  | ClassNode | getOriginType()Returns the type which was used when this variable expression was created. | 
|  | String | getText() | 
|  | ClassNode | getType() | 
|  | boolean | hasInitialExpression() | 
|  | boolean | isClosureSharedVariable()Tells if this variable or the accessed variable is used in a closure context, like in the following example : def str = 'Hello'
 def cl = { println str }
 The "str" variable is closure shared. | 
|  | boolean | isDynamicTyped() | 
|  | boolean | isInStaticContext() | 
|  | boolean | isSuperExpression() | 
|  | boolean | isThisExpression() | 
|  | boolean | isUseReferenceDirectly()For internal use only. | 
|  | void | setAccessedVariable(Variable origin) | 
|  | void | setClosureSharedVariable(boolean inClosure)Use this method to tell if a variable is used in a closure, like in the following example: def str = 'Hello'
 def cl = { println str }
 The "str" variable is closure shared. | 
|  | void | setInStaticContext(boolean inStaticContext) | 
|  | void | setModifiers(int modifiers) | 
|  | void | setType(ClassNode cn)Set the type of this variable. | 
|  | void | setUseReferenceDirectly(boolean useRef)For internal use only. | 
|  | String | toString() | 
|  | Expression | transformExpression(ExpressionTransformer transformer) | 
|  | void | visit(GroovyCodeVisitor visitor) | 
| Methods inherited from class | Name | 
|---|---|
| class Expression | getType, setType, transformExpression, transformExpressions, transformExpressions | 
| class AnnotatedNode | addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic | 
| class ASTNode | copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getNodeMetaData, getNodeMetaData, getText, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition, visit | 
Returns the type which was used when this variable expression was created. For example, getType() may return a boxed type while this method would return the primitive type.
Tells if this variable or the accessed variable is used in a closure context, like in the following example :
def str = 'Hello'
 def cl = { println str }
 
 The "str" variable is closure shared.
     For internal use only. This flag is used by compiler internals and should probably be converted to a node metadata in future.
Use this method to tell if a variable is used in a closure, like in the following example:
def str = 'Hello'
 def cl = { println str }
 
 The "str" variable is closure shared. The variable expression inside the closure references an
 accessed variable "str" which must have the closure shared flag set.
     inClosure -  tells if this variable is later referenced in a closureSet the type of this variable. If you call this method from an AST transformation and that the accessed variable is (shared, this operation is unsafe and may lead to a verify error at compile time. Instead, set the type of the accessed variable
cn -  the type to be set on this variableFor internal use only. This flag is used by compiler internals and should probably be converted to a node metadata in future.
Copyright © 2003-2021 The Apache Software Foundation. All rights reserved.