mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Abstract out injection point and slice context to interface
This commit is contained in:
1 parent
20793c058e
commit
3057bd9ca1
20 files changed
+156
-114
No files matched your search
@@ -38,7 +38,7 @@ import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
@@ -209,7 +209,7 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
}
|
||||
|
||||
public static String inflectTarget(String accessorName, AccessorType accessorType, String accessorDescription,
|
||||
IReferenceMapperContext context, boolean verbose) {
|
||||
IMixinContext context, boolean verbose) {
|
||||
Matcher nameMatcher = AccessorInfo.PATTERN_ACCESSOR.matcher(accessorName);
|
||||
if (nameMatcher.matches()) {
|
||||
String prefix = nameMatcher.group(1);
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@
|
||||
package org.spongepowered.asm.mixin.gen.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.gen.AccessorInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class InvalidAccessorException extends InvalidMixinException {
|
||||
|
||||
private final AccessorInfo info;
|
||||
|
||||
public InvalidAccessorException(IReferenceMapperContext context, String message) {
|
||||
public InvalidAccessorException(IMixinContext context, String message) {
|
||||
super(context, message);
|
||||
this.info = null;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class InvalidAccessorException extends InvalidMixinException {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public InvalidAccessorException(IReferenceMapperContext context, Throwable cause) {
|
||||
public InvalidAccessorException(IMixinContext context, Throwable cause) {
|
||||
super(context, cause);
|
||||
this.info = null;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class InvalidAccessorException extends InvalidMixinException {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public InvalidAccessorException(IReferenceMapperContext context, String message, Throwable cause) {
|
||||
public InvalidAccessorException(IMixinContext context, String message, Throwable cause) {
|
||||
super(context, message, cause);
|
||||
this.info = null;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,7 @@ import org.spongepowered.asm.mixin.injection.points.JumpInsnPoint;
|
||||
import org.spongepowered.asm.mixin.injection.points.MethodHead;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
@@ -416,32 +415,32 @@ public abstract class InjectionPoint {
|
||||
* Parse a collection of InjectionPoints from the supplied {@link At}
|
||||
* annotations
|
||||
*
|
||||
* @param info Data for the mixin containing the annotation, used to obtain
|
||||
* @param owner Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param ats {@link At} annotations to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static List<InjectionPoint> parse(SpecialMethodInfo info, List<AnnotationNode> ats) {
|
||||
return InjectionPoint.parse(info.getContext(), info.getMethod(), info.getAnnotation(), ats);
|
||||
public static List<InjectionPoint> parse(IInjectionPointContext owner, List<AnnotationNode> ats) {
|
||||
return InjectionPoint.parse(owner.getContext(), owner.getMethod(), owner.getAnnotation(), ats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a collection of InjectionPoints from the supplied {@link At}
|
||||
* annotations
|
||||
*
|
||||
* @param mixin Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param context Data for the mixin containing the annotation, used to
|
||||
* obtain the refmap, amongst other things
|
||||
* @param method The annotated handler method
|
||||
* @param parent The parent annotation which owns this {@link At} annotation
|
||||
* @param ats {@link At} annotations to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static List<InjectionPoint> parse(MixinTargetContext mixin, MethodNode method, AnnotationNode parent, List<AnnotationNode> ats) {
|
||||
public static List<InjectionPoint> parse(IMixinContext context, MethodNode method, AnnotationNode parent, List<AnnotationNode> ats) {
|
||||
Builder<InjectionPoint> injectionPoints = ImmutableList.<InjectionPoint>builder();
|
||||
for (AnnotationNode at : ats) {
|
||||
InjectionPoint injectionPoint = InjectionPoint.parse(mixin, method, parent, at);
|
||||
InjectionPoint injectionPoint = InjectionPoint.parse(context, method, parent, at);
|
||||
if (injectionPoint != null) {
|
||||
injectionPoints.add(injectionPoint);
|
||||
}
|
||||
@@ -452,30 +451,30 @@ public abstract class InjectionPoint {
|
||||
/**
|
||||
* Parse an InjectionPoint from the supplied {@link At} annotation
|
||||
*
|
||||
* @param info Data for the mixin containing the annotation, used to obtain
|
||||
* @param owner Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param at {@link At} annotation to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static InjectionPoint parse(SpecialMethodInfo info, At at) {
|
||||
return InjectionPoint.parse(info.getContext(), info.getMethod(), info.getAnnotation(), at.value(), at.shift(), at.by(),
|
||||
public static InjectionPoint parse(IInjectionPointContext owner, At at) {
|
||||
return InjectionPoint.parse(owner.getContext(), owner.getMethod(), owner.getAnnotation(), at.value(), at.shift(), at.by(),
|
||||
Arrays.asList(at.args()), at.target(), at.slice(), at.ordinal(), at.opcode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an InjectionPoint from the supplied {@link At} annotation
|
||||
*
|
||||
* @param mixin Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param context Data for the mixin containing the annotation, used to
|
||||
* obtain the refmap, amongst other things
|
||||
* @param method The annotated handler method
|
||||
* @param parent The parent annotation which owns this {@link At} annotation
|
||||
* @param at {@link At} annotation to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static InjectionPoint parse(MixinTargetContext mixin, MethodNode method, AnnotationNode parent, At at) {
|
||||
return InjectionPoint.parse(mixin, method, parent, at.value(), at.shift(), at.by(), Arrays.asList(at.args()), at.target(), at.slice(),
|
||||
public static InjectionPoint parse(IMixinContext context, MethodNode method, AnnotationNode parent, At at) {
|
||||
return InjectionPoint.parse(context, method, parent, at.value(), at.shift(), at.by(), Arrays.asList(at.args()), at.target(), at.slice(),
|
||||
at.ordinal(), at.opcode());
|
||||
}
|
||||
|
||||
@@ -483,29 +482,29 @@ public abstract class InjectionPoint {
|
||||
* Parse an InjectionPoint from the supplied {@link At} annotation supplied
|
||||
* as an AnnotationNode instance
|
||||
*
|
||||
* @param info Data for the mixin containing the annotation, used to obtain
|
||||
* @param owner Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param node {@link At} annotation to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static InjectionPoint parse(SpecialMethodInfo info, AnnotationNode node) {
|
||||
return InjectionPoint.parse(info.getContext(), info.getMethod(), info.getAnnotation(), node);
|
||||
public static InjectionPoint parse(IInjectionPointContext owner, AnnotationNode node) {
|
||||
return InjectionPoint.parse(owner.getContext(), owner.getMethod(), owner.getAnnotation(), node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an InjectionPoint from the supplied {@link At} annotation supplied
|
||||
* as an AnnotationNode instance
|
||||
*
|
||||
* @param mixin Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param context Data for the mixin containing the annotation, used to
|
||||
* obtain the refmap, amongst other things
|
||||
* @param method The annotated handler method
|
||||
* @param parent The parent annotation which owns this {@link At} annotation
|
||||
* @param node {@link At} annotation to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static InjectionPoint parse(MixinTargetContext mixin, MethodNode method, AnnotationNode parent, AnnotationNode node) {
|
||||
public static InjectionPoint parse(IMixinContext context, MethodNode method, AnnotationNode parent, AnnotationNode node) {
|
||||
String at = ASMHelper.<String>getAnnotationValue(node, "value");
|
||||
List<String> args = ASMHelper.<List<String>>getAnnotationValue(node, "args");
|
||||
String target = ASMHelper.<String>getAnnotationValue(node, "target", "");
|
||||
@@ -519,15 +518,15 @@ public abstract class InjectionPoint {
|
||||
args = ImmutableList.<String>of();
|
||||
}
|
||||
|
||||
return InjectionPoint.parse(mixin, method, parent, at, shift, by, args, target, slice, ordinal, opcode);
|
||||
return InjectionPoint.parse(context, method, parent, at, shift, by, args, target, slice, ordinal, opcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and instantiate an InjectionPoint from the supplied information.
|
||||
* Returns null if an InjectionPoint could not be created.
|
||||
*
|
||||
* @param mixin Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param context Data for the mixin containing the annotation, used to
|
||||
* obtain the refmap, amongst other things
|
||||
* @param method The annotated handler method
|
||||
* @param parent The parent annotation which owns this {@link At} annotation
|
||||
* @param at Injection point specifier
|
||||
@@ -541,16 +540,16 @@ public abstract class InjectionPoint {
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
*/
|
||||
public static InjectionPoint parse(MixinTargetContext mixin, MethodNode method, AnnotationNode parent, String at, At.Shift shift, int by,
|
||||
public static InjectionPoint parse(IMixinContext context, MethodNode method, AnnotationNode parent, String at, At.Shift shift, int by,
|
||||
List<String> args, String target, String slice, int ordinal, int opcode) {
|
||||
InjectionPointData data = new InjectionPointData(mixin, method, parent, at, args, target, slice, ordinal, opcode);
|
||||
Class<? extends InjectionPoint> ipClass = findClass(mixin, data);
|
||||
InjectionPoint point = InjectionPoint.create(mixin, data, ipClass);
|
||||
InjectionPointData data = new InjectionPointData(context, method, parent, at, args, target, slice, ordinal, opcode);
|
||||
Class<? extends InjectionPoint> ipClass = findClass(context, data);
|
||||
InjectionPoint point = InjectionPoint.create(context, data, ipClass);
|
||||
return InjectionPoint.shift(point, shift, by);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Class<? extends InjectionPoint> findClass(MixinTargetContext mixin, InjectionPointData data) {
|
||||
private static Class<? extends InjectionPoint> findClass(IMixinContext context, InjectionPointData data) {
|
||||
String type = data.getType();
|
||||
Class<? extends InjectionPoint> ipClass = InjectionPoint.types.get(type);
|
||||
if (ipClass == null) {
|
||||
@@ -559,29 +558,29 @@ public abstract class InjectionPoint {
|
||||
ipClass = (Class<? extends InjectionPoint>)Class.forName(type);
|
||||
InjectionPoint.types.put(type, ipClass);
|
||||
} catch (Exception ex) {
|
||||
throw new InvalidInjectionException(mixin, data + " could not be loaded or is not a valid InjectionPoint", ex);
|
||||
throw new InvalidInjectionException(context, data + " could not be loaded or is not a valid InjectionPoint", ex);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidInjectionException(mixin, data + " is not a valid injection point specifier");
|
||||
throw new InvalidInjectionException(context, data + " is not a valid injection point specifier");
|
||||
}
|
||||
}
|
||||
return ipClass;
|
||||
}
|
||||
|
||||
private static InjectionPoint create(MixinTargetContext mixin, InjectionPointData data, Class<? extends InjectionPoint> ipClass) {
|
||||
private static InjectionPoint create(IMixinContext context, InjectionPointData data, Class<? extends InjectionPoint> ipClass) {
|
||||
Constructor<? extends InjectionPoint> ipCtor = null;
|
||||
try {
|
||||
ipCtor = ipClass.getDeclaredConstructor(InjectionPointData.class);
|
||||
ipCtor.setAccessible(true);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new InvalidInjectionException(mixin, ipClass.getName() + " must contain a constructor which accepts an InjectionPointData", ex);
|
||||
throw new InvalidInjectionException(context, ipClass.getName() + " must contain a constructor which accepts an InjectionPointData", ex);
|
||||
}
|
||||
|
||||
InjectionPoint point = null;
|
||||
try {
|
||||
point = ipCtor.newInstance(data);
|
||||
} catch (Exception ex) {
|
||||
throw new InvalidInjectionException(mixin, "Error whilst instancing injection point " + ipClass.getName() + " for " + data.getAt(), ex);
|
||||
throw new InvalidInjectionException(context, "Error whilst instancing injection point " + ipClass.getName() + " for " + data.getAt(), ex);
|
||||
}
|
||||
|
||||
return point;
|
||||
|
||||
@@ -162,7 +162,7 @@ public abstract class Injector {
|
||||
public final void inject(Target target, List<InjectionNode> nodes) {
|
||||
for (InjectionNode node : nodes) {
|
||||
if (node.isRemoved()) {
|
||||
if (this.info.getContext().getEnvironment().getOption(Option.DEBUG_VERBOSE)) {
|
||||
if (this.info.getContext().getOption(Option.DEBUG_VERBOSE)) {
|
||||
Injector.logger.warn("Target node for {} was removed by a previous injector in {}", this.info, target);
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidSliceException;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
@@ -293,7 +292,7 @@ public class MethodSlice {
|
||||
/**
|
||||
* Owner of this slice
|
||||
*/
|
||||
private final InjectionInfo info;
|
||||
private final ISliceContext owner;
|
||||
|
||||
/**
|
||||
* Slice ID as declared, slice ID in the parent {@link MethodSlices}
|
||||
@@ -321,17 +320,17 @@ public class MethodSlice {
|
||||
/**
|
||||
* ctor
|
||||
*
|
||||
* @param info owner
|
||||
* @param owner owner
|
||||
* @param id declared id
|
||||
* @param from start point, may be null as long as {@link #to} is not null
|
||||
* @param to end point, may be null as long as {@link #from} is not null
|
||||
*/
|
||||
private MethodSlice(InjectionInfo info, String id, InjectionPoint from, InjectionPoint to) {
|
||||
private MethodSlice(ISliceContext owner, String id, InjectionPoint from, InjectionPoint to) {
|
||||
if (from == null && to == null) {
|
||||
throw new InvalidSliceException(info, String.format("%s is redundant. No 'from' or 'to' value specified", this));
|
||||
throw new InvalidSliceException(owner, String.format("%s is redundant. No 'from' or 'to' value specified", this));
|
||||
}
|
||||
|
||||
this.info = info;
|
||||
this.owner = owner;
|
||||
this.id = Strings.nullToEmpty(id);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@@ -357,7 +356,7 @@ public class MethodSlice {
|
||||
int end = this.find(method, this.to, max, this.name + "(to)");
|
||||
|
||||
if (start > end) {
|
||||
throw new InvalidSliceException(this.info, String.format("%s is negative size. Range(%d -> %d)", this.describe(), start, end));
|
||||
throw new InvalidSliceException(this.owner, String.format("%s is negative size. Range(%d -> %d)", this.describe(), start, end));
|
||||
}
|
||||
|
||||
if (start < 0 || end < 0 || start > max || end > max) {
|
||||
@@ -392,7 +391,7 @@ public class MethodSlice {
|
||||
boolean result = injectionPoint.find(method.desc, insns, nodes);
|
||||
Selector select = injectionPoint.getSelector();
|
||||
if (nodes.size() != 1 && select == Selector.ONE) {
|
||||
throw new InvalidSliceException(this.info, String.format("%s requires 1 result but found %d", this.describe(description), nodes.size()));
|
||||
throw new InvalidSliceException(this.owner, String.format("%s requires 1 result but found %d", this.describe(description), nodes.size()));
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
@@ -415,13 +414,13 @@ public class MethodSlice {
|
||||
}
|
||||
|
||||
private String describe(String description) {
|
||||
return MethodSlice.describeSlice(description, this.info);
|
||||
return MethodSlice.describeSlice(description, this.owner);
|
||||
}
|
||||
|
||||
private static String describeSlice(String description, InjectionInfo info) {
|
||||
String annotation = ASMHelper.getSimpleName(info.getAnnotation());
|
||||
MethodNode method = info.getMethod();
|
||||
return String.format("%s->%s(%s)::%s%s", info.getContext(), annotation, description, method.name, method.desc);
|
||||
private static String describeSlice(String description, ISliceContext owner) {
|
||||
String annotation = ASMHelper.getSimpleName(owner.getAnnotation());
|
||||
MethodNode method = owner.getMethod();
|
||||
return String.format("%s->%s(%s)::%s%s", owner.getContext(), annotation, description, method.name, method.desc);
|
||||
}
|
||||
|
||||
private static String getSliceName(String id) {
|
||||
@@ -431,20 +430,20 @@ public class MethodSlice {
|
||||
/**
|
||||
* Parses the supplied annotation into a MethodSlice
|
||||
*
|
||||
* @param info Owner injection info
|
||||
* @param owner Owner injection info
|
||||
* @param slice Annotation to parse
|
||||
* @return parsed MethodSlice
|
||||
*/
|
||||
public static MethodSlice parse(InjectionInfo info, Slice slice) {
|
||||
public static MethodSlice parse(ISliceContext owner, Slice slice) {
|
||||
String id = slice.id();
|
||||
|
||||
At from = slice.from();
|
||||
At to = slice.to();
|
||||
|
||||
InjectionPoint fromPoint = from != null ? InjectionPoint.parse(info, from) : null;
|
||||
InjectionPoint toPoint = to != null ? InjectionPoint.parse(info, to) : null;
|
||||
InjectionPoint fromPoint = from != null ? InjectionPoint.parse(owner, from) : null;
|
||||
InjectionPoint toPoint = to != null ? InjectionPoint.parse(owner, to) : null;
|
||||
|
||||
return new MethodSlice(info, id, fromPoint, toPoint);
|
||||
return new MethodSlice(owner, id, fromPoint, toPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -454,7 +453,7 @@ public class MethodSlice {
|
||||
* @param node Annotation to parse
|
||||
* @return parsed MethodSlice
|
||||
*/
|
||||
public static MethodSlice parse(InjectionInfo info, AnnotationNode node) {
|
||||
public static MethodSlice parse(ISliceContext info, AnnotationNode node) {
|
||||
String id = ASMHelper.<String>getAnnotationValue(node, "id");
|
||||
|
||||
AnnotationNode from = ASMHelper.<AnnotationNode>getAnnotationValue(node, "from");
|
||||
|
||||
+5
-4
@@ -40,7 +40,7 @@ import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
@@ -73,9 +73,9 @@ public class ModifyVariableInjector extends Injector {
|
||||
*/
|
||||
abstract static class ContextualInjectionPoint extends InjectionPoint {
|
||||
|
||||
protected final MixinTargetContext mixin;
|
||||
protected final IMixinContext mixin;
|
||||
|
||||
ContextualInjectionPoint(MixinTargetContext mixin) {
|
||||
ContextualInjectionPoint(IMixinContext mixin) {
|
||||
this.mixin = mixin;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,8 @@ public class ModifyVariableInjector extends Injector {
|
||||
@Override
|
||||
protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
if (injectionPoint instanceof ContextualInjectionPoint) {
|
||||
return ((ContextualInjectionPoint)injectionPoint).find(this.info.getContext().getTargetMethod(into), nodes);
|
||||
Target target = this.info.getContext().getTargetMethod(into);
|
||||
return ((ContextualInjectionPoint)injectionPoint).find(target, nodes);
|
||||
}
|
||||
return injectionPoint.find(into.desc, insns, nodes);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
/**
|
||||
* <p>This injection point searches for the last RETURN opcode in the target
|
||||
@@ -58,7 +58,7 @@ import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
@AtCode("TAIL")
|
||||
public class BeforeFinalReturn extends InjectionPoint {
|
||||
|
||||
private final MixinTargetContext mixin;
|
||||
private final IMixinContext mixin;
|
||||
|
||||
public BeforeFinalReturn(InjectionPointData data) {
|
||||
super(data);
|
||||
|
||||
@@ -48,12 +48,14 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.code.ISliceContext;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.code.InjectorTarget;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlice;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlices;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
@@ -64,7 +66,7 @@ import org.spongepowered.asm.util.ASMHelper;
|
||||
* Contructs information about an injection from an {@link Inject} annotation
|
||||
* and allows the injection to be processed.
|
||||
*/
|
||||
public abstract class InjectionInfo extends SpecialMethodInfo {
|
||||
public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceContext {
|
||||
|
||||
/**
|
||||
* Annotated method is static
|
||||
@@ -438,7 +440,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo {
|
||||
return "handler";
|
||||
}
|
||||
|
||||
static String describeInjector(MixinTargetContext mixin, AnnotationNode annotation, MethodNode method) {
|
||||
static String describeInjector(IMixinContext mixin, AnnotationNode annotation, MethodNode method) {
|
||||
return String.format("%s->@%s::%s%s", mixin.toString(), ASMHelper.getSimpleName(annotation), method.name, method.desc);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector;
|
||||
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionPointException;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
@@ -61,7 +61,7 @@ public class InjectionPointData {
|
||||
/**
|
||||
* Mixin
|
||||
*/
|
||||
private final MixinTargetContext mixin;
|
||||
private final IMixinContext mixin;
|
||||
|
||||
/**
|
||||
* Injector callback
|
||||
@@ -108,7 +108,7 @@ public class InjectionPointData {
|
||||
*/
|
||||
private final int opcode;
|
||||
|
||||
public InjectionPointData(MixinTargetContext mixin, MethodNode method, AnnotationNode parent, String at, List<String> args, String target,
|
||||
public InjectionPointData(IMixinContext mixin, MethodNode method, AnnotationNode parent, String at, List<String> args, String target,
|
||||
String slice, int ordinal, int opcode) {
|
||||
this.mixin = mixin;
|
||||
this.method = method;
|
||||
@@ -158,7 +158,7 @@ public class InjectionPointData {
|
||||
return this.selector;
|
||||
}
|
||||
|
||||
public MixinTargetContext getMixin() {
|
||||
public IMixinContext getMixin() {
|
||||
return this.mixin;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.FieldInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
@@ -541,7 +541,7 @@ public class MemberInfo {
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parseAndValidate(String string, IReferenceMapperContext context) throws InvalidMemberDescriptorException {
|
||||
public static MemberInfo parseAndValidate(String string, IMixinContext context) throws InvalidMemberDescriptorException {
|
||||
return MemberInfo.parse(string, context.getReferenceMapper(), context.getClassRef()).validate();
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ public class MemberInfo {
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parse(String string, IReferenceMapperContext context) {
|
||||
public static MemberInfo parse(String string, IMixinContext context) {
|
||||
return MemberInfo.parse(string, context.getReferenceMapper(), context.getClassRef());
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@
|
||||
package org.spongepowered.asm.mixin.injection.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ public class InvalidInjectionException extends InvalidMixinException {
|
||||
|
||||
private final InjectionInfo info;
|
||||
|
||||
public InvalidInjectionException(IReferenceMapperContext context, String message) {
|
||||
public InvalidInjectionException(IMixinContext context, String message) {
|
||||
super(context, message);
|
||||
this.info = null;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class InvalidInjectionException extends InvalidMixinException {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public InvalidInjectionException(IReferenceMapperContext context, Throwable cause) {
|
||||
public InvalidInjectionException(IMixinContext context, Throwable cause) {
|
||||
super(context, cause);
|
||||
this.info = null;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class InvalidInjectionException extends InvalidMixinException {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public InvalidInjectionException(IReferenceMapperContext context, String message, Throwable cause) {
|
||||
public InvalidInjectionException(IMixinContext context, String message, Throwable cause) {
|
||||
super(context, message, cause);
|
||||
this.info = null;
|
||||
}
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@
|
||||
package org.spongepowered.asm.mixin.injection.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
/**
|
||||
* Thrown when an injection point cannot be parsed due to invalid data
|
||||
@@ -34,7 +34,7 @@ public class InvalidInjectionPointException extends InvalidInjectionException {
|
||||
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
public InvalidInjectionPointException(IReferenceMapperContext context, String format, Object... args) {
|
||||
public InvalidInjectionPointException(IMixinContext context, String format, Object... args) {
|
||||
super(context, String.format(format, args));
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class InvalidInjectionPointException extends InvalidInjectionException {
|
||||
super(info, String.format(format, args));
|
||||
}
|
||||
|
||||
public InvalidInjectionPointException(IReferenceMapperContext context, Throwable cause, String format, Object... args) {
|
||||
public InvalidInjectionPointException(IMixinContext context, Throwable cause, String format, Object... args) {
|
||||
super(context, String.format(format, args), cause);
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -24,8 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.injection.code.ISliceContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
/**
|
||||
* Thrown when an injector slice fails a state check, for example if a slice
|
||||
@@ -35,28 +35,28 @@ public class InvalidSliceException extends InvalidInjectionException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidSliceException(IReferenceMapperContext context, String message) {
|
||||
public InvalidSliceException(IMixinContext context, String message) {
|
||||
super(context, message);
|
||||
}
|
||||
|
||||
public InvalidSliceException(InjectionInfo info, String message) {
|
||||
super(info, message);
|
||||
public InvalidSliceException(ISliceContext owner, String message) {
|
||||
super(owner.getContext(), message);
|
||||
}
|
||||
|
||||
public InvalidSliceException(IReferenceMapperContext context, Throwable cause) {
|
||||
public InvalidSliceException(IMixinContext context, Throwable cause) {
|
||||
super(context, cause);
|
||||
}
|
||||
|
||||
public InvalidSliceException(InjectionInfo info, Throwable cause) {
|
||||
super(info, cause);
|
||||
public InvalidSliceException(ISliceContext owner, Throwable cause) {
|
||||
super(owner.getContext(), cause);
|
||||
}
|
||||
|
||||
public InvalidSliceException(IReferenceMapperContext context, String message, Throwable cause) {
|
||||
public InvalidSliceException(IMixinContext context, String message, Throwable cause) {
|
||||
super(context, message, cause);
|
||||
}
|
||||
|
||||
public InvalidSliceException(InjectionInfo info, String message, Throwable cause) {
|
||||
super(info, message, cause);
|
||||
public InvalidSliceException(ISliceContext owner, String message, Throwable cause) {
|
||||
super(owner.getContext(), message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+10
-1
@@ -24,12 +24,15 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.refmap;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
|
||||
/**
|
||||
* Context for performing reference mapping
|
||||
*/
|
||||
public interface IReferenceMapperContext {
|
||||
public interface IMixinContext {
|
||||
|
||||
/**
|
||||
* Get the mixin info
|
||||
@@ -50,4 +53,10 @@ public interface IReferenceMapperContext {
|
||||
*/
|
||||
public abstract ReferenceMapper getReferenceMapper();
|
||||
|
||||
public abstract boolean getOption(Option option);
|
||||
|
||||
public abstract int getPriority();
|
||||
|
||||
public abstract Target getTargetMethod(MethodNode into);
|
||||
|
||||
}
|
||||
@@ -27,12 +27,14 @@ package org.spongepowered.asm.mixin.struct;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.IInjectionPointContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
/**
|
||||
* Information about a special mixin method such as an injector or accessor
|
||||
*/
|
||||
public abstract class SpecialMethodInfo {
|
||||
public abstract class SpecialMethodInfo implements IInjectionPointContext {
|
||||
|
||||
/**
|
||||
* Annotation on the method
|
||||
@@ -66,7 +68,8 @@ public abstract class SpecialMethodInfo {
|
||||
*
|
||||
* @return the target context
|
||||
*/
|
||||
public final MixinTargetContext getContext() {
|
||||
@Override
|
||||
public final IMixinContext getContext() {
|
||||
return this.mixin;
|
||||
}
|
||||
|
||||
@@ -75,6 +78,7 @@ public abstract class SpecialMethodInfo {
|
||||
*
|
||||
* @return The annotation which this InjectionInfo was created from
|
||||
*/
|
||||
@Override
|
||||
public final AnnotationNode getAnnotation() {
|
||||
return this.annotation;
|
||||
}
|
||||
@@ -93,6 +97,7 @@ public abstract class SpecialMethodInfo {
|
||||
*
|
||||
* @return injector method
|
||||
*/
|
||||
@Override
|
||||
public final MethodNode getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
@@ -55,16 +55,16 @@ import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap.File;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.obfuscation.RemapperChain;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap.File;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
@@ -77,7 +77,7 @@ import org.spongepowered.asm.util.Constants;
|
||||
* context-sensitive operations such as re-targetting method and field accesses
|
||||
* in the mixin to the appropriate members in the target class hierarchy.
|
||||
*/
|
||||
public class MixinTargetContext implements IReferenceMapperContext {
|
||||
public class MixinTargetContext implements IMixinContext {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
@@ -231,6 +231,15 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
public MixinEnvironment getEnvironment() {
|
||||
return this.mixin.getParent().getEnvironment();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.refmap.IMixinContext
|
||||
* #getOption(org.spongepowered.asm.mixin.MixinEnvironment.Option)
|
||||
*/
|
||||
@Override
|
||||
public boolean getOption(Option option) {
|
||||
return this.getEnvironment().getOption(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mixin tree
|
||||
@@ -813,6 +822,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
* @param method method to get a target handle for
|
||||
* @return new or existing target handle for the supplied method
|
||||
*/
|
||||
@Override
|
||||
public Target getTargetMethod(MethodNode method) {
|
||||
return this.targetClass.getTargetMethod(method);
|
||||
}
|
||||
@@ -886,7 +896,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.refmap.IReferenceMapperContext
|
||||
* @see org.spongepowered.asm.mixin.refmap.IMixinContext
|
||||
* #getMixin()
|
||||
*/
|
||||
@Override
|
||||
@@ -906,6 +916,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
*
|
||||
* @return the priority (only meaningful in relation to other mixins)
|
||||
*/
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.mixin.getPriority();
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@
|
||||
package org.spongepowered.asm.mixin.transformer.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
/**
|
||||
* Exception thrown for bad states when parsing/loading interface mixins
|
||||
@@ -38,7 +38,7 @@ public class InvalidInterfaceMixinException extends InvalidMixinException {
|
||||
super(mixin, message);
|
||||
}
|
||||
|
||||
public InvalidInterfaceMixinException(IReferenceMapperContext context, String message) {
|
||||
public InvalidInterfaceMixinException(IMixinContext context, String message) {
|
||||
super(context, message);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class InvalidInterfaceMixinException extends InvalidMixinException {
|
||||
super(mixin, cause);
|
||||
}
|
||||
|
||||
public InvalidInterfaceMixinException(IReferenceMapperContext context, Throwable cause) {
|
||||
public InvalidInterfaceMixinException(IMixinContext context, Throwable cause) {
|
||||
super(context, cause);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class InvalidInterfaceMixinException extends InvalidMixinException {
|
||||
super(mixin, message, cause);
|
||||
}
|
||||
|
||||
public InvalidInterfaceMixinException(IReferenceMapperContext context, String message, Throwable cause) {
|
||||
public InvalidInterfaceMixinException(IMixinContext context, String message, Throwable cause) {
|
||||
super(context, message, cause);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@
|
||||
package org.spongepowered.asm.mixin.transformer.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class InvalidMixinException extends MixinException {
|
||||
this.mixin = mixin;
|
||||
}
|
||||
|
||||
public InvalidMixinException(IReferenceMapperContext context, String message) {
|
||||
public InvalidMixinException(IMixinContext context, String message) {
|
||||
this(context.getMixin(), message);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class InvalidMixinException extends MixinException {
|
||||
this.mixin = mixin;
|
||||
}
|
||||
|
||||
public InvalidMixinException(IReferenceMapperContext context, Throwable cause) {
|
||||
public InvalidMixinException(IMixinContext context, Throwable cause) {
|
||||
this(context.getMixin(), cause);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class InvalidMixinException extends MixinException {
|
||||
this.mixin = mixin;
|
||||
}
|
||||
|
||||
public InvalidMixinException(IReferenceMapperContext context, String message, Throwable cause) {
|
||||
public InvalidMixinException(IMixinContext context, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.mixin = context.getMixin();
|
||||
}
|
||||
|
||||
@@ -414,7 +414,6 @@ public class ASMHelper {
|
||||
* @param annotationClasses Types of annotation to search for
|
||||
* @return the annotation, or null if not present
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static AnnotationNode getSingleVisibleAnnotation(MethodNode method, Class<? extends Annotation>... annotationClasses) {
|
||||
return ASMHelper.getSingleAnnotation(method.visibleAnnotations, annotationClasses);
|
||||
}
|
||||
@@ -427,7 +426,6 @@ public class ASMHelper {
|
||||
* @param annotationClasses Types of annotation to search for
|
||||
* @return the annotation, or null if not present
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static AnnotationNode getSingleInvisibleAnnotation(MethodNode method, Class<? extends Annotation>... annotationClasses) {
|
||||
return ASMHelper.getSingleAnnotation(method.invisibleAnnotations, annotationClasses);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user