VariableExpression (Groovy 5.1.0)

Package: org.codehaus.groovy.ast.expr

## [Java] Class VariableExpression

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

- All Implemented Interfaces and Traits:
    Cloneable, Variable

      public class VariableExpression
      extends Expression
      implements Cloneable, Variable

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

- - ### Field Summary

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

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class Expression` | `EMPTY_ARRAY`

  - ### Constructor Summary

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

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public VariableExpression` | `clone()`
    `` | `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.
    `` | `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.
    `` | `public boolean` | `isDynamicTyped()`
    `` | `public boolean` | `isInStaticContext()`
    `` | `public boolean` | `isSuperExpression()`
    `` | `public boolean` | `isThisExpression()`
    `` | `public boolean` | `isUseReferenceDirectly()` For internal use only.
    `` | `public void` | `setAccessedVariable(Variable variable)`
    `` | `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.
    `` | `public void` | `setInStaticContext(boolean inStaticContext)`
    `` | `public void` | `setModifiers(int modifiers)`
    `` | `public void` | `setType(ClassNode type)` Set the type of this variable.
    `` | `public void` | `setUseReferenceDirectly(boolean useRef)` For internal use only.
    `` | `public String` | `toString()`
    `` | `public Expression` | `transformExpression(ExpressionTransformer transformer)`
    `` | `public void` | `visit(GroovyCodeVisitor visitor)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Expression` | `getType, setType, transformExpression, transformExpressions, transformExpressions`
    `class AnnotatedNode` | `addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic`
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Field Detail

    - #### public static final VariableExpression SUPER_EXPRESSION

    - #### public static final VariableExpression THIS_EXPRESSION

  - ### Constructor Detail

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

    - #### public VariableExpression(String name)

    - #### public VariableExpression(Variable av)

  - ### Method Detail

    - #### @Override
      public VariableExpression clone()

    - #### public Variable getAccessedVariable()

    - #### @Override
      public Expression getInitialExpression()

    - #### @Override
      public int getModifiers()

    - #### @Override
      public String getName()

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

    - #### @Override
      public String getText()

    - #### @Override
      public ClassNode getType()

    - #### @Override
      public boolean hasInitialExpression()

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

    - #### @Override
      public boolean isDynamicTyped()

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

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

    - #### @Override
      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` - indicates if this variable is referenced from a closure

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

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

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

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

    - #### @Override
      public String toString()

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

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