public class VariableExpression extends Expression implements Variable
Represents a local variable name, the simplest form of expression. e.g. "foo".
Modifiers | Name | Description |
---|---|---|
static VariableExpression |
SUPER_EXPRESSION |
|
static VariableExpression |
THIS_EXPRESSION |
Fields inherited from class | Fields |
---|---|
class Expression |
EMPTY_ARRAY |
Constructor and description |
---|
VariableExpression
(String variable, ClassNode type) |
VariableExpression
(String variable) |
VariableExpression
(Variable variable) |
Type Params | Return Type | Name and description |
---|---|---|
|
public Variable |
getAccessedVariable() |
|
public Expression |
getInitialExpression() |
|
public int |
getModifiers() |
|
public String |
getName() |
|
public ClassNode |
getOriginType() Returns the type which was used when this variable expression was created. |
|
public String |
getText() |
|
public ClassNode |
getType() |
|
public boolean |
hasInitialExpression() |
|
public 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. |
|
public boolean |
isDynamicTyped() |
|
public boolean |
isInStaticContext() |
|
public boolean |
isSuperExpression() |
|
public boolean |
isThisExpression() |
|
public boolean |
isUseReferenceDirectly() For internal use only. |
|
public void |
setAccessedVariable(Variable origin) |
|
public 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. |
|
public void |
setInStaticContext(boolean inStaticContext) |
|
public void |
setModifiers(int modifiers) |
|
public void |
setType(ClassNode cn) Set the type of this variable. |
|
public void |
setUseReferenceDirectly(boolean useRef) For internal use only. |
|
public String |
toString() |
|
public Expression |
transformExpression(ExpressionTransformer transformer) |
|
public void |
visit(GroovyCodeVisitor visitor) |
Methods inherited from class | Name |
---|---|
class Expression |
getType, setType, transformExpression, transformExpressions, transformExpressions |
class AnnotatedNode |
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, 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-2020 The Apache Software Foundation. All rights reserved.