Package org.spongepowered.asm.mixin.injection.code

## Class Injector

- java.lang.Object
- - org.spongepowered.asm.mixin.injection.code.Injector

- Direct Known Subclasses:
    `CallbackInjector`, `InvokeInjector`, `ModifyVariableInjector`

      public abstract class Injector
      extends java.lang.Object

  Base class for bytecode injectors

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Injector.InjectorData` | Redirection data bundle base.
    `static class` | `Injector.TargetNode` | A nominated target node

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected java.lang.String` | `annotationType` | Annotation type, for use in informational errors
    `protected org.objectweb.asm.tree.ClassNode` | `classNode` | Class node
    `protected InjectionInfo` | `info` | Injection info
    `protected boolean` | `isInterface` | True if the callback method is in an interface
    `protected boolean` | `isStatic` | True if the callback method is static
    `protected static ILogger` | `logger` | Log more things
    `protected org.objectweb.asm.Type[]` | `methodArgs` | Arguments of the handler method
    `protected org.objectweb.asm.tree.MethodNode` | `methodNode` | Callback method
    `protected org.objectweb.asm.Type` | `returnType` | Return type of the handler method

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Injector​(InjectionInfo info, java.lang.String annotationType)` | Make a new CallbackInjector for the supplied InjectionInfo

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `addTargetNode​(InjectorTarget injectorTarget, java.util.List<InjectionNodes.InjectionNode> myNodes, org.objectweb.asm.tree.AbstractInsnNode node, java.util.Set<InjectionPoint> nominators)` |
    `protected void` | `addTargetNode​(InjectorTarget target, java.util.Map<java.lang.Integer,​Injector.TargetNode> targetNodes, InjectionPoint injectionPoint, org.objectweb.asm.tree.AbstractInsnNode insn)` |
    `static boolean` | `canCoerce​(char from, char to)` | Returns whether the `from` type can be coerced to the `to` type.
    `static boolean` | `canCoerce​(java.lang.String from, java.lang.String to)` | Returns whether the `from` type can be coerced to the `to` type.
    `static boolean` | `canCoerce​(org.objectweb.asm.Type from, org.objectweb.asm.Type to)` | Returns whether the `from` type can be coerced to the `to` type.
    `protected boolean` | `checkCoerce​(int index, org.objectweb.asm.Type toType, java.lang.String description, boolean allowCoercion)` | Called inside `validateParams(org.spongepowered.asm.mixin.injection.code.Injector.InjectorData, org.objectweb.asm.Type, org.objectweb.asm.Type...)` but can also be used directly.
    `protected void` | `checkTargetForNode​(Target target, InjectionNodes.InjectionNode node, InjectionPoint.RestrictTargetLevel targetLevel)` | The normal staticness check is not location-aware, in that it merely enforces static modifiers of handlers to match their targets.
    `protected void` | `checkTargetModifiers​(Target target, boolean exactMatch)` | Check that the `static` modifier of the target method matches the handler
    `java.util.List<InjectionNodes.InjectionNode>` | `find​(InjectorTarget injectorTarget, java.util.List<InjectionPoint> injectionPoints)` | ...
    `protected boolean` | `findTargetNodes​(InjectorTarget target, InjectionPoint injectionPoint, java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)` |
    `void` | `inject​(Target target, java.util.List<InjectionNodes.InjectionNode> nodes)` | Performs the injection on the specified target
    `protected abstract void` | `inject​(Target target, InjectionNodes.InjectionNode node)` |
    `protected org.objectweb.asm.tree.AbstractInsnNode` | `invokeHandler​(org.objectweb.asm.tree.InsnList insns)` | Invoke the handler method
    `protected org.objectweb.asm.tree.AbstractInsnNode` | `invokeHandler​(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.MethodNode handler)` | Invoke a handler method
    `protected org.objectweb.asm.tree.AbstractInsnNode` | `invokeHandlerWithArgs​(org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap)` |
    `protected org.objectweb.asm.tree.AbstractInsnNode` | `invokeHandlerWithArgs​(org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap, int startArg, int endArg)` |
    `protected void` | `postInject​(Target target, InjectionNodes.InjectionNode node)` |
    `void` | `preInject​(Target target, java.util.List<InjectionNodes.InjectionNode> nodes)` | Performs pre-injection checks and tasks on the specified target
    `protected void` | `preInject​(Target target, InjectionNodes.InjectionNode node)` |
    `protected void` | `pushArgs​(org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap, int start, int end)` | Load args onto the stack from their positions allocated in argMap
    `protected void` | `pushArgs​(org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap, int start, int end, Target.Extension extension)` | Load args onto the stack from their positions allocated in argMap
    `protected void` | `sanityCheck​(Target target, java.util.List<InjectionPoint> injectionPoints)` |
    `protected int[]` | `storeArgs​(Target target, org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int start)` | Store args on the stack starting at the end and working back to position specified by start, return the generated argMap
    `protected void` | `storeArgs​(Target target, org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap, int start, int end)` | Store args on the stack to their positions allocated based on argMap
    `protected void` | `storeArgs​(Target target, org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int[] argMap, int start, int end, org.objectweb.asm.tree.LabelNode from, org.objectweb.asm.tree.LabelNode to)` | Store args on the stack to their positions allocated based on argMap
    `protected int[]` | `storeArgs​(Target target, org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int start, org.objectweb.asm.tree.LabelNode from, org.objectweb.asm.tree.LabelNode to)` | Store args on the stack starting at the end and working back to position specified by start, return the generated argMap
    `protected void` | `throwException​(org.objectweb.asm.tree.InsnList insns, Target.Extension extraStack, java.lang.String exceptionType, java.lang.String message)` | Throw an exception.
    `java.lang.String` | `toString()` |
    `protected void` | `validateParams​(Injector.InjectorData injector, org.objectweb.asm.Type returnType, org.objectweb.asm.Type... args)` | Collects all the logic from old validateParams/checkDescriptor so that we can consistently apply coercion logic to method params, and also provide more detailed errors when something doesn't line up.

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

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

- - ### Field Detail

    - #### logger

          protected static final ILogger logger

      Log more things

    - #### info

          protected InjectionInfo info

      Injection info

    - #### annotationType

          protected final java.lang.String annotationType

      Annotation type, for use in informational errors

    - #### classNode

          protected final org.objectweb.asm.tree.ClassNode classNode

      Class node

    - #### methodNode

          protected final org.objectweb.asm.tree.MethodNode methodNode

      Callback method

    - #### methodArgs

          protected final org.objectweb.asm.Type[] methodArgs

      Arguments of the handler method

    - #### returnType

          protected final org.objectweb.asm.Type returnType

      Return type of the handler method

    - #### isStatic

          protected final boolean isStatic

      True if the callback method is static

    - #### isInterface

          protected final boolean isInterface

      True if the callback method is in an interface

  - ### Constructor Detail

    - #### Injector

          public Injector​(InjectionInfo info,
                          java.lang.String annotationType)

      Make a new CallbackInjector for the supplied InjectionInfo
      Parameters:
        `info` - Information about this injection

  - ### Method Detail

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### find

          public final java.util.List<InjectionNodes.InjectionNode> find​(InjectorTarget injectorTarget,
                                                                         java.util.List<InjectionPoint> injectionPoints)

      ...
      Parameters:
        `injectorTarget` - Target method to inject into
        `injectionPoints` - InjectionPoint instances which will identify target insns in the target method
      Returns:
        discovered injection points

    - #### addTargetNode

          protected void addTargetNode​(InjectorTarget injectorTarget,
                                       java.util.List<InjectionNodes.InjectionNode> myNodes,
                                       org.objectweb.asm.tree.AbstractInsnNode node,
                                       java.util.Set<InjectionPoint> nominators)

    - #### preInject

          public final void preInject​(Target target,
                                      java.util.List<InjectionNodes.InjectionNode> nodes)

      Performs pre-injection checks and tasks on the specified target
      Parameters:
        `target` - target potentially being injected into
        `nodes` - selected target nodes

    - #### inject

          public final void inject​(Target target,
                                   java.util.List<InjectionNodes.InjectionNode> nodes)

      Performs the injection on the specified target
      Parameters:
        `target` - target to inject into
        `nodes` - selected nodes

    - #### addTargetNode

          protected void addTargetNode​(InjectorTarget target,
                                       java.util.Map<java.lang.Integer,​Injector.TargetNode> targetNodes,
                                       InjectionPoint injectionPoint,
                                       org.objectweb.asm.tree.AbstractInsnNode insn)

    - #### findTargetNodes

          protected boolean findTargetNodes​(InjectorTarget target,
                                            InjectionPoint injectionPoint,
                                            java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)

    - #### sanityCheck

          protected void sanityCheck​(Target target,
                                     java.util.List<InjectionPoint> injectionPoints)

    - #### checkTargetModifiers

          protected final void checkTargetModifiers​(Target target,
                                                    boolean exactMatch)

      Check that the `static` modifier of the target method matches the handler
      Parameters:
        `target` - Target to check
        `exactMatch` - True if static must match, false to only check if an instance handler is targetting a static method

    - #### checkTargetForNode

          protected void checkTargetForNode​(Target target,
                                            InjectionNodes.InjectionNode node,
                                            InjectionPoint.RestrictTargetLevel targetLevel)

      The normal staticness check is not location-aware, in that it merely enforces static modifiers of handlers to match their targets. For injecting into constructors however (which are ostensibly instance methods) calls which are injected before the call to `super()` cannot access `this` and must therefore be declared as static.
      Parameters:
        `target` - Target method
        `node` - Injection location

    - #### preInject

          protected void preInject​(Target target,
                                   InjectionNodes.InjectionNode node)

    - #### inject

          protected abstract void inject​(Target target,
                                         InjectionNodes.InjectionNode node)

    - #### postInject

          protected void postInject​(Target target,
                                    InjectionNodes.InjectionNode node)

    - #### invokeHandler

          protected org.objectweb.asm.tree.AbstractInsnNode invokeHandler​(org.objectweb.asm.tree.InsnList insns)

      Invoke the handler method
      Parameters:
        `insns` - Instruction list to inject into
      Returns:
        injected insn node

    - #### invokeHandler

          protected org.objectweb.asm.tree.AbstractInsnNode invokeHandler​(org.objectweb.asm.tree.InsnList insns,
                                                                          org.objectweb.asm.tree.MethodNode handler)

      Invoke a handler method
      Parameters:
        `insns` - Instruction list to inject into
        `handler` - Actual method to invoke (may be different if using a surrogate)
      Returns:
        injected insn node

    - #### invokeHandlerWithArgs

          protected org.objectweb.asm.tree.AbstractInsnNode invokeHandlerWithArgs​(org.objectweb.asm.Type[] args,
                                                                                  org.objectweb.asm.tree.InsnList insns,
                                                                                  int[] argMap)

      Parameters:
        `args` - handler arguments
        `insns` - InsnList to inject insns into
        `argMap` - Mapping of args to local variables
      Returns:
        injected insn node

    - #### invokeHandlerWithArgs

          protected org.objectweb.asm.tree.AbstractInsnNode invokeHandlerWithArgs​(org.objectweb.asm.Type[] args,
                                                                                  org.objectweb.asm.tree.InsnList insns,
                                                                                  int[] argMap,
                                                                                  int startArg,
                                                                                  int endArg)

      Parameters:
        `args` - handler arguments
        `insns` - InsnList to inject insns into
        `argMap` - Mapping of args to local variables
        `startArg` - Starting arg to consume
        `endArg` - Ending arg to consume
      Returns:
        injected insn node

    - #### storeArgs

          protected int[] storeArgs​(Target target,
                                    org.objectweb.asm.Type[] args,
                                    org.objectweb.asm.tree.InsnList insns,
                                    int start)

      Store args on the stack starting at the end and working back to position specified by start, return the generated argMap
      Parameters:
        `target` - target method
        `args` - argument types
        `insns` - instruction list to generate insns into
        `start` - Starting index
      Returns:
        the generated argmap

    - #### storeArgs

          protected int[] storeArgs​(Target target,
                                    org.objectweb.asm.Type[] args,
                                    org.objectweb.asm.tree.InsnList insns,
                                    int start,
                                    org.objectweb.asm.tree.LabelNode from,
                                    org.objectweb.asm.tree.LabelNode to)

      Store args on the stack starting at the end and working back to position specified by start, return the generated argMap
      Parameters:
        `target` - target method
        `args` - argument types
        `insns` - instruction list to generate insns into
        `start` - Starting index
        `from` - The label marking the start of the region for the locals
        `to` - The label marking the end of the region for the stored locals
      Returns:
        the generated argmap

    - #### storeArgs

          protected void storeArgs​(Target target,
                                   org.objectweb.asm.Type[] args,
                                   org.objectweb.asm.tree.InsnList insns,
                                   int[] argMap,
                                   int start,
                                   int end)

      Store args on the stack to their positions allocated based on argMap
      Parameters:
        `args` - argument types
        `insns` - instruction list to generate insns into
        `argMap` - generated argmap containing local indices for all args
        `start` - Starting index
        `end` - Ending index

    - #### storeArgs

          protected void storeArgs​(Target target,
                                   org.objectweb.asm.Type[] args,
                                   org.objectweb.asm.tree.InsnList insns,
                                   int[] argMap,
                                   int start,
                                   int end,
                                   org.objectweb.asm.tree.LabelNode from,
                                   org.objectweb.asm.tree.LabelNode to)

      Store args on the stack to their positions allocated based on argMap
      Parameters:
        `args` - argument types
        `insns` - instruction list to generate insns into
        `argMap` - generated argmap containing local indices for all args
        `start` - Starting index
        `end` - Ending index
        `from` - The label marking the start of the region for the locals
        `to` - The label marking the end of the region for the stored locals

    - #### pushArgs

          protected void pushArgs​(org.objectweb.asm.Type[] args,
                                  org.objectweb.asm.tree.InsnList insns,
                                  int[] argMap,
                                  int start,
                                  int end)

      Load args onto the stack from their positions allocated in argMap
      Parameters:
        `args` - argument types
        `insns` - instruction list to generate insns into
        `argMap` - generated argmap containing local indices for all args
        `start` - Starting index
        `end` - Ending index

    - #### pushArgs

          protected void pushArgs​(org.objectweb.asm.Type[] args,
                                  org.objectweb.asm.tree.InsnList insns,
                                  int[] argMap,
                                  int start,
                                  int end,
                                  Target.Extension extension)

      Load args onto the stack from their positions allocated in argMap
      Parameters:
        `args` - argument types
        `insns` - instruction list to generate insns into
        `argMap` - generated argmap containing local indices for all args
        `start` - Starting index
        `end` - Ending index

    - #### validateParams

          protected final void validateParams​(Injector.InjectorData injector,
                                              org.objectweb.asm.Type returnType,
                                              org.objectweb.asm.Type... args)

      Collects all the logic from old validateParams/checkDescriptor so that we can consistently apply coercion logic to method params, and also provide more detailed errors when something doesn't line up.

      The supplied return type and argument list will be verified first. Any arguments on the handler beyond the base arguments consume arguments from the target. The flag `allowCoerceArgs` on the `redirect` instance determines whether coercion is supported for the base args and return type, coercion is always allowed for captured target args.

      Following validation, the `captureTargetArgs` and `coerceReturnType` values will be set on the bundle and the calling injector function should adjust itself accordingly.

      Parameters:
        `injector` - Data bundle for the injector
        `returnType` - Return type for the handler, must not be null
        `args` - Array of handler args, must not be null

    - #### checkCoerce

          protected final boolean checkCoerce​(int index,
                                              org.objectweb.asm.Type toType,
                                              java.lang.String description,
                                              boolean allowCoercion)

      Called inside `validateParams(org.spongepowered.asm.mixin.injection.code.Injector.InjectorData, org.objectweb.asm.Type, org.objectweb.asm.Type...)` but can also be used directly. This method checks whether the supplied type is compatible with the specified handler argument, apply coercion logic where necessary.
      Parameters:
        `index` - Handler argument index, pass in a negative value (by convention -1) to specify handler return type
        `toType` - Desired type based on the injector contract
        `description` - human-readable description of the handler method, used in raised exception
        `allowCoercion` - True if coercion logic can be applied to this argument, false to only allow a precise match
      Returns:
        `false` if the argument matched perfectly, `true` if coercion is required for the argument

    - #### throwException

          protected void throwException​(org.objectweb.asm.tree.InsnList insns,
                                        Target.Extension extraStack,
                                        java.lang.String exceptionType,
                                        java.lang.String message)

      Throw an exception. The exception class must have a string which takes a string argument
      Parameters:
        `insns` - Insn list to inject into
        `exceptionType` - Type of exception to throw (binary name)
        `message` - Message to pass to the exception constructor

    - #### canCoerce

          public static boolean canCoerce​(org.objectweb.asm.Type from,
                                          org.objectweb.asm.Type to)

      Returns whether the `from` type can be coerced to the `to` type.
      Parameters:
        `from` - type to coerce from
        `to` - type to coerce to
      Returns:
        true if `from` can be coerced to `to`

    - #### canCoerce

          public static boolean canCoerce​(java.lang.String from,
                                          java.lang.String to)

      Returns whether the `from` type can be coerced to the `to` type.
      Parameters:
        `from` - type to coerce from
        `to` - type to coerce to
      Returns:
        true if `from` can be coerced to `to`

    - #### canCoerce

          public static boolean canCoerce​(char from,
                                          char to)

      Returns whether the `from` type can be coerced to the `to` type.
      Parameters:
        `from` - type to coerce from
        `to` - type to coerce to
      Returns:
        true if `from` can be coerced to `to`