Top Description Fields Constructors Methods
org.codehaus.groovy.ast.expr

public Class VariableExpression

extends Expression
implements Variable
Class Inheritance
All Implemented Interfaces
org.codehaus.groovy.ast.Variable
Known Direct Subclasses
org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.ParameterVariableExpression
Imports
org.codehaus.groovy.ast.ClassHelper, .ClassNode, .GroovyCodeVisitor, .Variable

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

Field Summary

Modifier and TypeField and Description
private Variable
pack-priv boolean
private boolean
private boolean
private int
private final ClassNode
public static final VariableExpression
public static final VariableExpression
pack-priv boolean
private final String
Inherited from org.codehaus.groovy.ast.expr.Expression:
EMPTY_ARRAY

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public Variable
public Expression
getInitialExpression()

Implements org.codehaus.groovy.ast.Variable.getInitialExpression.

expression used to initialize the variable or null of there is no initialization.
public int
public String
getName()

Implements org.codehaus.groovy.ast.Variable.getName.

the name of the variable
public ClassNode

Returns:

the type which was used to define this variable expression
getOriginType
()

Implements org.codehaus.groovy.ast.Variable.getOriginType.

Returns the type which was used when this variable expression was created.
public String
public ClassNode
public boolean
hasInitialExpression()

Implements org.codehaus.groovy.ast.Variable.hasInitialExpression.

returns true if there is an initialization expression
public boolean

Returns:

true if this variable is used in a closure
isClosureSharedVariable
()

Implements org.codehaus.groovy.ast.Variable.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 }
public boolean
public boolean
isInStaticContext()

Implements org.codehaus.groovy.ast.Variable.isInStaticContext.

returns true if this variable is used in a static context.
public boolean
public boolean
public boolean
isUseReferenceDirectly()

For internal use only.

public void
public void
setClosureSharedVariable(boolean
tells if this variable is later referenced in a closure
inClosure
)

Implements org.codehaus.groovy.ast.Variable.setClosureSharedVariable.

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 }
public void
setInStaticContext(boolean inStaticContext)

public void
setModifiers(int modifiers)

public void
setType(ClassNode
the type to be set on this variable
cn
)

Overrides org.codehaus.groovy.ast.expr.Expression.setType.

Set the type of this variable.
public void
setUseReferenceDirectly(boolean useRef)

For internal use only.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Expression
transformExpression(ExpressionTransformer transformer)

Implements abstract org.codehaus.groovy.ast.expr.Expression.transformExpression.

Return a copy of the expression calling the transformer on any nested expressions
public void
Inherited from org.codehaus.groovy.ast.expr.Expression:
transformExpressionstransformExpressions

Field Detail

accessedVariableback to summary
private Variable accessedVariable
closureShareback to summary
pack-priv boolean closureShare
inStaticContextback to summary
private boolean inStaticContext
isDynamicTypedback to summary
private boolean isDynamicTyped
modifiersback to summary
private int modifiers
originTypeback to summary
private final ClassNode originType
SUPER_EXPRESSIONback to summary
public static final VariableExpression SUPER_EXPRESSION
THIS_EXPRESSIONback to summary
public static final VariableExpression THIS_EXPRESSION
useRefback to summary
pack-priv boolean useRef
variableback to summary
private final String variable

Constructor Detail

VariableExpressionback to summary
public VariableExpression(String name, ClassNode type)
VariableExpressionback to summary
public VariableExpression(String variable)
VariableExpressionback to summary
public VariableExpression(Variable variable)

Method Detail

getAccessedVariableback to summary
public Variable getAccessedVariable()
getInitialExpressionback to summary
public Expression getInitialExpression()

Implements org.codehaus.groovy.ast.Variable.getInitialExpression.

Doc from org.codehaus.groovy.ast.Variable.getInitialExpression.

expression used to initialize the variable or null of there is no initialization.

Annotations
@Override
getModifiersback to summary
public int getModifiers()

Implements org.codehaus.groovy.ast.Variable.getModifiers.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.codehaus.groovy.ast.Variable.getName.

Doc from org.codehaus.groovy.ast.Variable.getName.

the name of the variable

Annotations
@Override
getOriginTypeback to summary
public ClassNode getOriginType()

Implements org.codehaus.groovy.ast.Variable.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:ClassNode

the type which was used to define this variable expression

Annotations
@Override
getTextback to summary
public String getText()

Overrides org.codehaus.groovy.ast.ASTNode.getText.

Annotations
@Override
getTypeback to summary
public ClassNode getType()

Overrides org.codehaus.groovy.ast.expr.Expression.getType.

Implements org.codehaus.groovy.ast.Variable.getType.

Doc from org.codehaus.groovy.ast.Variable.getType.

the type of the variable

Annotations
@Override
hasInitialExpressionback to summary
public boolean hasInitialExpression()

Implements org.codehaus.groovy.ast.Variable.hasInitialExpression.

Doc from org.codehaus.groovy.ast.Variable.hasInitialExpression.

returns true if there is an initialization expression

Annotations
@Override
isClosureSharedVariableback to summary
public boolean isClosureSharedVariable()

Implements org.codehaus.groovy.ast.Variable.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:boolean

true if this variable is used in a closure

Annotations
@Override
isDynamicTypedback to summary
public boolean isDynamicTyped()

Implements org.codehaus.groovy.ast.Variable.isDynamicTyped.

Annotations
@Override
isInStaticContextback to summary
public boolean isInStaticContext()

Implements org.codehaus.groovy.ast.Variable.isInStaticContext.

Doc from org.codehaus.groovy.ast.Variable.isInStaticContext.

returns true if this variable is used in a static context. A static context is any static initializer block, when this variable is declared as static or when this variable is used in a static method

Annotations
@Override
isSuperExpressionback to summary
public boolean isSuperExpression()
isThisExpressionback to summary
public boolean isThisExpression()
isUseReferenceDirectlyback to summary
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.

setAccessedVariableback to summary
public void setAccessedVariable(Variable origin)
setClosureSharedVariableback to summary
public void setClosureSharedVariable(boolean inClosure)

Implements org.codehaus.groovy.ast.Variable.setClosureSharedVariable.

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:boolean

tells if this variable is later referenced in a closure

Annotations
@Override
setInStaticContextback to summary
public void setInStaticContext(boolean inStaticContext)
setModifiersback to summary
public void setModifiers(int modifiers)
setTypeback to summary
public void setType(ClassNode cn)

Overrides org.codehaus.groovy.ast.expr.Expression.setType.

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:ClassNode

the type to be set on this variable

Annotations
@Override
setUseReferenceDirectlyback to summary
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.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transformExpressionback to summary
public Expression transformExpression(ExpressionTransformer transformer)

Implements abstract org.codehaus.groovy.ast.expr.Expression.transformExpression.

Doc from org.codehaus.groovy.ast.expr.Expression.transformExpression.

Return a copy of the expression calling the transformer on any nested expressions

Annotations
@Override
visitback to summary
public void visit(GroovyCodeVisitor visitor)

Overrides org.codehaus.groovy.ast.ASTNode.visit.

Annotations
@Override