Package org.codehaus.groovy.ast.expr
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:
GroovydocHolder<AnnotatedNode>
,NodeMetaDataHandler
,Variable
public class VariableExpression extends Expression implements Variable
Represents a local variable name, the simplest form of expression. e.g. "foo".
-
Field Summary
Fields Modifier and Type Field Description static VariableExpression
SUPER_EXPRESSION
static VariableExpression
THIS_EXPRESSION
Fields inherited from class org.codehaus.groovy.ast.expr.Expression
EMPTY_ARRAY
Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT
-
Constructor Summary
Constructors Constructor Description VariableExpression(java.lang.String variable)
VariableExpression(java.lang.String name, ClassNode type)
VariableExpression(Variable variable)
-
Method Summary
Modifier and Type Method Description Variable
getAccessedVariable()
Expression
getInitialExpression()
expression used to initialize the variable or null of there is no initialization.int
getModifiers()
java.lang.String
getName()
the name of the variableClassNode
getOriginType()
Returns the type which was used when this variable expression was created.java.lang.String
getText()
ClassNode
getType()
the type of the variableboolean
hasInitialExpression()
returns true if there is an initialization expressionboolean
isClosureSharedVariable()
Tells if this variable or the accessed variable is used in a closure context, like in the following example :boolean
isDynamicTyped()
boolean
isInStaticContext()
returns true if this variable is used in a static context.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: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.java.lang.String
toString()
Expression
transformExpression(ExpressionTransformer transformer)
Return a copy of the expression calling the transformer on any nested expressionsvoid
visit(GroovyCodeVisitor visitor)
Methods inherited from class org.codehaus.groovy.ast.expr.Expression
transformExpressions, transformExpressions
Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic
Methods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Field Details
-
THIS_EXPRESSION
-
SUPER_EXPRESSION
-
-
Constructor Details
-
VariableExpression
-
VariableExpression
public VariableExpression(java.lang.String variable) -
VariableExpression
-
-
Method Details
-
getAccessedVariable
-
setAccessedVariable
-
visit
-
transformExpression
Description copied from class:Expression
Return a copy of the expression calling the transformer on any nested expressions- Specified by:
transformExpression
in classExpression
-
getText
public java.lang.String getText() -
getName
public java.lang.String getName()Description copied from interface:Variable
the name of the variable -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getInitialExpression
Description copied from interface:Variable
expression used to initialize the variable or null of there is no initialization.- Specified by:
getInitialExpression
in interfaceVariable
-
hasInitialExpression
public boolean hasInitialExpression()Description copied from interface:Variable
returns true if there is an initialization expression- Specified by:
hasInitialExpression
in interfaceVariable
-
isInStaticContext
public boolean isInStaticContext()Description copied from interface:Variable
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- Specified by:
isInStaticContext
in interfaceVariable
-
setInStaticContext
public void setInStaticContext(boolean inStaticContext) -
setType
Set the type of this variable. If you call this method from an AST transformation and that theaccessed variable
is (shared
, this operation is unsafe and may lead to a verify error at compile time. Instead, set the type of theaccessed variable
- Overrides:
setType
in classExpression
- Parameters:
cn
- the type to be set on this variable
-
isDynamicTyped
public boolean isDynamicTyped()- Specified by:
isDynamicTyped
in interfaceVariable
-
getModifiers
public int getModifiers()- Specified by:
getModifiers
in interfaceVariable
-
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
-
-
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. -
getType
Description copied from interface:Variable
the type of the variable- Specified by:
getType
in interfaceVariable
- Overrides:
getType
in classExpression
-
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.- Specified by:
getOriginType
in interfaceVariable
- Returns:
- the type which was used to define this variable expression
-
isThisExpression
public boolean isThisExpression() -
isSuperExpression
public boolean isSuperExpression() -
setModifiers
public void setModifiers(int modifiers)
-