VariableExpression (Groovy 5.1.0)
Description: declaration: package: org.codehaus.groovy.ast.expr, class: VariableExpression

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>`, `Cloneable`, `NodeMetaDataHandler`, `Variable`

public class VariableExpression extends Expression implements Cloneable, Variable
Represents a local variable, the simplest form of expression. e.g. "foo".

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final VariableExpression`
  `SUPER_EXPRESSION`
  `static final 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(String name)`
  `VariableExpression(String name, ClassNode type)`
  `VariableExpression(Variable av)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `VariableExpression`
  `clone()`
  `Variable`
  `getAccessedVariable()`
  `Expression`
  `getInitialExpression()`
  Returns the expression used to initialize the variable or null of there is no initialization.
  `int`
  `getModifiers()`
  `String`
  `getName()`
  Returns the name of the variable.
  `ClassNode`
  `getOriginType()`
  Returns the type which was used when this variable expression was created.
  `String`
  `getText()`
  `ClassNode`
  `getType()`
  Returns the type of the variable.
  `boolean`
  `hasInitialExpression()`
  Returns true if there is an initialization expression.
  `boolean`
  `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 variable)`
  `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 type)`
  Set the type of this variable.
  `void`
  `setUseReferenceDirectly(boolean useRef)`
  For internal use only.
  `String`
  `toString()`
  `Expression`
  `transformExpression(ExpressionTransformer transformer)`
  Transforms this expression and any nested expressions.
  `void`
  `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, 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

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

  ### Methods inherited from interface org.codehaus.groovy.ast.Variable

  `isFinal, isPrivate, isProtected, isPublic, isStatic, isVolatile`

- ## Field Details

  - ### THIS_EXPRESSION

    public static final VariableExpression THIS_EXPRESSION

  - ### SUPER_EXPRESSION

    public static final VariableExpression SUPER_EXPRESSION

- ## Constructor Details

  - ### VariableExpression

    public VariableExpression(String name, ClassNode type)

  - ### VariableExpression

    public VariableExpression(String name)

  - ### VariableExpression

    public VariableExpression(Variable av)

- ## Method Details

  - ### clone

    public VariableExpression clone()
    Overrides:
      `clone` in class `Object`

  - ### setAccessedVariable

    public void setAccessedVariable(Variable variable)

  - ### 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.
    Specified by:
      `setClosureSharedVariable` in interface `Variable`
    Parameters:
      `inClosure` - indicates if this variable is referenced from a closure

  - ### setInStaticContext

    public void setInStaticContext(boolean inStaticContext)

  - ### setModifiers

    public void setModifiers(int modifiers)

  - ### setType

    public void setType(ClassNode type)
    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`
    Overrides:
      `setType` in class `Expression`

  - ### 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 the future.

  - ### getAccessedVariable

    public Variable getAccessedVariable()

  - ### getInitialExpression

    public Expression getInitialExpression()
    Description copied from interface: `Variable`
    Returns the expression used to initialize the variable or null of there is no initialization.
    Specified by:
      `getInitialExpression` in interface `Variable`

  - ### hasInitialExpression

    public boolean hasInitialExpression()
    Description copied from interface: `Variable`
    Returns true if there is an initialization expression.
    Specified by:
      `hasInitialExpression` in interface `Variable`

  - ### getModifiers

    public int getModifiers()
    Specified by:
      `getModifiers` in interface `Variable`

  - ### getName

    public String getName()
    Description copied from interface: `Variable`
    Returns the name of the variable.
    Specified by:
      `getName` in interface `Variable`

  - ### getText

    public String getText()
    Overrides:
      `getText` in class `ASTNode`

  - ### getType

    public ClassNode getType()
    Description copied from interface: `Variable`
    Returns the type of the variable.
    Specified by:
      `getType` in interface `Variable`
    Overrides:
      `getType` in class `Expression`

  - ### 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.
    Specified by:
      `getOriginType` in interface `Variable`
    Returns:
      the type which was used to define this variable expression

  - ### 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.
    Specified by:
      `isClosureSharedVariable` in interface `Variable`
    Returns:
      true if this variable is used in a closure

  - ### isDynamicTyped

    public boolean isDynamicTyped()
    Specified by:
      `isDynamicTyped` in interface `Variable`

  - ### 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 interface `Variable`

  - ### 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 the future.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### transformExpression

    public Expression transformExpression(ExpressionTransformer transformer)
    Description copied from class: `Expression`
    Transforms this expression and any nested expressions.
    Specified by:
      `transformExpression` in class `Expression`

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Overrides:
      `visit` in class `ASTNode`