java.lang.Object
org.spongepowered.asm.mixin.injection.struct.ArgOffsets
All Implemented Interfaces:
IChainedDecoration<ArgOffsets>

public class ArgOffsets extends Object implements IChainedDecoration<ArgOffsets>
Decoration which stores a linear offset of arguments when a node replacement results in a call to a method with the same arguments as the original (replaced) call but offset by some fixed amount. Since ModifyArg and ModifyArgs always assume the method args are on the top of the stack (which they must be), this results in locating the original method args as as a contiguous "window" of arguments somewhere in the middle of the args as they exist at application time.

Injectors which mutate the arguments of an invocation should apply this decoration to indicate the starting offset and size of the window which contains the original args.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static ArgOffsets
    Null offsets
    static final String
    Decoration key for this decoration type
  • Constructor Summary

    Constructors
    Constructor
    Description
    ArgOffsets(int offset, int length)
    Create contiguous offsets starting from start and continuing for length
  • Method Summary

    Modifier and Type
    Method
    Description
    org.objectweb.asm.Type[]
    apply(org.objectweb.asm.Type[] args)
    Apply this offset collection to the supplied argument array
    int
    getArgIndex(int index)
    Compute the argument index for the specified new index
    int
    getArgIndex(int index, boolean mustBeInWindow)
    Compute the argument index for the specified new index
    int
    Compute the argument index for the end of the window (offset length)
    int
    Get the size of the offset window
    int
    Compute the argument index for the start of the window (offet 0)
    boolean
    Get whether this argument offset window is empty
    void
    Called when this decoration replaces a previous decoration with the same key
     

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • ArgOffsets

      public ArgOffsets(int offset, int length)
      Create contiguous offsets starting from start and continuing for length
      Parameters:
      offset - start index
      length - length
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • replace

      public void replace(ArgOffsets old)
      Description copied from interface: IChainedDecoration
      Called when this decoration replaces a previous decoration with the same key
      Specified by:
      replace in interface IChainedDecoration<ArgOffsets>
      Parameters:
      old - The previous decoration
    • getLength

      public int getLength()
      Get the size of the offset window
    • isEmpty

      public boolean isEmpty()
      Get whether this argument offset window is empty
    • getStartIndex

      public int getStartIndex()
      Compute the argument index for the start of the window (offet 0)
      Returns:
      the offset index for the start of the window (inclusive)
    • getEndIndex

      public int getEndIndex()
      Compute the argument index for the end of the window (offset length)
      Returns:
      the offset index for the end of the window (inclusive)
    • getArgIndex

      public int getArgIndex(int index)
      Compute the argument index for the specified new index
      Parameters:
      index - The new index to compute
      Returns:
      The original index based on this mapping
    • getArgIndex

      public int getArgIndex(int index, boolean mustBeInWindow)
      Compute the argument index for the specified new index
      Parameters:
      index - The new index to compute
      mustBeInWindow - Throw an exception if the requested index exceeds the length of the defined window
      Returns:
      The original index based on this mapping
    • apply

      public org.objectweb.asm.Type[] apply(org.objectweb.asm.Type[] args)
      Apply this offset collection to the supplied argument array
      Parameters:
      args - New arguments
      Returns:
      Unmapped arguments