Package org.stianloader.micromixin.transform.internal.util

## Class ASMUtil

- java.lang.Object
- - org.stianloader.micromixin.transform.internal.util.ASMUtil

-     @Internal
      public class ASMUtil
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `CALLBACK_INFO_DESC` |
    `static java.lang.String` | `CALLBACK_INFO_NAME` |
    `static java.lang.String` | `CALLBACK_INFO_RETURNABLE_DESC` |
    `static java.lang.String` | `CALLBACK_INFO_RETURNABLE_NAME` |
    `static int` | `CI_LEN` |
    `static int` | `CIR_LEN` |
    `static java.lang.String` | `COMMON_CI_INSTANCE_ANNOT_DESC` |
    `static java.lang.String` | `ROLL_ANNOT_DESC` |
    `static java.lang.String` | `UNROLL_ANNOT_DESC` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ASMUtil()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static org.objectweb.asm.tree.AbstractInsnNode` | `afterInstruction​(org.objectweb.asm.tree.AbstractInsnNode insn)` |
    `static void` | `copyAnnotations​(org.objectweb.asm.tree.MethodNode from, org.objectweb.asm.tree.MethodNode to)` | Copy all visible and invisible annotations from a method to a different method, excluding `LocalVariableAnnotationNode`s which will not be copied due to their reliance on `LabelNode`.
    `static java.util.Collection<InjectionPointReference>` | `enumerateTargets​(java.util.Collection<MixinTargetSelector> selectors, java.util.Collection<SlicedInjectionPointSelector> ats, org.objectweb.asm.tree.ClassNode target, MixinStub mixinSource, org.objectweb.asm.tree.MethodNode injectMethodSource, int require, int expect, int allow, SimpleRemapper remapper, java.lang.StringBuilder sharedBuilder, MixinLoggingFacade logger)` |
    `static int` | `getArgumentCount​(java.lang.String methodDesc)` | Obtain the amount of arguments a method descriptor defines, irrespective of their size on the stack (so both int and long are counted as 1).
    `static org.objectweb.asm.tree.FieldNode` | `getField​(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)` |
    `static int` | `getInitialFrameSize​(org.objectweb.asm.tree.MethodNode method)` |
    `static int` | `getInputOperandCount​(org.objectweb.asm.tree.AbstractInsnNode insn)` | Obtain the amount of input operands of a given instruction, irrespective of how much space those input operands occupy on the operand stack.
    `static java.util.List<java.lang.String>` | `getInputOperandTypes​(org.objectweb.asm.tree.AbstractInsnNode insn)` | Obtain the types of the input operands of a given instruction.
    `static org.objectweb.asm.tree.LabelNode` | `getLabelNodeBefore​(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.InsnList merge)` |
    `static java.lang.String` | `getLastType​(java.lang.String methodDesc)` |
    `static int` | `getLoadOpcode​(int descReturnType)` |
    `static int` | `getLoadOpcodeFromMethodDesc​(java.lang.String methodDesc)` |
    `static org.objectweb.asm.tree.MethodNode` | `getMethod​(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)` |
    `static org.objectweb.asm.tree.AbstractInsnNode` | `getNext​(org.objectweb.asm.tree.AbstractInsnNode insn)` |
    `static java.lang.String` | `getRedirectHandlerSignature​(org.objectweb.asm.tree.AbstractInsnNode insn)` |
    `static int` | `getReturnComputationalType​(java.lang.String methodDesc)` |
    `static int` | `getReturnOpcode​(int descReturnType)` |
    `static int` | `getReturnOpcode​(java.lang.String methodDesc)` |
    `static java.lang.String` | `getReturnType​(java.lang.String methodDesc)` | Obtains the descriptor type returned by a method descriptor.
    `static int` | `getShallowStashConfiguration​(java.util.List<java.lang.String> headTypes, int uniformDepth)` |
    `static int` | `getStoreOpcode​(int descReturnType)` |
    `static int` | `getStoreOpcodeFromMethodDesc​(java.lang.String methodDesc)` |
    `static java.lang.String` | `getTargetDesc​(org.objectweb.asm.tree.MethodNode method, java.lang.StringBuilder sharedBuilder)` |
    `static boolean` | `hasField​(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)` |
    `static boolean` | `hasMethod​(org.objectweb.asm.tree.ClassNode node, java.lang.String name, java.lang.String desc)` |
    `static boolean` | `hasReducedAccess​(int witnessAccess, int testAccess)` |
    `static boolean` | `isBetween​(org.objectweb.asm.tree.AbstractInsnNode start, org.objectweb.asm.tree.AbstractInsnNode end, org.objectweb.asm.tree.AbstractInsnNode insn)` |
    `static boolean` | `isCategory2​(int descType)` |
    `static boolean` | `isCategory2VarInsn​(int opcode)` |
    `static boolean` | `isLoad​(int opcode)` |
    `static boolean` | `isReturn​(int opcode)` |
    `static boolean` | `isStore​(int opcode)` |
    `static int` | `loadCallbackInfoInstance​(org.objectweb.asm.tree.MethodNode injectTarget, org.objectweb.asm.tree.InsnList usageSiteOutput)` | Lazily allocates a shared `CallbackInfo` or `CallbackInfoCallbackInfo` instance for the given target method.
    `static void` | `moveStackHead​(org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AbstractInsnNode beginMoveInsn, org.objectweb.asm.tree.AbstractInsnNode endRollbackInsn, java.util.List<java.lang.String> headTypes, int uniformDepth, org.objectweb.asm.tree.InsnList moveOut, org.objectweb.asm.tree.InsnList rollbackOut)` | Temporarily pop (or hide them deep in the stack) a given amount of operands.
    `static int` | `popReturn​(java.lang.String methodDesc)` |
    `static org.objectweb.asm.tree.AbstractInsnNode` | `shiftInsn​(org.objectweb.asm.tree.AbstractInsnNode insn, int offset)` |
    `static int` | `toOperandDepth​(java.util.List<java.lang.String> headTypes, int uniformDepth)` |
    `static int` | `toUniformDepth​(java.util.List<java.lang.String> headTypes, int operandDepth)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CALLBACK_INFO_DESC

          public static final java.lang.String CALLBACK_INFO_DESC

      See Also:
        Constant Field Values

    - #### CALLBACK_INFO_NAME

          public static final java.lang.String CALLBACK_INFO_NAME

      See Also:
        Constant Field Values

    - #### CALLBACK_INFO_RETURNABLE_DESC

          public static final java.lang.String CALLBACK_INFO_RETURNABLE_DESC

      See Also:
        Constant Field Values

    - #### CALLBACK_INFO_RETURNABLE_NAME

          public static final java.lang.String CALLBACK_INFO_RETURNABLE_NAME

      See Also:
        Constant Field Values

    - #### CI_LEN

          public static final int CI_LEN

    - #### CIR_LEN

          public static final int CIR_LEN

    - #### COMMON_CI_INSTANCE_ANNOT_DESC

          public static final java.lang.String COMMON_CI_INSTANCE_ANNOT_DESC

      See Also:
        Constant Field Values

    - #### ROLL_ANNOT_DESC

          public static final java.lang.String ROLL_ANNOT_DESC

      See Also:
        Constant Field Values

    - #### UNROLL_ANNOT_DESC

          public static final java.lang.String UNROLL_ANNOT_DESC

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ASMUtil

          public ASMUtil()

  - ### Method Detail

    - #### afterInstruction

          @NotNull
          public static org.objectweb.asm.tree.AbstractInsnNode afterInstruction​(@NotNull
                                                                                 org.objectweb.asm.tree.AbstractInsnNode insn)

    - #### copyAnnotations

          public static void copyAnnotations​(@NotNull
                                             org.objectweb.asm.tree.MethodNode from,
                                             @NotNull
                                             org.objectweb.asm.tree.MethodNode to)

      Copy all visible and invisible annotations from a method to a different method, excluding `LocalVariableAnnotationNode`s which will not be copied due to their reliance on `LabelNode`.

      This method creates independently operating copies. That is, if the annotations in `from` where to be modified after invoking this method, the annotations in `to` will not be affected.

      This method will copy even when an annotation shouldn't be present more than once. Neither will this method honour Java 8's `Repeatable.value()`.

      Parameters:
        `from` - The `MethodNode` to copy the annotations from.
        `to` - The `MethodNode` to copy the annotations to.
      Since:
        0.8.0

    - #### enumerateTargets

          @NotNull
          public static java.util.Collection<InjectionPointReference> enumerateTargets​(@NotNull
                                                                                       java.util.Collection<MixinTargetSelector> selectors,
                                                                                       @NotNull
                                                                                       java.util.Collection<SlicedInjectionPointSelector> ats,
                                                                                       @NotNull
                                                                                       org.objectweb.asm.tree.ClassNode target,
                                                                                       @NotNull
                                                                                       MixinStub mixinSource,
                                                                                       @NotNull
                                                                                       org.objectweb.asm.tree.MethodNode injectMethodSource,
                                                                                       int require,
                                                                                       int expect,
                                                                                       int allow,
                                                                                       @NotNull
                                                                                       SimpleRemapper remapper,
                                                                                       @NotNull
                                                                                       java.lang.StringBuilder sharedBuilder,
                                                                                       @NotNull
                                                                                       MixinLoggingFacade logger)

    - #### getArgumentCount

          public static int getArgumentCount​(@NotNull
                                             java.lang.String methodDesc)

      Obtain the amount of arguments a method descriptor defines, irrespective of their size on the stack (so both int and long are counted as 1).
      Parameters:
        `methodDesc` - The method descriptor to use
      Returns:
        The amount of arguments

    - #### getField

          @Nullable
          public static org.objectweb.asm.tree.FieldNode getField​(@NotNull
                                                                  org.objectweb.asm.tree.ClassNode node,
                                                                  @NotNull
                                                                  java.lang.String name,
                                                                  @NotNull
                                                                  java.lang.String desc)

    - #### getInitialFrameSize

          public static int getInitialFrameSize​(@NotNull
                                                org.objectweb.asm.tree.MethodNode method)

    - #### getInputOperandCount

          public static int getInputOperandCount​(@NotNull
                                                 org.objectweb.asm.tree.AbstractInsnNode insn)

      Obtain the amount of input operands of a given instruction, irrespective of how much space those input operands occupy on the operand stack.
      Parameters:
        `insn` - The instruction to analyze
      Returns:
        The amount of input operands

    - #### getInputOperandTypes

          @NotNull
          public static java.util.List<java.lang.String> getInputOperandTypes​(org.objectweb.asm.tree.AbstractInsnNode insn)

      Obtain the types of the input operands of a given instruction. The returned list does not contain any null values, that is doubles are a single value within the return list.

      The values within the list are descriptor strings (e.g. Ljava/lang/Object;)

      Parameters:
        `insn` - The instruction
      Returns:
        The input operand types

    - #### getLabelNodeBefore

          @NotNull
          public static org.objectweb.asm.tree.LabelNode getLabelNodeBefore​(@NotNull
                                                                            org.objectweb.asm.tree.AbstractInsnNode insn,
                                                                            @NotNull
                                                                            org.objectweb.asm.tree.InsnList merge)

    - #### getLastType

          @Nullable
          public static java.lang.String getLastType​(@NotNull
                                                     java.lang.String methodDesc)

    - #### getLoadOpcode

          public static int getLoadOpcode​(int descReturnType)

    - #### getLoadOpcodeFromMethodDesc

          public static int getLoadOpcodeFromMethodDesc​(@NotNull
                                                        java.lang.String methodDesc)

    - #### getMethod

          @Nullable
          public static org.objectweb.asm.tree.MethodNode getMethod​(@NotNull
                                                                    org.objectweb.asm.tree.ClassNode node,
                                                                    @NotNull
                                                                    java.lang.String name,
                                                                    @NotNull
                                                                    java.lang.String desc)

    - #### getNext

          @NotNull
          public static org.objectweb.asm.tree.AbstractInsnNode getNext​(org.objectweb.asm.tree.AbstractInsnNode insn)

    - #### getRedirectHandlerSignature

          @NotNull
          public static java.lang.String getRedirectHandlerSignature​(@NotNull
                                                                     org.objectweb.asm.tree.AbstractInsnNode insn)

    - #### getReturnComputationalType

          public static int getReturnComputationalType​(@NotNull
                                                       java.lang.String methodDesc)

    - #### getReturnOpcode

          public static int getReturnOpcode​(int descReturnType)

    - #### getReturnOpcode

          public static int getReturnOpcode​(@NotNull
                                            java.lang.String methodDesc)

    - #### getReturnType

          @NotNull
          public static java.lang.String getReturnType​(java.lang.String methodDesc)

      Obtains the descriptor type returned by a method descriptor. Throws an arbitrary exception if the descriptor is not a method descriptor.
      Parameters:
        `methodDesc` - The method descriptor to get the return type of.
      Returns:
        The returned type of the method

    - #### getShallowStashConfiguration

          public static int getShallowStashConfiguration​(java.util.List<java.lang.String> headTypes,
                                                         int uniformDepth)

    - #### getStoreOpcode

          public static int getStoreOpcode​(int descReturnType)

    - #### getStoreOpcodeFromMethodDesc

          public static int getStoreOpcodeFromMethodDesc​(@NotNull
                                                         java.lang.String methodDesc)

    - #### getTargetDesc

          @NotNull
          public static java.lang.String getTargetDesc​(@NotNull
                                                       org.objectweb.asm.tree.MethodNode method,
                                                       @NotNull
                                                       java.lang.StringBuilder sharedBuilder)

    - #### hasField

          public static boolean hasField​(@NotNull
                                         org.objectweb.asm.tree.ClassNode node,
                                         @NotNull
                                         java.lang.String name,
                                         @NotNull
                                         java.lang.String desc)

    - #### hasMethod

          public static boolean hasMethod​(@NotNull
                                          org.objectweb.asm.tree.ClassNode node,
                                          @NotNull
                                          java.lang.String name,
                                          @NotNull
                                          java.lang.String desc)

    - #### hasReducedAccess

          public static boolean hasReducedAccess​(int witnessAccess,
                                                 int testAccess)

    - #### isBetween

          public static boolean isBetween​(org.objectweb.asm.tree.AbstractInsnNode start,
                                          org.objectweb.asm.tree.AbstractInsnNode end,
                                          @NotNull
                                          org.objectweb.asm.tree.AbstractInsnNode insn)

    - #### isCategory2

          public static boolean isCategory2​(int descType)

    - #### isCategory2VarInsn

          public static boolean isCategory2VarInsn​(int opcode)

    - #### isLoad

          public static boolean isLoad​(int opcode)

    - #### isReturn

          public static boolean isReturn​(int opcode)

    - #### isStore

          public static boolean isStore​(int opcode)

    - #### loadCallbackInfoInstance

          public static int loadCallbackInfoInstance​(@NotNull
                                                     org.objectweb.asm.tree.MethodNode injectTarget,
                                                     @NotNull
                                                     org.objectweb.asm.tree.InsnList usageSiteOutput)

      Lazily allocates a shared `CallbackInfo` or `CallbackInfoCallbackInfo` instance for the given target method. This method will try to aggressively reuse indices for the `CallbackInfo` or `CallbackInfoCallbackInfo`.

      The instance will be loaded onto the top of the stack within the provided usageSiteOutput `InsnList`.

      This method mutates the injectTarget `MethodNode`.

      The callback info will be cancellable.

      Parameters:
        `injectTarget` - The method which is being injected into.
        `usageSiteOutput` - An instruction list where the allocation of the instance occurs in, if the allocation did not already occur.
      Returns:
        The index from which the callback info instance can be loaded from afterwards.
      Since:
        0.6.3

    - #### moveStackHead

          public static void moveStackHead​(org.objectweb.asm.tree.MethodNode method,
                                           @NotNull
                                           org.objectweb.asm.tree.AbstractInsnNode beginMoveInsn,
                                           @NotNull
                                           org.objectweb.asm.tree.AbstractInsnNode endRollbackInsn,
                                           @NotNull
                                           java.util.List<java.lang.String> headTypes,
                                           int uniformDepth,
                                           @NotNull
                                           org.objectweb.asm.tree.InsnList moveOut,
                                           @NotNull
                                           org.objectweb.asm.tree.InsnList rollbackOut)

      Temporarily pop (or hide them deep in the stack) a given amount of operands. This method will attempt to use as few additional local variables as possible, depending on the implementation this may be achieved via annotations or even stack analysis. The method's signature is made in a way to easily change the implementation as needed, so arguments that appear superfluous on the surface ought not be discarded.
      Parameters:
        `method` - The method where the instructions belong to. For locals analysis purposes only.
        `beginMoveInsn` - The instruction at which the stack has it's original contents. For locals analysis purposes only.
        `endRollbackInsn` - The instruction at which the stack should return to it's original constellation. No jump instruction which moves outside beginMoveInsn and this instruction may be between the two instructions. For locals analysis purposes only.
        `headTypes` - The type descriptors of the types on the top of the stack. There might be more types a bit more deeply hidden but they are not of relevance.
        `uniformDepth` - The amount of operands to pop - category 2 operands count as a single value. May not be larger than the size of headTypes .
        `moveOut` - Instructions which "store" the operands of the rollback operation are appended to this insn list.
        `rollbackOut` - Instructions which "load" the operands of the rollback operation are prepended (as per `InsnList.insert(AbstractInsnNode)`) to this insn list.

    - #### popReturn

          public static int popReturn​(@NotNull
                                      java.lang.String methodDesc)

    - #### shiftInsn

          public static org.objectweb.asm.tree.AbstractInsnNode shiftInsn​(org.objectweb.asm.tree.AbstractInsnNode insn,
                                                                          int offset)

    - #### toOperandDepth

          public static int toOperandDepth​(java.util.List<java.lang.String> headTypes,
                                           int uniformDepth)

    - #### toUniformDepth

          public static int toUniformDepth​(java.util.List<java.lang.String> headTypes,
                                           int operandDepth)