[Java] Class VariableExpression

  • org.codehaus.groovy.ast.expr.VariableExpression
All Implemented Interfaces and Traits:
Variable
public class VariableExpression
extends Expression
implements Variable

Represents a local variable name, the simplest form of expression. e.g. "foo".

Field Summary

Fields
Modifiers Name Description
static VariableExpression SUPER_EXPRESSION
static VariableExpression THIS_EXPRESSION
Inherited fields
Fields inherited from class Fields
class Expression EMPTY_ARRAY

Constructor Summary

Constructors
Constructor and description
VariableExpression (String variable, ClassNode type)
VariableExpression (String variable)
VariableExpression (Variable variable)

Methods Summary

Methods
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)

Inherited Methods Summary

Inherited Methods
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

Field Detail

public static final VariableExpression SUPER_EXPRESSION

public static final VariableExpression THIS_EXPRESSION

Constructor Detail

public VariableExpression(String variable, ClassNode type)

public VariableExpression(String variable)

public VariableExpression(Variable variable)

Method Detail

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. For example, getType() may return a boxed type while this method would return the primitive type.

Returns:
the type which was used to define this variable expression

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.
Returns:
true if this variable is used in a closure

public boolean isDynamicTyped()

public boolean isInStaticContext()

public boolean isSuperExpression()

public boolean isThisExpression()

public boolean isUseReferenceDirectly()

For internal use only. This flag is used by compiler internals and should probably be converted to a node metadata in future.

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. The variable expression inside the closure references an accessed variable "str" which must have the closure shared flag set.
Parameters:
inClosure - tells if this variable is later referenced in a closure

public void setInStaticContext(boolean inStaticContext)

public void setModifiers(int modifiers)

public void setType(ClassNode cn)

Set 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

Parameters:
cn - the type to be set on this variable

public void setUseReferenceDirectly(boolean useRef)

For internal use only. This flag is used by compiler internals and should probably be converted to a node metadata in future.

Parameters:
useRef

public String toString()

public Expression transformExpression(ExpressionTransformer transformer)

public void visit(GroovyCodeVisitor visitor)

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/3.0.7/html/gapi/org/codehaus/groovy/ast/expr/VariableExpression.html