Package org.spongepowered.asm.mixin.injection.struct

## Class Target

- java.lang.Object
- - org.spongepowered.asm.mixin.injection.struct.Target

All Implemented Interfaces:
  `java.lang.Comparable<Target>`, `java.lang.Iterable<org.objectweb.asm.tree.AbstractInsnNode>`

Direct Known Subclasses:
  `Constructor`

    public class Target
    extends java.lang.Object
    implements java.lang.Comparable<Target>, java.lang.Iterable<org.objectweb.asm.tree.AbstractInsnNode>

Information about the current injection target (method) which bundles common injection context with the target method in order to allow injectors to interoperate.

### Nested Class Summary

Nested Classes
`class` `Target.Extension` A stateful extension of stack or locals space for a target method which can be applied.

### Field Summary

Fields
`org.objectweb.asm.Type[]` `arguments` Method arguments
`ClassInfo` `classInfo` Target class info
`org.objectweb.asm.tree.ClassNode` `classNode` Target class node
`org.objectweb.asm.tree.InsnList` `insns` Method instructions
`boolean` `isStatic` True if the method is static
`org.objectweb.asm.tree.MethodNode` `method` Target method
`org.objectweb.asm.Type` `returnType` Return type computed from the method descriptor

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`InjectionNodes.InjectionNode` `addInjectionNode​(org.objectweb.asm.tree.AbstractInsnNode node)` Add an injection node to this target if it does not already exist, returns the existing node if it exists
`void` `addLocalVariable​(int index, java.lang.String name, java.lang.String desc)` Add an entry to the target LVT
`void` `addLocalVariable​(int index, java.lang.String name, java.lang.String desc, org.objectweb.asm.tree.LabelNode from, org.objectweb.asm.tree.LabelNode to)` Add an entry to the target LVT between the specified start and end labels
`int` `allocateLocal()` Allocate a new local variable for the method
`int` `allocateLocals​(int locals)` Allocate a number of new local variables for this method, returns the first local variable index of the allocated range.
`int` `compareTo​(Target o)`
`Target.Extension` `extendLocals()` Creates a new locals extension.
`Target.Extension` `extendStack()` Creates a new stack extension.
`org.objectweb.asm.tree.MethodInsnNode` `findInitNodeFor​(org.objectweb.asm.tree.TypeInsnNode newNode)` Find the first `<init>` invocation after the specified `NEW` insn
`org.objectweb.asm.tree.MethodInsnNode` `findInitNodeFor​(org.objectweb.asm.tree.TypeInsnNode newNode, java.lang.String desc)` Find the matching `<init>` invocation after the specified `NEW` insn, ensuring that the supplied descriptor matches.
`int[]` `generateArgMap​(org.objectweb.asm.Type[] args, int start)` Generate an array containing local indexes for the specified args, returns an array of identical size to the supplied array with an allocated local index in each corresponding position
`int[]` `generateArgMap​(org.objectweb.asm.Type[] args, int start, boolean fresh)` Generate an array containing local indexes for the specified args, returns an array of identical size to the supplied array with an allocated local index in each corresponding position
`org.objectweb.asm.tree.AbstractInsnNode` `get​(int index)` Return the instruction at the specified index
`int[]` `getArgIndices()` Get the argument indices for this target, calculated on first use
`java.lang.String` `getCallbackDescriptor​(boolean captureLocals, org.objectweb.asm.Type[] locals, org.objectweb.asm.Type[] argumentTypes, int startIndex, int extra)` Get the callback descriptor
`java.lang.String` `getCallbackDescriptor​(org.objectweb.asm.Type[] locals, org.objectweb.asm.Type[] argumentTypes)` Get the callback descriptor
`java.lang.String` `getCallbackInfoClass()` Get the CallbackInfo class used for this target, based on the target return type
`int` `getCurrentMaxLocals()` Get the current max locals of the method
`int` `getCurrentMaxStack()` Get the current max stack of the method
`java.lang.String` `getDesc()` Get the target method descriptor
`InjectionNodes.InjectionNode` `getInjectionNode​(org.objectweb.asm.tree.AbstractInsnNode node)` Get an injection node from this collection if it already exists, returns null if the node is not tracked
`int` `getMaxLocals()` Get the original max locals of the method
`int` `getMaxStack()` Get the original max stack of the method
`java.lang.String` `getName()` Get the target method name
`java.lang.String` `getSignature()` Get the target method signature
`java.lang.String` `getSimpleCallbackDescriptor()` Get "simple" callback descriptor (descriptor with only CallbackInfo)
`int` `indexOf​(org.objectweb.asm.tree.AbstractInsnNode insn)` Return the index of the specified instruction in this instruction list
`int` `indexOf​(InjectionNodes.InjectionNode node)` Return the index of the specified instruction in this instruction list
`void` `insert​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode insn)` Insert the supplied instruction after the specified instruction
`void` `insert​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.InsnList insns)` Insert the supplied instructions after the specified instruction
`void` `insert​(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.AbstractInsnNode insn)` Insert the supplied instruction after the specified instruction
`void` `insert​(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.InsnList insns)` Insert the supplied instructions after the specified instruction
`void` `insertBefore​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode insn)` Insert the supplied instruction before the specified instruction
`void` `insertBefore​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.InsnList insns)` Insert the supplied instructions before the specified instruction
`void` `insertBefore​(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.AbstractInsnNode insn)` Insert the supplied instruction before the specified instruction
`void` `insertBefore​(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.InsnList insns)` Insert the supplied instructions before the specified instruction
`java.util.Iterator<org.objectweb.asm.tree.AbstractInsnNode>` `iterator()`
`static Target` `of​(ClassInfo classInfo, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode method)`
`void` `removeNode​(org.objectweb.asm.tree.AbstractInsnNode insn)` Remove the specified instruction from the target and mark it as removed for injections
`void` `replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode insn)` Replace an instruction in this target with the specified instruction and mark the node as replaced for other injectors
`void` `replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode champion, org.objectweb.asm.tree.InsnList insns)` Replace an instruction in this target with the specified instructions and mark the node as replaced with the specified champion node from the list.
`void` `replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.InsnList insns)` Replace an instruction in this target with the specified instructions and mark the original node as removed
`java.lang.String` `toString()`
`void` `wrapNode​(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode champion, org.objectweb.asm.tree.InsnList before, org.objectweb.asm.tree.InsnList after)` Wrap instruction in this target with the specified instructions and mark the node as replaced with the specified champion node from the list.

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

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Field Detail

