Groovy 2.2.1

org.codehaus.groovy.ast.expr
[Java] Class VariableExpression

java.lang.Object
  org.codehaus.groovy.ast.ASTNode
      org.codehaus.groovy.ast.AnnotatedNode
          org.codehaus.groovy.ast.expr.Expression
              org.codehaus.groovy.ast.expr.VariableExpression
All Implemented Interfaces:
Variable

public class VariableExpression
extends Expression

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

Authors:
James Strachan
Version:
\$Revision\$


Field Summary
static VariableExpression SUPER_EXPRESSION

static VariableExpression THIS_EXPRESSION

 
Constructor Summary
VariableExpression(String variable, ClassNode type)

VariableExpression(String variable)

VariableExpression(Variable variable)

 
Method Summary
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 Expression
getType, setType, transformExpression, transformExpressions, transformExpressions
 
Methods inherited from class AnnotatedNode
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic
 
Methods inherited from class ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getNodeMetaData, getText, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition, visit
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

SUPER_EXPRESSION

public static final VariableExpression SUPER_EXPRESSION


THIS_EXPRESSION

public static final VariableExpression THIS_EXPRESSION


 
Constructor Detail

VariableExpression

public VariableExpression(String variable, ClassNode type)


VariableExpression

public VariableExpression(String variable)


VariableExpression

public VariableExpression(Variable variable)


 
Method Detail

getAccessedVariable

public Variable getAccessedVariable()


getInitialExpression

public Expression getInitialExpression()


getModifiers

public int getModifiers()


getName

public String getName()


getOriginType

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


getText

public String getText()


getType

public ClassNode getType()


hasInitialExpression

public boolean hasInitialExpression()


isClosureSharedVariable

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


isDynamicTyped

public boolean isDynamicTyped()


isInStaticContext

public boolean isInStaticContext()


isSuperExpression

public boolean isSuperExpression()


isThisExpression

public boolean isThisExpression()


isUseReferenceDirectly

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.


setAccessedVariable

public void setAccessedVariable(Variable origin)


setClosureSharedVariable

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


setInStaticContext

public void setInStaticContext(boolean inStaticContext)


setModifiers

public void setModifiers(int modifiers)


setType

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


setUseReferenceDirectly

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


toString

public String toString()


transformExpression

public Expression transformExpression(ExpressionTransformer transformer)


visit

public void visit(GroovyCodeVisitor visitor)


 

Copyright © 2003-2013 The Codehaus. All rights reserved.