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:
- Variable
 
 public class VariableExpression extends Expression implements Variable Represents a local variable name, the simplest form of expression. e.g. "foo".
- 
- 
Field SummaryFields Modifier and Type Field Description static VariableExpressionSUPER_EXPRESSIONstatic VariableExpressionTHIS_EXPRESSION
 - 
Constructor SummaryConstructors Constructor Description VariableExpression(java.lang.String variable)VariableExpression(java.lang.String name, ClassNode type)VariableExpression(Variable variable)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description VariablegetAccessedVariable()ExpressiongetInitialExpression()expression used to initialize the variable or null of there is no initialization.intgetModifiers()java.lang.StringgetName()the name of the variableClassNodegetOriginType()Returns the type which was used when this variable expression was created.java.lang.StringgetText()ClassNodegetType()the type of the variablebooleanhasInitialExpression()returns true if there is an initialization expressionbooleanisClosureSharedVariable()Tells if this variable or the accessed variable is used in a closure context, like in the following example :booleanisDynamicTyped()booleanisInStaticContext()returns true if this variable is used in a static context.booleanisSuperExpression()booleanisThisExpression()booleanisUseReferenceDirectly()For internal use only.voidsetAccessedVariable(Variable origin)voidsetClosureSharedVariable(boolean inClosure)Use this method to tell if a variable is used in a closure, like in the following example:voidsetInStaticContext(boolean inStaticContext)voidsetModifiers(int modifiers)voidsetType(ClassNode cn)Set the type of this variable.voidsetUseReferenceDirectly(boolean useRef)For internal use only.java.lang.StringtoString()ExpressiontransformExpression(ExpressionTransformer transformer)Return a copy of the expression calling the transformer on any nested expressionsvoidvisit(GroovyCodeVisitor visitor)- 
Methods inherited from class org.codehaus.groovy.ast.expr.ExpressiontransformExpressions, transformExpressions
 - 
Methods inherited from class org.codehaus.groovy.ast.AnnotatedNodeaddAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic
 - 
Methods inherited from class org.codehaus.groovy.ast.ASTNodecopyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getNodeMetaData, getNodeMetaData, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition
 
- 
 
- 
- 
- 
Field Detail- 
THIS_EXPRESSIONpublic static final VariableExpression THIS_EXPRESSION 
 - 
SUPER_EXPRESSIONpublic static final VariableExpression SUPER_EXPRESSION 
 
- 
 - 
Method Detail- 
getAccessedVariablepublic Variable getAccessedVariable() 
 - 
setAccessedVariablepublic void setAccessedVariable(Variable origin) 
 - 
visitpublic void visit(GroovyCodeVisitor visitor) 
 - 
transformExpressionpublic Expression transformExpression(ExpressionTransformer transformer) Description copied from class:ExpressionReturn a copy of the expression calling the transformer on any nested expressions- Specified by:
- transformExpressionin class- Expression
 
 - 
getNamepublic java.lang.String getName() Description copied from interface:Variablethe name of the variable
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
getInitialExpressionpublic Expression getInitialExpression() Description copied from interface:Variableexpression used to initialize the variable or null of there is no initialization.- Specified by:
- getInitialExpressionin interface- Variable
 
 - 
hasInitialExpressionpublic boolean hasInitialExpression() Description copied from interface:Variablereturns true if there is an initialization expression- Specified by:
- hasInitialExpressionin interface- Variable
 
 - 
isInStaticContextpublic boolean isInStaticContext() Description copied from interface:Variablereturns 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:
- isInStaticContextin interface- Variable
 
 - 
setInStaticContextpublic void setInStaticContext(boolean inStaticContext) 
 - 
setTypepublic void setType(ClassNode cn) Set the type of this variable. If you call this method from an AST transformation and that theaccessed variableis (shared, this operation is unsafe and may lead to a verify error at compile time. Instead, set the type of theaccessed variable- Overrides:
- setTypein class- Expression
- Parameters:
- cn- the type to be set on this variable
 
 - 
isDynamicTypedpublic boolean isDynamicTyped() - Specified by:
- isDynamicTypedin interface- Variable
 
 - 
isClosureSharedVariablepublic 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.- Specified by:
- isClosureSharedVariablein interface- Variable
- Returns:
- true if this variable is used in a closure
 
 - 
setClosureSharedVariablepublic 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.- Specified by:
- setClosureSharedVariablein interface- Variable
- Parameters:
- inClosure- tells if this variable is later referenced in a closure
 
 - 
getModifierspublic int getModifiers() - Specified by:
- getModifiersin interface- Variable
 
 - 
setUseReferenceDirectlypublic 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-
 
 - 
isUseReferenceDirectlypublic boolean isUseReferenceDirectly() For internal use only. This flag is used by compiler internals and should probably be converted to a node metadata in future.
 - 
getTypepublic ClassNode getType() Description copied from interface:Variablethe type of the variable- Specified by:
- getTypein interface- Variable
- Overrides:
- getTypein class- Expression
 
 - 
getOriginTypepublic 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.- Specified by:
- getOriginTypein interface- Variable
- Returns:
- the type which was used to define this variable expression
 
 - 
isThisExpressionpublic boolean isThisExpression() 
 - 
isSuperExpressionpublic boolean isSuperExpression() 
 - 
setModifierspublic void setModifiers(int modifiers) 
 
- 
 
-