Class VariableExpression

    • Constructor Detail

      • VariableExpression

        public VariableExpression​(String variable,
                                  ClassNode type)
      • VariableExpression

        public VariableExpression​(String variable)
      • VariableExpression

        public VariableExpression​(Variable variable)
    • Method Detail

      • getAccessedVariable

        public Variable getAccessedVariable()
      • setAccessedVariable

        public void setAccessedVariable​(Variable origin)
      • getName

        public String getName()
        Description copied from interface: Variable
        the name of the variable
        Specified by:
        getName in interface Variable
      • getInitialExpression

        public Expression getInitialExpression()
        Description copied from interface: Variable
        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
      • 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
      • setInStaticContext

        public void setInStaticContext​(boolean inStaticContext)
      • setType

        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
        Overrides:
        setType in class Expression
        Parameters:
        cn - the type to be set on this variable
      • 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
      • 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 - tells if this variable is later referenced in a closure
      • 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.
      • 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
      • isThisExpression

        public boolean isThisExpression()
      • isSuperExpression

        public boolean isSuperExpression()
      • setModifiers

        public void setModifiers​(int modifiers)