Class Target
java.lang.Object
org.spongepowered.asm.mixin.injection.struct.Target
- All Implemented Interfaces:
Comparable<Target>,Iterable<org.objectweb.asm.tree.AbstractInsnNode>
- Direct Known Subclasses:
Constructor
public class Target
extends Object
implements Comparable<Target>, 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 ClassesModifier and TypeClassDescriptionclassA stateful extension of stack or locals space for a target method which can be applied. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal org.objectweb.asm.Type[]Method argumentsfinal ClassInfoTarget class infofinal org.objectweb.asm.tree.ClassNodeTarget class nodefinal org.objectweb.asm.tree.InsnListMethod instructionsfinal booleanTrue if the method is staticfinal org.objectweb.asm.tree.MethodNodeTarget methodfinal org.objectweb.asm.TypeReturn type computed from the method descriptor -
Method Summary
Modifier and TypeMethodDescriptionaddInjectionNode(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 existsvoidaddLocalVariable(int index, String name, String desc) Add an entry to the target LVTvoidaddLocalVariable(int index, String name, 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 labelsintAllocate a new local variable for the methodintallocateLocals(int locals) Allocate a number of new local variables for this method, returns the first local variable index of the allocated range.intCreates a new locals extension.Creates a new stack extension.org.objectweb.asm.tree.MethodInsnNodefindInitNodeFor(org.objectweb.asm.tree.TypeInsnNode newNode) Find the first <init> invocation after the specified NEW insnorg.objectweb.asm.tree.MethodInsnNodefindInitNodeFor(org.objectweb.asm.tree.TypeInsnNode newNode, 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 positionint[]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 positionorg.objectweb.asm.tree.AbstractInsnNodeget(int index) Return the instruction at the specified indexint[]Get the argument indices for this target, calculated on first usegetCallbackDescriptor(boolean captureLocals, org.objectweb.asm.Type[] locals, org.objectweb.asm.Type[] argumentTypes, int startIndex, int extra) Get the callback descriptorgetCallbackDescriptor(org.objectweb.asm.Type[] locals, org.objectweb.asm.Type[] argumentTypes) Get the callback descriptorGet the CallbackInfo class used for this target, based on the target return typeintGet the current max locals of the methodintGet the current max stack of the methodgetDesc()Get the target method descriptorgetInjectionNode(org.objectweb.asm.tree.AbstractInsnNode node) Get an injection node from this collection if it already exists, returns null if the node is not trackedintGet the original max locals of the methodintGet the original max stack of the methodgetName()Get the target method nameGet the target method signatureGet "simple" callback descriptor (descriptor with only CallbackInfo)intindexOf(org.objectweb.asm.tree.AbstractInsnNode insn) Return the index of the specified instruction in this instruction listintReturn the index of the specified instruction in this instruction listvoidinsert(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode insn) Insert the supplied instruction after the specified instructionvoidinsert(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.InsnList insns) Insert the supplied instructions after the specified instructionvoidinsert(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.AbstractInsnNode insn) Insert the supplied instruction after the specified instructionvoidinsert(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.InsnList insns) Insert the supplied instructions after the specified instructionvoidinsertBefore(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.AbstractInsnNode insn) Insert the supplied instruction before the specified instructionvoidinsertBefore(org.objectweb.asm.tree.AbstractInsnNode location, org.objectweb.asm.tree.InsnList insns) Insert the supplied instructions before the specified instructionvoidinsertBefore(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.AbstractInsnNode insn) Insert the supplied instruction before the specified instructionvoidinsertBefore(InjectionNodes.InjectionNode location, org.objectweb.asm.tree.InsnList insns) Insert the supplied instructions before the specified instructionIterator<org.objectweb.asm.tree.AbstractInsnNode> iterator()static Targetof(ClassInfo classInfo, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode method) voidremoveNode(org.objectweb.asm.tree.AbstractInsnNode insn) Remove the specified instruction from the target and mark it as removed for injectionsvoidreplaceNode(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 injectorsvoidreplaceNode(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.voidreplaceNode(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 removedtoString()voidwrapNode(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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
classInfo
Target class info -
classNode
public final org.objectweb.asm.tree.ClassNode classNodeTarget class node -
method
public final org.objectweb.asm.tree.MethodNode methodTarget method -
insns
public final org.objectweb.asm.tree.InsnList insnsMethod instructions -
isStatic
public final boolean isStaticTrue if the method is static -
arguments
public final org.objectweb.asm.Type[] argumentsMethod arguments -
returnType
public final org.objectweb.asm.Type returnTypeReturn type computed from the method descriptor
-
-
Method Details
-
addInjectionNode
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
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
Get the target method name -
getDesc
Get the target method descriptor -
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 methodNote 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
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
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 typesstart- 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 typesstart- starting indexfresh- 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
Get the CallbackInfo class used for this target, based on the target return type- Returns:
- CallbackInfo class name
-
getSimpleCallbackDescriptor
Get "simple" callback descriptor (descriptor with only CallbackInfo)- Returns:
- generated descriptor
-
getCallbackDescriptor
public String getCallbackDescriptor(org.objectweb.asm.Type[] locals, org.objectweb.asm.Type[] argumentTypes) Get the callback descriptor- Parameters:
locals- Local variable typesargumentTypes- Argument types- Returns:
- generated descriptor
-
getCallbackDescriptor
public 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 localslocals- Local variable typesargumentTypes- Argument typesstartIndex- local index to start atextra- extra locals to include- Returns:
- generated descriptor
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<Target>
-
indexOf
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
-
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, 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 insndesc- Descriptor to match- Returns:
- INVOKESPECIAL opcode of ctor, or null if not found
-
insert
Insert the supplied instructions after the specified instruction- Parameters:
location- Instruction to insert beforeinsns- 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 beforeinsn- 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 beforeinsns- 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 beforeinsn- 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 beforeinsns- 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 beforeinsn- 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 beforeinsns- 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 beforeinsn- 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 replaceinsn- 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 replacechampion- Instruction which notionally replaces the original insninsns- 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 replacechampion- Instruction which notionally replaces the original insnbefore- 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 replaceinsns- 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
Add an entry to the target LVT- Parameters:
index- local variable indexname- local variable namedesc- local variable type
-
addLocalVariable
public void addLocalVariable(int index, String name, 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 indexname- local variable namedesc- local variable typefrom- start of rangeto- end of range
-
of
-