diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java b/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java index fb3bd543..00d5abb2 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java @@ -162,19 +162,15 @@ public abstract class InjectionPoint { } /** - * Additional specifier for injection points. Specifiers can be - * supplied in {@link At} annotations by including a colon (:) - * character followed by the specifier type (case-sensitive), eg: + * Selector type for slice delmiters, ignored for normal injection points. + * Selectors can be supplied in {@link At} annotations by including + * a colon (:) character followed by the selector type + * (case-sensitive), eg: * *
@At(value = "INVOKE:LAST", ... )
*/ - public enum Specifier { - - /** - * Use all instructions from the query result. - */ - ALL, - + public enum Selector { + /** * Use the first instruction from the query result. */ @@ -190,13 +186,13 @@ public abstract class InjectionPoint { * more than one instruction this should be considered a fail-fast error * state and a runtime exception will be thrown. */ - ONE, + ONE; /** - * Use the default setting as defined by the consumer. For slices this - * is {@link #FIRST}, for all other consumers this is {@link #ALL} + * Default selector type used if no selector is explicitly specified. + * For internal use only. Currently {@link #FIRST} */ - DEFAULT; + public static final Selector DEFAULT = Selector.FIRST; } @@ -280,26 +276,26 @@ public abstract class InjectionPoint { } private final String slice; - private final Specifier specifier; + private final Selector selector; private final String id; private final IMessageSink messageSink; protected InjectionPoint() { - this("", Specifier.DEFAULT, null); + this("", Selector.DEFAULT, null); } protected InjectionPoint(InjectionPointData data) { - this(data.getSlice(), data.getSpecifier(), data.getId(), data.getMessageSink()); + this(data.getSlice(), data.getSelector(), data.getId(), data.getMessageSink()); } - public InjectionPoint(String slice, Specifier specifier, String id) { - this(slice, specifier, id, null); + public InjectionPoint(String slice, Selector selector, String id) { + this(slice, selector, id, null); } - public InjectionPoint(String slice, Specifier specifier, String id, IMessageSink messageSink) { + public InjectionPoint(String slice, Selector selector, String id, IMessageSink messageSink) { this.slice = slice; - this.specifier = specifier; + this.selector = selector; this.id = id; this.messageSink = messageSink; } @@ -308,8 +304,8 @@ public abstract class InjectionPoint { return this.slice; } - public Specifier getSpecifier(Specifier defaultSpecifier) { - return this.specifier == Specifier.DEFAULT ? defaultSpecifier : this.specifier; + public Selector getSelector() { + return this.selector; } public String getId() { diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java b/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java index 68689107..857432db 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java @@ -28,7 +28,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier; +import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector; /** * A Slice identifies a section of a method to search for injection @@ -162,10 +162,10 @@ public @interface Slice { /** * Injection point which specifies the start of the slice region. - * {@link At}s supplied here should generally use a {@link Specifier} + * {@link At}s supplied here should generally specify a {@link Selector} * in order to identify which instruction should be used for queries which - * return multiple results. The specifier is supplied by appending the - * specifier type to the injection point type as follows: + * return multiple results. The selector is specified by appending the + * selector type to the injection point type as follows: * *
@At(value = "INVOKE:LAST", ... )
* @@ -182,9 +182,9 @@ public @interface Slice { /** * Injection point which specifies the end of the slice region. * Like {@link #from}, {@link At}s supplied here should generally specify a - * {@link Specifier} in order to identify which instruction should be used - * for queries which return multiple results. The specifier is supplied by - * appending the specifier type to the injection point type as follows: + * {@link Selector} in order to identify which instruction should be used + * for queries which return multiple results. The selector is specified by + * appending the selector type to the injection point type as follows: * *
@At(value = "INVOKE:LAST", ... )
* diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java index b7b55ff3..c37a3d56 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java @@ -42,7 +42,6 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.InjectionPoint; import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel; -import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier; import org.spongepowered.asm.mixin.injection.invoke.RedirectInjector; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode; @@ -295,7 +294,7 @@ public abstract class Injector { IMixinContext mixin = this.info.getMixin(); MethodNode method = injectorTarget.getMethod(); Map targetNodes = new TreeMap(); - List nodes = new ArrayList(32); + Collection nodes = new ArrayList(32); for (InjectionPoint injectionPoint : injectionPoints) { nodes.clear(); @@ -308,20 +307,15 @@ public abstract class Injector { injectorTarget, injectorTarget.getMergedBy(), injectorTarget.getMergedPriority())); } - if (!this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) { - continue; - } - - Specifier specifier = injectionPoint.getSpecifier(Specifier.ALL); - if (specifier == Specifier.ONE && nodes.size() != 1) { - throw new InvalidInjectionException(this.info, String.format("%s on %s has specifier :ONE but matched %d instructions", - injectionPoint, this, nodes.size())); - } else if (specifier != Specifier.ALL && nodes.size() > 1) { - AbstractInsnNode specified = nodes.get(specifier == Specifier.FIRST ? 0 : nodes.size() - 1); - this.addTargetNode(method, targetNodes, injectionPoint, specified); - } else { + if (this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) { for (AbstractInsnNode insn : nodes) { - this.addTargetNode(method, targetNodes, injectionPoint, insn); + Integer key = method.instructions.indexOf(insn); + TargetNode targetNode = targetNodes.get(key); + if (targetNode == null) { + targetNode = new TargetNode(insn); + targetNodes.put(key, targetNode); + } + targetNode.nominators.add(injectionPoint); } } } @@ -329,16 +323,6 @@ public abstract class Injector { return targetNodes.values(); } - protected void addTargetNode(MethodNode method, Map targetNodes, InjectionPoint injectionPoint, AbstractInsnNode insn) { - Integer key = method.instructions.indexOf(insn); - TargetNode targetNode = targetNodes.get(key); - if (targetNode == null) { - targetNode = new TargetNode(insn); - targetNodes.put(key, targetNode); - } - targetNode.nominators.add(injectionPoint); - } - protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget, Collection nodes) { return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes); diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlice.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlice.java index 58201c05..79891e95 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlice.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlice.java @@ -37,7 +37,7 @@ import org.objectweb.asm.tree.MethodNode; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier; +import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.struct.InjectionPointAnnotationContext; import org.spongepowered.asm.mixin.injection.throwables.InjectionError; @@ -325,11 +325,6 @@ public final class MethodSlice { * Descriptive name of the slice, used in exceptions */ private final String name; - - /** - * Success counts for from and to injection points - */ - private int successCountFrom, successCountTo; /** * ctor @@ -366,8 +361,8 @@ public final class MethodSlice { */ public InsnListReadOnly getSlice(MethodNode method) { int max = method.instructions.size() - 1; - int start = this.find(method, this.from, 0, 0, "from"); - int end = this.find(method, this.to, max, start, "to"); + int start = this.find(method, this.from, 0, 0, this.name + "(from)"); + int end = this.find(method, this.to, max, start, this.name + "(to)"); if (start > end) { throw new InvalidSliceException(this.owner, String.format("%s is negative size. Range(%d -> %d)", this.describe(), start, end)); @@ -394,53 +389,32 @@ public final class MethodSlice { * @param defaultValue Value to return if injection point is null (open * ended) * @param failValue Value to use if query fails - * @param argument The name of the argument ("from" or "to") for debug msgs + * @param description Description for error message * @return matching insn index */ - private int find(MethodNode method, InjectionPoint injectionPoint, int defaultValue, int failValue, String argument) { + private int find(MethodNode method, InjectionPoint injectionPoint, int defaultValue, int failValue, String description) { if (injectionPoint == null) { return defaultValue; } - String description = String.format("%s(%s)", this.name, argument); Deque nodes = new LinkedList(); InsnListReadOnly insns = new InsnListReadOnly(method.instructions); boolean result = injectionPoint.find(method.desc, insns, nodes); - Specifier specifier = injectionPoint.getSpecifier(Specifier.FIRST); - if (specifier == Specifier.ALL) { - throw new InvalidSliceException(this.owner, String.format("ALL is not a valid specifier for slice %s", this.describe(description))); - } - if (nodes.size() != 1 && specifier == Specifier.ONE) { + Selector select = injectionPoint.getSelector(); + if (nodes.size() != 1 && select == Selector.ONE) { throw new InvalidSliceException(this.owner, String.format("%s requires 1 result but found %d", this.describe(description), nodes.size())); } if (!result) { + if (this.owner.getMixin().getOption(Option.DEBUG_VERBOSE)) { + MethodSlice.logger.warn("{} did not match any instructions", this.describe(description)); + } return failValue; } - if ("from".equals(argument)) { - this.successCountFrom++; - } else { - this.successCountTo++; - } - - return method.instructions.indexOf(specifier == Specifier.FIRST ? nodes.getFirst() : nodes.getLast()); + return method.instructions.indexOf(select == Selector.FIRST ? nodes.getFirst() : nodes.getLast()); } - - /** - * Perform post-injection debugging and validation tasks - */ - public void postInject() { - if (this.owner.getMixin().getOption(Option.DEBUG_VERBOSE)) { - if (this.from != null && this.successCountFrom == 0) { - MethodSlice.logger.warn("{} did not match any instructions", this.describe(this.name + "(from)")); - } - if (this.to != null && this.successCountTo == 0) { - MethodSlice.logger.warn("{} did not match any instructions", this.describe(this.name + "(to)")); - } - } - } - + /* (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlices.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlices.java index 0789b762..fb9979aa 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlices.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/MethodSlices.java @@ -82,16 +82,6 @@ public final class MethodSlices { return this.slices.get(id); } - /** - * Called to do post-injection validation/debug logging for slices - */ - public void postInject() { - for (MethodSlice slice : this.slices.values()) { - slice.postInject(); - } - } - - /* (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeConstant.java b/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeConstant.java index bbad13ed..e8030562 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeConstant.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeConstant.java @@ -147,7 +147,7 @@ public class BeforeConstant extends InjectionPoint { private final boolean log; public BeforeConstant(IMixinContext context, AnnotationNode node, String returnType) { - super(Annotations.getValue(node, "slice", ""), Specifier.DEFAULT, null); + super(Annotations.getValue(node, "slice", ""), Selector.DEFAULT, null); Boolean empty = Annotations.getValue(node, "nullValue", (Boolean)null); this.ordinal = Annotations.getValue(node, "ordinal", Integer.valueOf(-1)); diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java index bf6be2c5..bb686fb5 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java @@ -473,8 +473,6 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC String.format("Critical injection failure: %s %s%s in %s failed injection check, %d succeeded of %d allowed.%s", description, this.methodName, this.method.desc, this.mixin, this.injectedCallbackCount, this.maxCallbackCount, extraInfo)); } - - this.slices.postInject(); } /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java index b41cdd7c..cb4290a9 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java @@ -36,7 +36,7 @@ import org.objectweb.asm.tree.MethodNode; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.IInjectionPointContext; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier; +import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector; import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator; import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector; import org.spongepowered.asm.mixin.injection.selectors.InvalidSelectorException; @@ -86,7 +86,7 @@ public class InjectionPointData { /** * Selector parsed from the at argument, only used by slices */ - private final Specifier specifier; + private final Selector selector; /** * Target @@ -131,7 +131,7 @@ public class InjectionPointData { Matcher matcher = InjectionPointData.AT_PATTERN.matcher(at); this.type = InjectionPointData.parseType(matcher, at); - this.specifier = InjectionPointData.parseSpecifier(matcher); + this.selector = InjectionPointData.parseSelector(matcher); } private void parseArgs(List args) { @@ -172,10 +172,10 @@ public class InjectionPointData { } /** - * Get the specifier value parsed from the injector + * Get the selector value parsed from the injector */ - public Specifier getSpecifier() { - return this.specifier; + public Selector getSelector() { + return this.selector; } /** @@ -362,7 +362,7 @@ public class InjectionPointData { } private static Pattern createPattern() { - return Pattern.compile(String.format("^(.+?)(:(%s))?$", Joiner.on('|').join(Specifier.values()))); + return Pattern.compile(String.format("^(.+?)(:(%s))?$", Joiner.on('|').join(Selector.values()))); } /** @@ -380,8 +380,8 @@ public class InjectionPointData { return matcher.matches() ? matcher.group(1) : at; } - private static Specifier parseSpecifier(Matcher matcher) { - return matcher.matches() && matcher.group(3) != null ? Specifier.valueOf(matcher.group(3)) : Specifier.DEFAULT; + private static Selector parseSelector(Matcher matcher) { + return matcher.matches() && matcher.group(3) != null ? Selector.valueOf(matcher.group(3)) : Selector.DEFAULT; } private static int parseInt(String string, int defaultValue) {