#### classInfo

    public final ClassInfo classInfo

Target class info

#### classNode

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

Target class node

#### method

    public final org.objectweb.asm.tree.MethodNode method

Target method

#### insns

    public final org.objectweb.asm.tree.InsnList insns

Method instructions

#### isStatic

    public final boolean isStatic

True if the method is static

#### arguments

    public final org.objectweb.asm.Type[] arguments

Method arguments

#### returnType

    public final org.objectweb.asm.Type returnType

Return type computed from the method descriptor

### Method Detail

#### addInjectionNode

    public InjectionNodes.InjectionNode addInjectionNode​(org.objectweb.asm.tree.AbstractInsnNode node)

Add an injection node to this target if it does not already exist, returns the existing node if it exists

Parameters:
  `node` - Instruction node to add
Returns:
  wrapper for the specified node

#### getInjectionNode

    public InjectionNodes.InjectionNode getInjectionNode​(org.objectweb.asm.tree.AbstractInsnNode node)

Get an injection node from this collection if it already exists, returns null if the node is not tracked

Parameters:
  `node` - instruction node
Returns:
  wrapper node or null if not tracked

#### getName

    public java.lang.String getName()

Get the target method name

#### getDesc

    public java.lang.String getDesc()

Get the target method descriptor

#### getSignature

    public java.lang.String getSignature()

Get the target method signature

#### getMaxLocals

    public int getMaxLocals()

Get the original max locals of the method

Returns:
  the original max locals value

#### getMaxStack

    public int getMaxStack()

Get the original max stack of the method

Returns:
  the original max stack value

#### getCurrentMaxLocals

    public int getCurrentMaxLocals()

Get the current max locals of the method

Returns:
  the current max local value

#### getCurrentMaxStack

    public int getCurrentMaxStack()

Get the current max stack of the method

Returns:
  the current max stack value

#### allocateLocal

    public int allocateLocal()

Allocate a new local variable for the method

Note that allocating a local differs from extending locals (see `extendLocals()`) in that the allocation immediately increases the target max locals and returns the new index of the local just allocated. Extending locals is used for temporary localised extensions to the locals table for the purposes of injectors.

Returns:
  the allocated local index

#### allocateLocals

    public int allocateLocals​(int locals)

Allocate a number of new local variables for this method, returns the first local variable index of the allocated range.

Note that allocating locals differs from extending locals (see `extendLocals()`) in that the allocation immediately increases the target max locals and returns the new index of the local just allocated. Extending locals is used for temporary localised extensions to the locals table for the purposes of injectors.

Parameters:
  `locals` - number of locals to allocate
Returns:
  the first local variable index of the allocated range

#### extendLocals

    public Target.Extension extendLocals()

