Class InjectionPoint
- Direct Known Subclasses:
BeforeConstant
,BeforeFinalReturn
,BeforeInvoke
,BeforeLoadLocal
,BeforeNew
,BeforeReturn
,JumpInsnPoint
,MethodHead
Base class for injection point discovery classes. Each subclass describes
a strategy for locating code injection points within an instruction list,
with the find
method populating a collection with insn nodes
from the supplied list which satisfy its strategy.
This base class also contains composite strategy factory methods such as
and
and or
which allow strategies to be combined
using intersection (and) or union (or) relationships to allow multiple
strategies to be easily combined.
Built-in Injection Points
The following built-in Injection Points are available:
HEAD
- Selects the first insnRETURN
- Selects RETURN insnsTAIL
- Selects the last RETURN insnINVOKE
- Selects method invocationsINVOKE_ASSIGN
- Selects STORE insns after method invocations which return a valueFIELD
- Selects field access insnsNEW
- Selects object constructionsINVOKE_STRING
- Selects method invocations where a specific string is passed to the invocation.JUMP
- Selects branching (jump) instructionsCONSTANT
- Selects constant values
Additionally, the two special injection points are available which are
only supported for use with @ModifyVariable
:
LOAD
- Selects xLOAD insns matching the ModifyVariable discriminators.STORE
- Selects xSTORE insns matching the ModifyVariable discriminators.
See the javadoc for each type for more details on the scheme used by each injection point.
Custom Injection Points
You are free to create your own injection point subclasses. Once defined, they can be used by your mixins in one of two ways:
- Specify the fully-qualified name of the injection point class in the
@At.value
. - Decorate your injection point class with
@AtCode
annotation which specifies a namespace and shortcode for the injection point, and register the class in your mixin config. You can then specify the namespaced code (eg. MYMOD:CUSTOMPOINT) in@At.value
.
When writing custom injection points, note that the general contract of
injection points is that they be entirely - or at least behaviourally -
stateless. It is allowed for a single InjectionPoint instance to be
used by the mixin processor for multiple injections and thus implementing
classes MUST NOT cache the insn list, event, or nodes instance
passed to the find
method, as each call to find
must be considered a separate contract and the InjectionPoint's lifespan is
not linked to the discovery lifespan. It is therefore important that the
InjectionPoint implementation is fully stateless and that calls to
find
are idempotent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
Injection point code forAt
annotations to usestatic final class
Boolean extensions for the At parser, mainly to avoid having to add many booleans in the futurestatic enum
Target restriction level for different injection point types when used by restricted injectors (eg.static enum
Additional specifier for injection points. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
InjectionPoint
(String slice, InjectionPoint.Specifier specifier, String id) InjectionPoint
(String slice, InjectionPoint.Specifier specifier, String id, IMessageSink messageSink) InjectionPoint
(String slice, InjectionPoint.Specifier specifier, String id, IMessageSink messageSink, InjectionPoint.RestrictTargetLevel targetRestriction) protected
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addMessage
(String format, Object... args) Notify method for subclasses to log when notable but non-fatal failures occur, for example allows subclasses to add notes when they return no results.static InjectionPoint
after
(InjectionPoint point) Returns an injection point which returns all insns immediately following insns from the supplied injection pointstatic InjectionPoint
and
(InjectionPoint... operands) Returns a composite injection point which returns the intersection of nodes from all component injection pointsstatic InjectionPoint
before
(InjectionPoint point) Returns an injection point which returns all insns immediately prior to insns from the supplied injection pointboolean
checkPriority
(int targetPriority, int mixinPriority) Runs a priority check in the context of this injection point.abstract boolean
find
(String desc, org.objectweb.asm.tree.InsnList insns, Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes) Find injection points in the supplied insn listprotected String
getId()
getSlice()
getSpecifier
(InjectionPoint.Specifier defaultSpecifier) Returns the target restriction level for this injection point.protected static org.objectweb.asm.tree.AbstractInsnNode
nextNode
(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.AbstractInsnNode insn) Get the insn immediately following the specified insn, or return the same insn if the insn is the last insn in the liststatic InjectionPoint
or
(InjectionPoint... operands) Returns a composite injection point which returns the union of nodes from all component injection pointsstatic InjectionPoint
parse
(IInjectionPointContext context, String at, At.Shift shift, int by, List<String> args, String target, String slice, int ordinal, int opcode, String id, int flags) Parse and instantiate an InjectionPoint from the supplied information.static List
<InjectionPoint> parse
(IInjectionPointContext context, List<org.objectweb.asm.tree.AnnotationNode> ats) Parse a collection of InjectionPoints from the suppliedAt
annotationsstatic InjectionPoint
parse
(IInjectionPointContext context, org.objectweb.asm.tree.AnnotationNode at) Parse an InjectionPoint from the suppliedAt
annotation supplied as an AnnotationNode instancestatic InjectionPoint
parse
(IInjectionPointContext context, At at) Parse an InjectionPoint from the suppliedAt
annotationstatic InjectionPoint
parse
(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, String at, At.Shift shift, int by, List<String> args, String target, String slice, int ordinal, int opcode, String id, int flags) Parse and instantiate an InjectionPoint from the supplied information.static List
<InjectionPoint> parse
(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, List<org.objectweb.asm.tree.AnnotationNode> ats) Parse a collection of InjectionPoints from the suppliedAt
annotationsstatic InjectionPoint
parse
(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, org.objectweb.asm.tree.AnnotationNode at) Parse an InjectionPoint from the suppliedAt
annotation supplied as an AnnotationNode instancestatic InjectionPoint
parse
(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, At at) Parse an InjectionPoint from the suppliedAt
annotationstatic void
register
(Class<? extends InjectionPoint> type) Deprecated.static void
register
(Class<? extends InjectionPoint> type, String namespace) Register an injection point class.protected void
setTargetRestriction
(InjectionPoint.RestrictTargetLevel targetRestriction) Set a new target restriction level for this injection pointstatic InjectionPoint
shift
(InjectionPoint point, int count) Returns an injection point which returns all insns offset by the specified "count" from insns from the supplied injection pointtoString()
-
Field Details
-
DEFAULT_ALLOWED_SHIFT_BY
public static final int DEFAULT_ALLOWED_SHIFT_BYInitial limit on the value ofAt.by()
which triggers warning/error (based on environment)- See Also:
-
MAX_ALLOWED_SHIFT_BY
public static final int MAX_ALLOWED_SHIFT_BYHard limit on the value ofAt.by()
which triggers error- See Also:
-
-
Constructor Details
-
InjectionPoint
protected InjectionPoint() -
InjectionPoint
-
InjectionPoint
-
InjectionPoint
public InjectionPoint(String slice, InjectionPoint.Specifier specifier, String id, IMessageSink messageSink) -
InjectionPoint
public InjectionPoint(String slice, InjectionPoint.Specifier specifier, String id, IMessageSink messageSink, InjectionPoint.RestrictTargetLevel targetRestriction)
-
-
Method Details
-
getSlice
-
getSpecifier
-
getId
-
addMessage
Notify method for subclasses to log when notable but non-fatal failures occur, for example allows subclasses to add notes when they return no results.- Parameters:
format
- Message formatargs
- Format args
-
checkPriority
public boolean checkPriority(int targetPriority, int mixinPriority) Runs a priority check in the context of this injection point. A priority check should return true if the injection point is allowed to inject given the relative priorities of the target (a method merged by another mixin with targetPriority) and the incoming mixin with priority mixinPriority.- Parameters:
targetPriority
- Priority of the mixin which originally merged the target method in questionmixinPriority
- Priority of the mixin which owns the owning injector- Returns:
- true if the priority check succeeds
-
setTargetRestriction
Set a new target restriction level for this injection point -
getTargetRestriction
Returns the target restriction level for this injection point. This level defines whether an injection point is valid in its current state when being used by a restricted injector (currentlyCallbackInjector
).- Parameters:
context
- injection-specific context- Returns:
- restriction level
-
find
public abstract boolean find(String desc, org.objectweb.asm.tree.InsnList insns, Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes) Find injection points in the supplied insn list- Parameters:
desc
- Method descriptor, supplied to allow return types and arguments etc. to be determinedinsns
- Insn list to search in, the strategy MUST ONLY add nodes from this list to thenodes
collectionnodes
- Collection of nodes to populate. Injectors should NOT make any assumptions about the state of this collection and should only call the add() method- Returns:
- true if one or more injection points were found
-
toString
-
nextNode
protected static org.objectweb.asm.tree.AbstractInsnNode nextNode(org.objectweb.asm.tree.InsnList insns, org.objectweb.asm.tree.AbstractInsnNode insn) Get the insn immediately following the specified insn, or return the same insn if the insn is the last insn in the list- Parameters:
insns
- Insn list to fetch frominsn
- Insn node- Returns:
- Next insn or the same insn if last in the list
-
and
Returns a composite injection point which returns the intersection of nodes from all component injection points- Parameters:
operands
- injection points to perform intersection- Returns:
- adjusted InjectionPoint
-
or
Returns a composite injection point which returns the union of nodes from all component injection points- Parameters:
operands
- injection points to perform union- Returns:
- adjusted InjectionPoint
-
after
Returns an injection point which returns all insns immediately following insns from the supplied injection point- Parameters:
point
- injection points to perform shift- Returns:
- adjusted InjectionPoint
-
before
Returns an injection point which returns all insns immediately prior to insns from the supplied injection point- Parameters:
point
- injection points to perform shift- Returns:
- adjusted InjectionPoint
-
shift
Returns an injection point which returns all insns offset by the specified "count" from insns from the supplied injection point- Parameters:
point
- injection points to perform shiftcount
- amount to shift by- Returns:
- adjusted InjectionPoint
-
parse
public static List<InjectionPoint> parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, List<org.objectweb.asm.tree.AnnotationNode> ats) Parse a collection of InjectionPoints from the suppliedAt
annotations- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsmethod
- The annotated handler methodparent
- The parent annotation which owns thisAt
annotationats
-At
annotations to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static List<InjectionPoint> parse(IInjectionPointContext context, List<org.objectweb.asm.tree.AnnotationNode> ats) Parse a collection of InjectionPoints from the suppliedAt
annotations- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsats
-At
annotations to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
Parse an InjectionPoint from the suppliedAt
annotation- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsat
-At
annotation to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, At at) Parse an InjectionPoint from the suppliedAt
annotation- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsmethod
- The annotated handler methodparent
- The parent annotation which owns thisAt
annotationat
-At
annotation to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, org.objectweb.asm.tree.AnnotationNode at) Parse an InjectionPoint from the suppliedAt
annotation supplied as an AnnotationNode instance- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsmethod
- The annotated handler methodparent
- The parent annotation which owns thisAt
annotationat
-At
annotation to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IInjectionPointContext context, org.objectweb.asm.tree.AnnotationNode at) Parse an InjectionPoint from the suppliedAt
annotation supplied as an AnnotationNode instance- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsat
-At
annotation to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, String at, At.Shift shift, int by, List<String> args, String target, String slice, int ordinal, int opcode, String id, int flags) Parse and instantiate an InjectionPoint from the supplied information. Returns null if an InjectionPoint could not be created.- Parameters:
context
- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsmethod
- The annotated handler methodparent
- The parent annotation which owns thisAt
annotationat
- Injection point specifiershift
- Shift type to applyby
- Amount of shift to apply for the BY shift typeargs
- Named parameterstarget
- Target for supported injection pointsslice
- Slice id for injectors which support multiple slicesordinal
- Ordinal offset for supported injection pointsopcode
- Bytecode opcode for supported injection pointsid
- Injection point id from annotationflags
- Additional flags- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IInjectionPointContext context, String at, At.Shift shift, int by, List<String> args, String target, String slice, int ordinal, int opcode, String id, int flags) Parse and instantiate an InjectionPoint from the supplied information. Returns null if an InjectionPoint could not be created.- Parameters:
context
- The injection point context which owns thisAt
annotationat
- Injection point specifiershift
- Shift type to applyby
- Amount of shift to apply for the BY shift typeargs
- Named parameterstarget
- Target for supported injection pointsslice
- Slice id for injectors which support multiple slicesordinal
- Ordinal offset for supported injection pointsopcode
- Bytecode opcode for supported injection pointsid
- Injection point id from annotationflags
- Additional flags- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
getAtCode
-
register
Deprecated.Register an injection point class. The supplied class must be decorated with anInjectionPoint.AtCode
annotation for registration purposes.- Parameters:
type
- injection point type to register
-
register
Register an injection point class. The supplied class must be decorated with anInjectionPoint.AtCode
annotation for registration purposes.- Parameters:
type
- injection point type to registernamespace
- namespace for AtCode
-