Class InjectionPoint
- java.lang.Object
-
- org.spongepowered.asm.mixin.injection.InjectionPoint
-
- Direct Known Subclasses:
BeforeConstant,BeforeFinalReturn,BeforeInvoke,BeforeLoadLocal,BeforeNew,BeforeReturn,JumpInsnPoint,MethodHead
public abstract class InjectionPoint extends java.lang.ObjectBase class for injection point discovery classes. Each subclass describes a strategy for locating code injection points within an instruction list, with the
findmethod 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
andandorwhich 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
@AtCodeannotation 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
findmethod, as each call tofindmust 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 tofindare idempotent.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceInjectionPoint.AtCodeInjection point code forAtannotations to usestatic classInjectionPoint.FlagsBoolean extensions for the At parser, mainly to avoid having to add many booleans in the futurestatic classInjectionPoint.RestrictTargetLevelTarget restriction level for different injection point types when used by restricted injectors (eg.static classInjectionPoint.SpecifierAdditional specifier for injection points.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_ALLOWED_SHIFT_BYInitial limit on the value ofAt.by()which triggers warning/error (based on environment)static intMAX_ALLOWED_SHIFT_BYHard limit on the value ofAt.by()which triggers error
-
Constructor Summary
Constructors Modifier Constructor Description protectedInjectionPoint()InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id)InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id, IMessageSink messageSink)InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id, IMessageSink messageSink, InjectionPoint.RestrictTargetLevel targetRestriction)protectedInjectionPoint(InjectionPointData data)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddMessage(java.lang.String format, java.lang.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 InjectionPointafter(InjectionPoint point)Returns an injection point which returns all insns immediately following insns from the supplied injection pointstatic InjectionPointand(InjectionPoint... operands)Returns a composite injection point which returns the intersection of nodes from all component injection pointsstatic InjectionPointbefore(InjectionPoint point)Returns an injection point which returns all insns immediately prior to insns from the supplied injection pointbooleancheckPriority(int targetPriority, int mixinPriority)Runs a priority check in the context of this injection point.abstract booleanfind(java.lang.String desc, org.objectweb.asm.tree.InsnList insns, java.util.Collection<org.objectweb.asm.tree.AbstractInsnNode> nodes)Find injection points in the supplied insn listprotected java.lang.StringgetAtCode()java.lang.StringgetId()java.lang.StringgetSlice()InjectionPoint.SpecifiergetSpecifier(InjectionPoint.Specifier defaultSpecifier)InjectionPoint.RestrictTargetLevelgetTargetRestriction(IInjectionPointContext context)Returns the target restriction level for this injection point.protected static org.objectweb.asm.tree.AbstractInsnNodenextNode(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 InjectionPointor(InjectionPoint... operands)Returns a composite injection point which returns the union of nodes from all component injection pointsstatic InjectionPointparse(IInjectionPointContext context, java.lang.String at, At.Shift shift, int by, java.util.List<java.lang.String> args, java.lang.String target, java.lang.String slice, int ordinal, int opcode, java.lang.String id, int flags)Parse and instantiate an InjectionPoint from the supplied information.static java.util.List<InjectionPoint>parse(IInjectionPointContext context, java.util.List<org.objectweb.asm.tree.AnnotationNode> ats)Parse a collection of InjectionPoints from the suppliedAtannotationsstatic InjectionPointparse(IInjectionPointContext context, org.objectweb.asm.tree.AnnotationNode at)Parse an InjectionPoint from the suppliedAtannotation supplied as an AnnotationNode instancestatic InjectionPointparse(IInjectionPointContext context, At at)Parse an InjectionPoint from the suppliedAtannotationstatic InjectionPointparse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, java.lang.String at, At.Shift shift, int by, java.util.List<java.lang.String> args, java.lang.String target, java.lang.String slice, int ordinal, int opcode, java.lang.String id, int flags)Parse and instantiate an InjectionPoint from the supplied information.static java.util.List<InjectionPoint>parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, java.util.List<org.objectweb.asm.tree.AnnotationNode> ats)Parse a collection of InjectionPoints from the suppliedAtannotationsstatic InjectionPointparse(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 suppliedAtannotation supplied as an AnnotationNode instancestatic InjectionPointparse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, At at)Parse an InjectionPoint from the suppliedAtannotationstatic voidregister(java.lang.Class<? extends InjectionPoint> type)Deprecated.static voidregister(java.lang.Class<? extends InjectionPoint> type, java.lang.String namespace)Register an injection point class.protected voidsetTargetRestriction(InjectionPoint.RestrictTargetLevel targetRestriction)Set a new target restriction level for this injection pointstatic InjectionPointshift(InjectionPoint point, int count)Returns an injection point which returns all insns offset by the specified "count" from insns from the supplied injection pointjava.lang.StringtoString()
-
-
-
Field Detail
-
DEFAULT_ALLOWED_SHIFT_BY
public static final int DEFAULT_ALLOWED_SHIFT_BY
Initial limit on the value ofAt.by()which triggers warning/error (based on environment)- See Also:
- Constant Field Values
-
MAX_ALLOWED_SHIFT_BY
public static final int MAX_ALLOWED_SHIFT_BY
Hard limit on the value ofAt.by()which triggers error- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InjectionPoint
protected InjectionPoint()
-
InjectionPoint
protected InjectionPoint(InjectionPointData data)
-
InjectionPoint
public InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id)
-
InjectionPoint
public InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id, IMessageSink messageSink)
-
InjectionPoint
public InjectionPoint(java.lang.String slice, InjectionPoint.Specifier specifier, java.lang.String id, IMessageSink messageSink, InjectionPoint.RestrictTargetLevel targetRestriction)
-
-
Method Detail
-
getSlice
public java.lang.String getSlice()
-
getSpecifier
public InjectionPoint.Specifier getSpecifier(InjectionPoint.Specifier defaultSpecifier)
-
getId
public java.lang.String getId()
-
addMessage
protected void addMessage(java.lang.String format, java.lang.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.- 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
protected void setTargetRestriction(InjectionPoint.RestrictTargetLevel targetRestriction)
Set a new target restriction level for this injection point
-
getTargetRestriction
public InjectionPoint.RestrictTargetLevel getTargetRestriction(IInjectionPointContext context)
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(java.lang.String desc, org.objectweb.asm.tree.InsnList insns, java.util.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 thenodescollectionnodes- 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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
public static InjectionPoint and(InjectionPoint... operands)
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
public static InjectionPoint or(InjectionPoint... operands)
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
public static InjectionPoint after(InjectionPoint point)
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
public static InjectionPoint before(InjectionPoint point)
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
public static 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 point- Parameters:
point- injection points to perform shiftcount- amount to shift by- Returns:
- adjusted InjectionPoint
-
parse
public static java.util.List<InjectionPoint> parse(IMixinContext context, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AnnotationNode parent, java.util.List<org.objectweb.asm.tree.AnnotationNode> ats)
Parse a collection of InjectionPoints from the suppliedAtannotations- 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 thisAtannotationats-Atannotations to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static java.util.List<InjectionPoint> parse(IInjectionPointContext context, java.util.List<org.objectweb.asm.tree.AnnotationNode> ats)
Parse a collection of InjectionPoints from the suppliedAtannotations- Parameters:
context- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsats-Atannotations to parse information from- Returns:
- InjectionPoint parsed from the supplied data or null if parsing failed
-
parse
public static InjectionPoint parse(IInjectionPointContext context, At at)
Parse an InjectionPoint from the suppliedAtannotation- Parameters:
context- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsat-Atannotation 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 suppliedAtannotation- 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 thisAtannotationat-Atannotation 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 suppliedAtannotation 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 thisAtannotationat-Atannotation 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 suppliedAtannotation supplied as an AnnotationNode instance- Parameters:
context- Data for the mixin containing the annotation, used to obtain the refmap, amongst other thingsat-Atannotation 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, java.lang.String at, At.Shift shift, int by, java.util.List<java.lang.String> args, java.lang.String target, java.lang.String slice, int ordinal, int opcode, java.lang.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 thisAtannotationat- 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, java.lang.String at, At.Shift shift, int by, java.util.List<java.lang.String> args, java.lang.String target, java.lang.String slice, int ordinal, int opcode, java.lang.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 thisAtannotationat- 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
protected java.lang.String getAtCode()
-
register
@Deprecated public static void register(java.lang.Class<? extends InjectionPoint> type)
Deprecated.Register an injection point class. The supplied class must be decorated with anInjectionPoint.AtCodeannotation for registration purposes.- Parameters:
type- injection point type to register
-
register
public static void register(java.lang.Class<? extends InjectionPoint> type, java.lang.String namespace)
Register an injection point class. The supplied class must be decorated with anInjectionPoint.AtCodeannotation for registration purposes.- Parameters:
type- injection point type to registernamespace- namespace for AtCode
-
-