Creates a new locals extension. The returned object can be used to create extensions to the method locals for an injector to use. Extensions are not designed to overlap, and the largest extension for a method will determine the amount by which the locals table is extended.

Returns:
  extension handle

#### extendStack

    public Target.Extension extendStack()

Creates a new stack extension. The returned object can be used to create extensions to the method stack for an injector to use. Extensions are not designed to overlap, and the largest extension for a method will determine the amount by which the stack is extended.

Returns:
  extension handle

#### generateArgMap

    public int[] generateArgMap​(org.objectweb.asm.Type[] args,
                                int start)

Generate an array containing local indexes for the specified args, returns an array of identical size to the supplied array with an allocated local index in each corresponding position

Parameters:
  `args` - Argument types
  `start` - starting index
Returns:
  array containing a corresponding local arg index for each member of the supplied args array

#### generateArgMap

    public int[] generateArgMap​(org.objectweb.asm.Type[] args,
                                int start,
                                boolean fresh)

Generate an array containing local indexes for the specified args, returns an array of identical size to the supplied array with an allocated local index in each corresponding position

Parameters:
  `args` - Argument types
  `start` - starting index
  `fresh` - allocate fresh locals only, do not reuse existing argmap slots
Returns:
  array containing a corresponding local arg index for each member of the supplied args array

#### getArgIndices

    public int[] getArgIndices()

Get the argument indices for this target, calculated on first use

Returns:
  argument indices for this target

#### getCallbackInfoClass

    public java.lang.String getCallbackInfoClass()

Get the CallbackInfo class used for this target, based on the target return type

Returns:
  CallbackInfo class name

#### getSimpleCallbackDescriptor

    public java.lang.String getSimpleCallbackDescriptor()

Get "simple" callback descriptor (descriptor with only CallbackInfo)

Returns:
  generated descriptor

#### getCallbackDescriptor

    public java.lang.String getCallbackDescriptor​(org.objectweb.asm.Type[] locals,
                                                  org.objectweb.asm.Type[] argumentTypes)

Get the callback descriptor

Parameters:
  `locals` - Local variable types
  `argumentTypes` - Argument types
Returns:
  generated descriptor

#### getCallbackDescriptor

    public java.lang.String getCallbackDescriptor​(boolean captureLocals,
                                                  org.objectweb.asm.Type[] locals,
                                                  org.objectweb.asm.Type[] argumentTypes,
                                                  int startIndex,
                                                  int extra)

Get the callback descriptor

Parameters:
  `captureLocals` - True if the callback is capturing locals
  `locals` - Local variable types
  `argumentTypes` - Argument types
  `startIndex` - local index to start at
  `extra` - extra locals to include
Returns:
  generated descriptor

#### toString

    public java.lang.String toString()

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

#### compareTo

    public int compareTo​(Target o)

Specified by:
  `compareTo` in interface `java.lang.Comparable<Target>`

#### indexOf

    public int indexOf​(InjectionNodes.InjectionNode node)

Return the index of the specified instruction in this instruction list

Parameters:
  `node` - instruction to locate, must exist in the target
Returns:
  opcode index

#### indexOf

    public int indexOf​(org.objectweb.asm.tree.AbstractInsnNode insn)

Return the index of the specified instruction in this instruction list

Parameters:
  `insn` - instruction to locate, must exist in the target
Returns:
  opcode index

#### get

    public org.objectweb.asm.tree.AbstractInsnNode get​(int index)

Return the instruction at the specified index

Parameters:
  `index` - opcode index
Returns:
  requested instruction

#### iterator

    public java.util.Iterator<org.objectweb.asm.tree.AbstractInsnNode> iterator()

Specified by:
  `iterator` in interface `java.lang.Iterable<org.objectweb.asm.tree.AbstractInsnNode>`

#### findInitNodeFor

    public org.objectweb.asm.tree.MethodInsnNode findInitNodeFor​(org.objectweb.asm.tree.TypeInsnNode newNode)

Find the first `<init>` invocation after the specified `NEW` insn

Parameters:
  `newNode` - NEW insn
Returns:
  INVOKESPECIAL opcode of ctor, or null if not found

#### findInitNodeFor

    public org.objectweb.asm.tree.MethodInsnNode findInitNodeFor​(org.objectweb.asm.tree.TypeInsnNode newNode,
                                                                 java.lang.String desc)

Find the matching `<init>` invocation after the specified `NEW` insn, ensuring that the supplied descriptor matches. If the supplied descriptor is `null` then any invocation matches. If additional `NEW` insns are encountered then corresponding `<init>` calls are skipped.

