Class StackIndexHelper

java.lang.Object
eu.cloudnetservice.driver.util.asm.StackIndexHelper

@Internal public final class StackIndexHelper extends Object
A small helper class that helps keeping track of bytecode stack indices while pushing/loading from it.
Since:
4.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    StackIndexHelper(int initialVarIndex)
    Constructs a new stack index helper instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new stack index helper which uses 0 as the initial index.
    create(int initialVarIndex)
    Constructs a new stack index helper with the given initial var index.
    load(@NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull Class<?> type)
    Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
    load(@NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull org.objectweb.asm.Type type)
    Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
    push(@NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull Class<?> type)
    Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
    push(@NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull org.objectweb.asm.Type type)
    Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
    skip(int depth)
    Skips the given amount of indices and uses the resulting value as the next var index to read/write from/to.
    Skips the next (one) element of the current stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • nextVarIndex

      private int nextVarIndex
  • Constructor Details

    • StackIndexHelper

      private StackIndexHelper(int initialVarIndex)
      Constructs a new stack index helper instance.
      Parameters:
      initialVarIndex - the initial var index for the first element to load/store from/to the stack.
  • Method Details

    • create

      @NonNull public static @NonNull StackIndexHelper create()
      Creates a new stack index helper which uses 0 as the initial index.
      Returns:
      a stack index helper that uses 0 as the initial index.
    • create

      @NonNull public static @NonNull StackIndexHelper create(int initialVarIndex)
      Constructs a new stack index helper with the given initial var index.
      Parameters:
      initialVarIndex - the initial var index for the first element to load/store from/to the stack.
      Returns:
      a stack index helper that uses the given initial var index.
    • skipNext

      @NonNull public @NonNull StackIndexHelper skipNext()
      Skips the next (one) element of the current stack. This method implies that the next element has a size of one.
      Returns:
      this index helper, for chaining.
    • skip

      @NonNull public @NonNull StackIndexHelper skip(int depth)
      Skips the given amount of indices and uses the resulting value as the next var index to read/write from/to.
      Parameters:
      depth - the stack depth to skip.
      Returns:
      this index helper, for chaining.
    • push

      @NonNull public @NonNull StackIndexHelper push(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull Class<?> type)
      Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
      Parameters:
      methodVisitor - the method visitor to notify about the store operation.
      type - the type to store on the stack.
      Returns:
      this index helper, for chaining.
      Throws:
      NullPointerException - if the given visitor or type is null.
    • push

      @NonNull public @NonNull StackIndexHelper push(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull org.objectweb.asm.Type type)
      Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
      Parameters:
      methodVisitor - the method visitor to notify about the store operation.
      type - the type to store on the stack.
      Returns:
      this index helper, for chaining.
      Throws:
      NullPointerException - if the given visitor or type is null.
    • load

      @NonNull public @NonNull StackIndexHelper load(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull Class<?> type)
      Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
      Parameters:
      methodVisitor - the method visitor to notify about the load operation.
      type - the type to load from the stack.
      Returns:
      this index helper, for chaining.
      Throws:
      NullPointerException - if the given visitor or type is null.
    • load

      @NonNull public @NonNull StackIndexHelper load(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull org.objectweb.asm.Type type)
      Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.
      Parameters:
      methodVisitor - the method visitor to notify about the load operation.
      type - the type to load from the stack.
      Returns:
      this index helper, for chaining.
      Throws:
      NullPointerException - if the given visitor or type is null.