VariableExpression (groovy 2.4.16 API)
Date: 2018-12-09

Package: org.codehaus.groovy.ast.expr

## [Java] Class VariableExpression

- org.codehaus.groovy.ast.expr.VariableExpression

- All Implemented Interfaces and Traits:
    Variable

      public class VariableExpression
      extends Expression

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

  Authors:
    James Strachan

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static VariableExpression` | `SUPER_EXPRESSION` |
    `static VariableExpression` | `THIS_EXPRESSION` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `VariableExpression (String variable, ClassNode type)`
    `VariableExpression (String variable)`
    `VariableExpression (Variable variable)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `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)`

  - ### Inherited Methods Summary

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

- - ### Field Detail

    - #### public static final VariableExpression SUPER_EXPRESSION

    - #### public static final VariableExpression THIS_EXPRESSION

  - ### Constructor Detail

    - #### public VariableExpression(String variable, ClassNode type)

    - #### public VariableExpression(String variable)

    - #### public VariableExpression(Variable variable)

  - ### Method Detail

    - #### public Variable getAccessedVariable()

    - #### public Expression getInitialExpression()

    - #### public int getModifiers()

    - #### public String getName()

    - #### 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

    - #### public String getText()

    - #### public ClassNode getType()

    - #### public boolean hasInitialExpression()

    - #### 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

    - #### public boolean isDynamicTyped()

    - #### public boolean isInStaticContext()

    - #### public boolean isSuperExpression()

    - #### public boolean isThisExpression()

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

    - #### public void setAccessedVariable(Variable origin)

    - #### 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

    - #### public void setInStaticContext(boolean inStaticContext)

    - #### public void setModifiers(int modifiers)

    - #### 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

    - #### 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

    - #### public String toString()

    - #### public Expression transformExpression(ExpressionTransformer transformer)

    - #### public void visit(GroovyCodeVisitor visitor)