Parameters:
  `newNode` - NEW insn
  `desc` - Descriptor to match
Returns:
  INVOKESPECIAL opcode of ctor, or null if not found

#### insert

    public void insert​(InjectionNodes.InjectionNode location,
                       org.objectweb.asm.tree.InsnList insns)

Insert the supplied instructions after the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insns` - Instructions to insert

#### insert

    public void insert​(InjectionNodes.InjectionNode location,
                       org.objectweb.asm.tree.AbstractInsnNode insn)

Insert the supplied instruction after the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insn` - Instruction to insert

#### insert

    public void insert​(org.objectweb.asm.tree.AbstractInsnNode location,
                       org.objectweb.asm.tree.InsnList insns)

Insert the supplied instructions after the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insns` - Instructions to insert

#### insert

    public void insert​(org.objectweb.asm.tree.AbstractInsnNode location,
                       org.objectweb.asm.tree.AbstractInsnNode insn)

Insert the supplied instruction after the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insn` - Instruction to insert

#### insertBefore

    public void insertBefore​(InjectionNodes.InjectionNode location,
                             org.objectweb.asm.tree.InsnList insns)

Insert the supplied instructions before the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insns` - Instructions to insert

#### insertBefore

    public void insertBefore​(InjectionNodes.InjectionNode location,
                             org.objectweb.asm.tree.AbstractInsnNode insn)

Insert the supplied instruction before the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insn` - Instruction to insert

#### insertBefore

    public void insertBefore​(org.objectweb.asm.tree.AbstractInsnNode location,
                             org.objectweb.asm.tree.InsnList insns)

Insert the supplied instructions before the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insns` - Instructions to insert

#### insertBefore

    public void insertBefore​(org.objectweb.asm.tree.AbstractInsnNode location,
                             org.objectweb.asm.tree.AbstractInsnNode insn)

Insert the supplied instruction before the specified instruction

Parameters:
  `location` - Instruction to insert before
  `insn` - Instruction to insert

#### replaceNode

    public void replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location,
                            org.objectweb.asm.tree.AbstractInsnNode insn)

Replace an instruction in this target with the specified instruction and mark the node as replaced for other injectors

Parameters:
  `location` - Instruction to replace
  `insn` - Instruction to replace with

#### replaceNode

    public void replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location,
                            org.objectweb.asm.tree.AbstractInsnNode champion,
                            org.objectweb.asm.tree.InsnList insns)

Replace an instruction in this target with the specified instructions and mark the node as replaced with the specified champion node from the list.

Parameters:
  `location` - Instruction to replace
  `champion` - Instruction which notionally replaces the original insn
  `insns` - Instructions to actually insert (must contain champion)

#### wrapNode

    public void wrapNode​(org.objectweb.asm.tree.AbstractInsnNode location,
                         org.objectweb.asm.tree.AbstractInsnNode champion,
                         org.objectweb.asm.tree.InsnList before,
                         org.objectweb.asm.tree.InsnList after)

Wrap instruction in this target with the specified instructions and mark the node as replaced with the specified champion node from the list.

Parameters:
  `location` - Instruction to replace
  `champion` - Instruction which notionally replaces the original insn
  `before` - Instructions to actually insert (must contain champion)
  `after` - Instructions to insert after the specified location

#### replaceNode

    public void replaceNode​(org.objectweb.asm.tree.AbstractInsnNode location,
                            org.objectweb.asm.tree.InsnList insns)

Replace an instruction in this target with the specified instructions and mark the original node as removed

Parameters:
  `location` - Instruction to replace
  `insns` - Instructions to replace with

#### removeNode

    public void removeNode​(org.objectweb.asm.tree.AbstractInsnNode insn)

Remove the specified instruction from the target and mark it as removed for injections

Parameters:
  `insn` - instruction to remove

#### addLocalVariable

    public void addLocalVariable​(int index,
                                 java.lang.String name,
                                 java.lang.String desc)

Add an entry to the target LVT

Parameters:
  `index` - local variable index
  `name` - local variable name
  `desc` - local variable type

#### addLocalVariable

    public void addLocalVariable​(int index,
                                 java.lang.String name,
                                 java.lang.String desc,
                                 org.objectweb.asm.tree.LabelNode from,
                                 org.objectweb.asm.tree.LabelNode to)

Add an entry to the target LVT between the specified start and end labels

Parameters:
  `index` - local variable index
  `name` - local variable name
  `desc` - local variable type
  `from` - start of range
  `to` - end of range

#### of

    public static Target of​(ClassInfo classInfo,
                            org.objectweb.asm.tree.ClassNode classNode,
                            org.objectweb.asm.tree.MethodNode method)