Class BytecodeVariable

java.lang.Object
org.codehaus.groovy.classgen.asm.BytecodeVariable

public class BytecodeVariable extends Object
Represents compile time variable metadata while compiling a method.
  • Field Details

    • THIS_VARIABLE

      public static final BytecodeVariable THIS_VARIABLE
      Sentinel metadata for the implicit this receiver.
    • SUPER_VARIABLE

      public static final BytecodeVariable SUPER_VARIABLE
      Sentinel metadata for the implicit super receiver.
  • Constructor Details

    • BytecodeVariable

      public BytecodeVariable(int index, ClassNode type, String name, int prevCurrent)
      Creates bytecode metadata for a local variable slot.
      Parameters:
      index - the JVM local-variable index
      type - the variable type
      name - the variable name
      prevCurrent - the previous current-variable index
  • Method Details

    • getIndex

      public int getIndex()
      Returns:
      the stack index for this variable
    • getName

      public String getName()
      Returns:
      the source-level variable name
    • getType

      public ClassNode getType()
      Returns:
      the variable type
    • setType

      public void setType(ClassNode type)
      Updates the tracked variable type.
      Parameters:
      type - the new variable type
    • getDeclaredType

      public ClassNode getDeclaredType()
      Returns the type as declared in source, which carries any type annotations (JSR 308). This may differ from getType(), e.g. when the slot type is an inferred or boxed type.
      Returns:
      the declared type, or the slot type if no declared type was recorded
      Since:
      6.0.1
    • setDeclaredType

      public void setDeclaredType(ClassNode declaredType)
      Records the type as declared in source.
      Parameters:
      declaredType - the declared type
      Since:
      6.0.1
    • getPrevIndex

      public int getPrevIndex()
      Returns:
      the previous current-variable index
    • isDynamicTyped

      public boolean isDynamicTyped()
      Returns:
      whether the variable uses dynamic typing
    • setDynamicTyped

      public void setDynamicTyped(boolean dynamicTyped)
      Marks whether the variable should be treated as dynamically typed.
      Parameters:
      dynamicTyped - true if the variable is dynamically typed
    • isHolder

      public boolean isHolder()
      Returns:
      is this local variable shared in other scopes (and so must use a ValueHolder)
    • setHolder

      public void setHolder(boolean holder)
      Marks whether this variable must be stored through a holder object.
      Parameters:
      holder - true if the variable is closure-shared
    • getStartLabel

      public org.objectweb.asm.Label getStartLabel()
      Returns:
      the start label used for local-variable table metadata
    • setStartLabel

      public void setStartLabel(org.objectweb.asm.Label startLabel)
      Sets the start label used for local-variable table metadata.
      Parameters:
      startLabel - the starting label
    • getEndLabel

      public org.objectweb.asm.Label getEndLabel()
      Returns:
      the end label used for local-variable table metadata
    • setEndLabel

      public void setEndLabel(org.objectweb.asm.Label endLabel)
      Sets the end label used for local-variable table metadata.
      Parameters:
      endLabel - the ending label
    • closeRange

      public void closeRange(org.objectweb.asm.Label end)
      Ends the currently open local-variable-table range at the given label, recording it for later emission. Used when flow scoping hides this variable (GROOVY-12242); a later reopenRange(org.objectweb.asm.Label) starts a new range if the variable becomes visible again.
      Parameters:
      end - the label at which visibility ends; ignored if null or if no range is open
    • reopenRange

      public void reopenRange(org.objectweb.asm.Label start)
      Starts a new local-variable-table range at the given label after a closeRange(org.objectweb.asm.Label). The end label is reset to the start and extended by subsequent scope pops; a range that is never extended has zero width and is not emitted.
      Parameters:
      start - the label at which visibility resumes; ignored if null or if no range was closed
    • isRangeClosed

      public boolean isRangeClosed()
      Returns:
      whether the current local-variable-table range has been closed without being reopened (the variable is hidden by flow scoping)
    • getClosedRanges

      public List<org.objectweb.asm.Label[]> getClosedRanges()
      Returns:
      the completed local-variable-table ranges as {start, end} label pairs, oldest first; empty for variables never hidden
    • toString

      public String toString()
      Overrides:
      toString in class Object