public abstract class Injector
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Injector.InjectorData
Redirection data bundle base.
|
static class |
Injector.TargetNode
A nominated target node
|
| Modifier and Type | Field and 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 |
isStatic
True if the callback method is static
|
protected static org.apache.logging.log4j.Logger |
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 and Description |
|---|
Injector(InjectionInfo info,
java.lang.String annotationType)
Make a new CallbackInjector for the supplied InjectionInfo
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addTargetNode(Target target,
java.util.List<InjectionNodes.InjectionNode> myNodes,
org.objectweb.asm.tree.AbstractInsnNode node,
java.util.Set<InjectionPoint> nominators) |
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(org.objectweb.asm.tree.MethodNode into,
InjectionPoint injectionPoint,
org.objectweb.asm.tree.InsnList insns,
java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes) |
protected abstract void |
inject(Target target,
InjectionNodes.InjectionNode node) |
void |
inject(Target target,
java.util.List<InjectionNodes.InjectionNode> nodes)
Performs the injection on the specified target
|
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) |
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(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 |
throwException(org.objectweb.asm.tree.InsnList insns,
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.
|
protected static final org.apache.logging.log4j.Logger logger
protected InjectionInfo info
protected final java.lang.String annotationType
protected final org.objectweb.asm.tree.ClassNode classNode
protected final org.objectweb.asm.tree.MethodNode methodNode
protected final org.objectweb.asm.Type[] methodArgs
protected final org.objectweb.asm.Type returnType
protected final boolean isStatic
public Injector(InjectionInfo info, java.lang.String annotationType)
info - Information about this injectionpublic java.lang.String toString()
toString in class java.lang.Objectpublic final java.util.List<InjectionNodes.InjectionNode> find(InjectorTarget injectorTarget, java.util.List<InjectionPoint> injectionPoints)
injectorTarget - Target method to inject intoinjectionPoints - InjectionPoint instances which will identify
target insns in the target methodprotected void addTargetNode(Target target, java.util.List<InjectionNodes.InjectionNode> myNodes, org.objectweb.asm.tree.AbstractInsnNode node, java.util.Set<InjectionPoint> nominators)
public final void inject(Target target, java.util.List<InjectionNodes.InjectionNode> nodes)
target - target to inject intonodes - selected nodesprotected boolean findTargetNodes(org.objectweb.asm.tree.MethodNode into,
InjectionPoint injectionPoint,
org.objectweb.asm.tree.InsnList insns,
java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)
protected void sanityCheck(Target target, java.util.List<InjectionPoint> injectionPoints)
protected final void checkTargetModifiers(Target target, boolean exactMatch)
target - Target to checkexactMatch - True if static must match, false to only check if an
instance handler is targetting a static methodprotected void checkTargetForNode(Target target, InjectionNodes.InjectionNode node, InjectionPoint.RestrictTargetLevel targetLevel)
target - Target methodnode - Injection locationprotected abstract void inject(Target target, InjectionNodes.InjectionNode node)
protected void postInject(Target target, InjectionNodes.InjectionNode node)
protected org.objectweb.asm.tree.AbstractInsnNode invokeHandler(org.objectweb.asm.tree.InsnList insns)
insns - Instruction list to inject intoprotected org.objectweb.asm.tree.AbstractInsnNode invokeHandler(org.objectweb.asm.tree.InsnList insns,
org.objectweb.asm.tree.MethodNode handler)
insns - Instruction list to inject intohandler - Actual method to invoke (may be different if using a
surrogate)protected org.objectweb.asm.tree.AbstractInsnNode invokeHandlerWithArgs(org.objectweb.asm.Type[] args,
org.objectweb.asm.tree.InsnList insns,
int[] argMap)
args - handler argumentsinsns - InsnList to inject insns intoargMap - Mapping of args to local variablesprotected org.objectweb.asm.tree.AbstractInsnNode invokeHandlerWithArgs(org.objectweb.asm.Type[] args,
org.objectweb.asm.tree.InsnList insns,
int[] argMap,
int startArg,
int endArg)
args - handler argumentsinsns - InsnList to inject insns intoargMap - Mapping of args to local variablesstartArg - Starting arg to consumeendArg - Ending arg to consumeprotected int[] storeArgs(Target target, org.objectweb.asm.Type[] args, org.objectweb.asm.tree.InsnList insns, int start)
target - target methodargs - argument typesinsns - instruction list to generate insns intostart - Starting indexprotected void storeArgs(org.objectweb.asm.Type[] args,
org.objectweb.asm.tree.InsnList insns,
int[] argMap,
int start,
int end)
args - argument typesinsns - instruction list to generate insns intoargMap - generated argmap containing local indices for all argsstart - Starting indexend - Ending indexprotected void pushArgs(org.objectweb.asm.Type[] args,
org.objectweb.asm.tree.InsnList insns,
int[] argMap,
int start,
int end)
args - argument typesinsns - instruction list to generate insns intoargMap - generated argmap containing local indices for all argsstart - Starting indexend - Ending indexprotected void pushArgs(org.objectweb.asm.Type[] args,
org.objectweb.asm.tree.InsnList insns,
int[] argMap,
int start,
int end,
Target.Extension extension)
args - argument typesinsns - instruction list to generate insns intoargMap - generated argmap containing local indices for all argsstart - Starting indexend - Ending indexprotected final void validateParams(Injector.InjectorData injector, org.objectweb.asm.Type returnType, org.objectweb.asm.Type... args)
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.
injector - Data bundle for the injectorreturnType - Return type for the handler, must not be nullargs - Array of handler args, must not be nullprotected final boolean checkCoerce(int index,
org.objectweb.asm.Type toType,
java.lang.String description,
boolean allowCoercion)
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.index - Handler argument index, pass in a negative value (by
convention -1) to specify handler return typetoType - Desired type based on the injector contractdescription - human-readable description of the handler method, used
in raised exceptionallowCoercion - True if coercion logic can be applied to this
argument, false to only allow a precise matchprotected void throwException(org.objectweb.asm.tree.InsnList insns,
java.lang.String exceptionType,
java.lang.String message)
insns - Insn list to inject intoexceptionType - Type of exception to throw (binary name)message - Message to pass to the exception constructorpublic static boolean canCoerce(org.objectweb.asm.Type from,
org.objectweb.asm.Type to)
from - type to coerce fromto - type to coerce topublic static boolean canCoerce(java.lang.String from,
java.lang.String to)
from - type to coerce fromto - type to coerce topublic static boolean canCoerce(char from,
char to)
from - type to coerce fromto - type to coerce to