Note that like other redirectors, it is possible to capture the target
* method's arguments by appending them to the handler method's signature:
*
* Note that this results in the injected code being less efficient, because
* the instanceof opcode is replaced with discrete code similar to
- * reference != null && yourClass.isAssignableFrom(reference.getClass()) in
- * the target method body.
+ * reference != null && yourClass.isAssignableFrom(reference.getClass())
+ * in the target method body.
*
* class Foo : Bar {
* Foo(int arg) {
- * super(Foo.isEven(arg));
+ * super(Foo.isEven(arg));
* }
*
* static int isEven(int arg) {
@@ -326,7 +326,15 @@ public @interface Redirect {
*
* @return target method(s) for this injector
*/
- public String[] method();
+ public String[] method() default {};
+
+ /**
+ * Literal representation of one or more {@link Desc @Desc} annotations
+ * which identify the target methods.
+ *
+ * @return target method(s) for this injector as descriptors
+ */
+ public Desc[] target() default {};
/**
* A {@link Slice} annotation which describes the method bisection used in
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 769b1555..857432db 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/Slice.java
@@ -85,7 +85,7 @@ import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector;
* thing.processStuff();
* }
*
- * // A new call to processStuff, which now has the ordinal 1
+ * // A new call to processStuff, which now has the ordinal 1
* bar.getActiveThing().processStuff();
*
* Thing specialThing = bar.getSpecialThing();
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java
index 5009a231..79188adf 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java
@@ -34,13 +34,14 @@ import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import org.spongepowered.asm.mixin.injection.Coerce;
+import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.Surrogate;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.injection.struct.Target.Extension;
-import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.util.Annotations;
@@ -53,7 +54,8 @@ import org.spongepowered.asm.util.SignaturePrinter;
import com.google.common.base.Strings;
/**
- * This class is responsible for generating the bytecode for injected callbacks
+ * This class is responsible for generating the bytecode for injected callbacks,
+ * for details of usage see {@link Inject @Inject}.
*/
public class CallbackInjector extends Injector {
@@ -343,6 +345,11 @@ public class CallbackInjector extends Injector {
}
+ /**
+ * Decorator key for local variables decoration
+ */
+ private static final String LOCALS_KEY = "locals";
+
/**
* True if cancellable
*/
@@ -444,6 +451,19 @@ public class CallbackInjector extends Injector {
myNodes.add(injectionNode);
this.totalInjections++;
}
+
+ @Override
+ protected void preInject(Target target, InjectionNode node) {
+ if (this.localCapture.isCaptureLocals() || this.localCapture.isPrintLocals()) {
+ LocalVariableNode[] locals = Locals.getLocalsAt(this.classNode, target.method, node.getCurrentTarget());
+ for (int j = 0; j < locals.length; j++) {
+ if (locals[j] != null && locals[j].desc != null && locals[j].desc.startsWith("Lorg/spongepowered/asm/mixin/injection/callback/")) {
+ locals[j] = null;
+ }
+ }
+ node.decorate(CallbackInjector.LOCALS_KEY, locals);
+ }
+ }
/* (non-Javadoc)
* @see org.spongepowered.asm.mixin.injection.callback.BytecodeInjector
@@ -452,17 +472,7 @@ public class CallbackInjector extends Injector {
*/
@Override
protected void inject(Target target, InjectionNode node) {
- LocalVariableNode[] locals = null;
-
- if (this.localCapture.isCaptureLocals() || this.localCapture.isPrintLocals()) {
- locals = Locals.getLocalsAt(this.classNode, target.method, node.getCurrentTarget());
- for (int j = 0; j < locals.length; j++) {
- if (locals[j] != null && locals[j].desc != null && locals[j].desc.startsWith("Lorg/spongepowered/asm/mixin/injection/callback/")) {
- locals[j] = null;
- }
- }
- }
-
+ LocalVariableNode[] locals = node.getDecoration(CallbackInjector.LOCALS_KEY);
this.inject(new Callback(this.methodNode, target, node, locals, this.localCapture.isCaptureLocals()));
}
@@ -484,7 +494,7 @@ public class CallbackInjector extends Injector {
MethodNode callbackMethod = this.methodNode;
if (!callback.checkDescriptor(this.methodNode.desc)) {
- if (this.info.getTargets().size() > 1) {
+ if (this.info.getTargetCount() > 1) {
return; // Look for a match in other targets before failing
}
@@ -560,13 +570,15 @@ public class CallbackInjector extends Injector {
*/
private String generateBadLVTMessage(final Callback callback) {
int position = callback.target.indexOf(callback.node);
- List expected = CallbackInjector.summariseLocals(this.methodNode.desc, callback.target.arguments.length + 1);
- List found = CallbackInjector.summariseLocals(callback.getDescriptor(), callback.frameSize + (callback.target.isStatic ? 1 : 0));
+ int targetArgc = callback.target.arguments.length + 1;
+ List expected = CallbackInjector.summariseLocals(this.methodNode.desc, targetArgc, 255);
+ List found = CallbackInjector.summariseLocals(callback.getDescriptorWithAllLocals(), targetArgc, expected.size());
if (expected.equals(found)) {
return String.format("Invalid descriptor on %s! Expected %s but found %s", this.info, callback.getDescriptor(), this.methodNode.desc);
}
- return String.format("LVT in %s has incompatible changes at opcode %d in callback %s.\nExpected: %s\n Found: %s",
- callback.target, position, this, expected, found);
+ List available = CallbackInjector.summariseLocals(callback.getDescriptorWithAllLocals(), targetArgc, 255);
+ return String.format("LVT in %s has incompatible changes at opcode %d in callback %s.\n Expected: %s\n Found: %s\nAvailable: %s",
+ callback.target, position, this.info, expected, found, available);
}
/**
@@ -816,14 +828,14 @@ public class CallbackInjector extends Injector {
return this.isStatic;
}
- private static List summariseLocals(String desc, int pos) {
- return CallbackInjector.summariseLocals(Type.getArgumentTypes(desc), pos);
+ private static List summariseLocals(String desc, int pos, int count) {
+ return CallbackInjector.summariseLocals(Type.getArgumentTypes(desc), pos, count);
}
- private static List summariseLocals(Type[] locals, int pos) {
+ private static List summariseLocals(Type[] locals, int pos, int count) {
List list = new ArrayList();
if (locals != null) {
- for (; pos < locals.length; pos++) {
+ for (; pos < locals.length && list.size() < count; pos++) {
if (locals[pos] != null) {
list.add(locals[pos].toString());
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/callback/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/callback/package-info.java
new file mode 100644
index 00000000..39952e3a
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/callback/package-info.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Implementation of callback injector functionality provided by
+ * {@link org.spongepowered.asm.mixin.injection.Inject @#64;Inject}.
+ */
+package org.spongepowered.asm.mixin.injection.callback;
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 d985037a..9f7b07c7 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
@@ -247,6 +247,18 @@ public abstract class Injector {
myNodes.add(target.addInjectionNode(node));
}
+ /**
+ * Performs pre-injection checks and tasks on the specified target
+ *
+ * @param target target potentially being injected into
+ * @param nodes selected target nodes
+ */
+ public final void preInject(Target target, List nodes) {
+ for (InjectionNode node : nodes) {
+ this.preInject(target, node);
+ }
+ }
+
/**
* Performs the injection on the specified target
*
@@ -256,7 +268,7 @@ public abstract class Injector {
public final void inject(Target target, List nodes) {
for (InjectionNode node : nodes) {
if (node.isRemoved()) {
- if (this.info.getContext().getOption(Option.DEBUG_VERBOSE)) {
+ if (this.info.getMixin().getOption(Option.DEBUG_VERBOSE)) {
Injector.logger.warn("Target node for {} was removed by a previous injector in {}", this.info, target);
}
continue;
@@ -279,7 +291,7 @@ public abstract class Injector {
* @return Target insn nodes in the target method
*/
private Collection findTargetNodes(InjectorTarget injectorTarget, List injectionPoints) {
- IMixinContext mixin = this.info.getContext();
+ IMixinContext mixin = this.info.getMixin();
MethodNode method = injectorTarget.getMethod();
Map targetNodes = new TreeMap();
Collection nodes = new ArrayList(32);
@@ -295,7 +307,7 @@ public abstract class Injector {
injectorTarget, injectorTarget.getMergedBy(), injectorTarget.getMergedPriority()));
}
- if (this.findTargetNodes(method, injectionPoint, injectorTarget.getSlice(injectionPoint), nodes)) {
+ if (this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) {
for (AbstractInsnNode insn : nodes) {
Integer key = method.instructions.indexOf(insn);
TargetNode targetNode = targetNodes.get(key);
@@ -311,8 +323,9 @@ public abstract class Injector {
return targetNodes.values();
}
- protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InsnList insns, Collection nodes) {
- return injectionPoint.find(into.desc, insns, nodes);
+ protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget,
+ Collection nodes) {
+ return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes);
}
protected void sanityCheck(Target target, List injectionPoints) {
@@ -380,6 +393,10 @@ public abstract class Injector {
this.checkTargetModifiers(target, true);
}
+ protected void preInject(Target target, InjectionNode node) {
+ // stub
+ }
+
protected abstract void inject(Target target, InjectionNode node);
protected void postInject(Target target, InjectionNode node) {
@@ -439,7 +456,7 @@ public abstract class Injector {
this.pushArgs(args, insns, argMap, startArg, endArg);
return this.invokeHandler(insns);
}
-
+
/**
* Store args on the stack starting at the end and working back to position
* specified by start, return the generated argMap
@@ -451,8 +468,24 @@ public abstract class Injector {
* @return the generated argmap
*/
protected int[] storeArgs(Target target, Type[] args, InsnList insns, int start) {
+ return this.storeArgs(target, args, insns, start, null, null);
+ }
+
+ /**
+ * Store args on the stack starting at the end and working back to position
+ * specified by start, return the generated argMap
+ *
+ * @param target target method
+ * @param args argument types
+ * @param insns instruction list to generate insns into
+ * @param start Starting index
+ * @param from The label marking the start of the region for the locals
+ * @param to The label marking the end of the region for the stored locals
+ * @return the generated argmap
+ */
+ protected int[] storeArgs(Target target, Type[] args, InsnList insns, int start, LabelNode from, LabelNode to) {
int[] argMap = target.generateArgMap(args, start);
- this.storeArgs(args, insns, argMap, start, args.length);
+ this.storeArgs(target, args, insns, argMap, start, args.length, from, to);
return argMap;
}
@@ -465,9 +498,25 @@ public abstract class Injector {
* @param start Starting index
* @param end Ending index
*/
- protected void storeArgs(Type[] args, InsnList insns, int[] argMap, int start, int end) {
+ protected void storeArgs(Target target, Type[] args, InsnList insns, int[] argMap, int start, int end) {
+ this.storeArgs(target, args, insns, argMap, start, end, null, null);
+ }
+
+ /**
+ * Store args on the stack to their positions allocated based on argMap
+ *
+ * @param args argument types
+ * @param insns instruction list to generate insns into
+ * @param argMap generated argmap containing local indices for all args
+ * @param start Starting index
+ * @param end Ending index
+ * @param from The label marking the start of the region for the locals
+ * @param to The label marking the end of the region for the stored locals
+ */
+ protected void storeArgs(Target target, Type[] args, InsnList insns, int[] argMap, int start, int end, LabelNode from, LabelNode to) {
for (int arg = end - 1; arg >= start; arg--) {
insns.add(new VarInsnNode(args[arg].getOpcode(Opcodes.ISTORE), argMap[arg]));
+ target.addLocalVariable(argMap[arg], String.format("injectorAllocatedLocal%d", argMap[arg]), args[arg].getDescriptor(), from, to);
}
}
@@ -522,7 +571,7 @@ public abstract class Injector {
* @param args Array of handler args, must not be null
*/
protected final void validateParams(InjectorData injector, Type returnType, Type... args) {
- String description = String.format("%s %s method %s from %s", this.annotationType, injector, this, this.info.getContext());
+ String description = String.format("%s %s method %s from %s", this.annotationType, injector, this, this.info.getMixin());
int argIndex = 0;
try {
injector.coerceReturnType = this.checkCoerce(-1, returnType, description, injector.allowCoerceArgs);
@@ -574,12 +623,13 @@ public abstract class Injector {
* if coercion is required for the argument
*/
protected final boolean checkCoerce(int index, Type toType, String description, boolean allowCoercion) {
- Type fromType = index < 0 ? this.returnType : this.methodArgs[index];
if (index >= this.methodArgs.length) {
throw new InvalidInjectionException(this.info, String.format(
"%s has an invalid signature. Not enough arguments: expected argument type %s at index %d",
description, SignaturePrinter.getTypeName(toType), index));
}
+
+ Type fromType = index < 0 ? this.returnType : this.methodArgs[index];
AnnotationNode coerce = Annotations.getInvisibleParameter(this.methodNode, Coerce.class, index);
boolean isReturn = index < 0;
@@ -587,7 +637,7 @@ public abstract class Injector {
Object argIndex = isReturn ? "" : " at index " + index;
if (fromType.equals(toType)) {
- if (coerce != null && this.info.getContext().getOption(Option.DEBUG_VERBOSE)) {
+ if (coerce != null && this.info.getMixin().getOption(Option.DEBUG_VERBOSE)) {
Injector.logger.info("Possibly-redundant @Coerce on {} {} type{}, {} is identical to {}", description, argType, argIndex,
SignaturePrinter.getTypeName(toType), SignaturePrinter.getTypeName(fromType));
}
@@ -619,12 +669,13 @@ public abstract class Injector {
* @param exceptionType Type of exception to throw (binary name)
* @param message Message to pass to the exception constructor
*/
- protected void throwException(InsnList insns, String exceptionType, String message) {
+ protected void throwException(InsnList insns, Extension extraStack, String exceptionType, String message) {
insns.add(new TypeInsnNode(Opcodes.NEW, exceptionType));
insns.add(new InsnNode(Opcodes.DUP));
insns.add(new LdcInsnNode(message));
insns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, exceptionType, "", "(Ljava/lang/String;)V", false));
insns.add(new InsnNode(Opcodes.ATHROW));
+ extraStack.add(3);
}
/**
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/InjectorTarget.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/InjectorTarget.java
index 23c053c7..9347f3a7 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/code/InjectorTarget.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/InjectorTarget.java
@@ -32,6 +32,7 @@ import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
+import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
import org.spongepowered.asm.util.Annotations;
@@ -50,15 +51,26 @@ public class InjectorTarget {
/**
* Cache of slices
*/
- private final Map cache = new HashMap();
+ private final Map cache = new HashMap();
/**
* Target method data
*/
private final Target target;
+ /**
+ * Selector which selected this method
+ */
+ private final ITargetSelector selector;
+
+ /**
+ * Name of the mixin which merged the target, if any
+ */
private final String mergedBy;
+ /**
+ * Priority of the mixin which merged the target, if any
+ */
private final int mergedPriority;
/**
@@ -67,9 +79,10 @@ public class InjectorTarget {
* @param context owner
* @param target target
*/
- public InjectorTarget(ISliceContext context, Target target) {
+ public InjectorTarget(ISliceContext context, Target target, ITargetSelector selector) {
this.context = context;
this.target = target;
+ this.selector = selector;
AnnotationNode merged = Annotations.getVisible(target.method, MixinMerged.class);
this.mergedBy = Annotations.getValue(merged, "mixin");
@@ -95,6 +108,13 @@ public class InjectorTarget {
return this.target.method;
}
+ /**
+ * Get the selector which selected this target
+ */
+ public ITargetSelector getSelector() {
+ return this.selector;
+ }
+
/**
* Get whether this target method was merged by another mixin
*/
@@ -125,14 +145,14 @@ public class InjectorTarget {
* @return insn slice
*/
public InsnList getSlice(String id) {
- ReadOnlyInsnList slice = this.cache.get(id);
+ InsnListReadOnly slice = this.cache.get(id);
if (slice == null) {
MethodSlice sliceInfo = this.context.getSlice(id);
if (sliceInfo != null) {
slice = sliceInfo.getSlice(this.target.method);
} else {
// No slice exists so just wrap the method insns
- slice = new ReadOnlyInsnList(this.target.method.instructions);
+ slice = new InsnListReadOnly(this.target.method.instructions);
}
this.cache.put(id, slice);
}
@@ -154,7 +174,7 @@ public class InjectorTarget {
* Dispose all cached instruction lists
*/
public void dispose() {
- for (ReadOnlyInsnList insns : this.cache.values()) {
+ for (InsnListReadOnly insns : this.cache.values()) {
insns.dispose();
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/ReadOnlyInsnList.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java
similarity index 98%
rename from src/main/java/org/spongepowered/asm/mixin/injection/code/ReadOnlyInsnList.java
rename to src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java
index 528ebac6..70c86574 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/code/ReadOnlyInsnList.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/InsnListReadOnly.java
@@ -34,11 +34,11 @@ import org.objectweb.asm.tree.InsnList;
* instances so that custom InjectionPoint implementations cannot modify the
* insn list whilst inspecting it.
*/
-class ReadOnlyInsnList extends InsnList {
+class InsnListReadOnly extends InsnList {
private InsnList insnList;
- public ReadOnlyInsnList(InsnList insns) {
+ public InsnListReadOnly(InsnList insns) {
this.insnList = insns;
}
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 85ac3af6..77b28703 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
@@ -40,9 +40,9 @@ 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.InjectionPointAnnotationContext;
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
import org.spongepowered.asm.mixin.injection.throwables.InvalidSliceException;
-import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Annotations;
import com.google.common.base.Strings;
@@ -57,7 +57,7 @@ public final class MethodSlice {
* identified by start and end to be accessed. In essence
* this class provides a view of the underlying InsnList.
*/
- static final class InsnListSlice extends ReadOnlyInsnList {
+ static final class InsnListSlice extends InsnListReadOnly {
/**
* ListIterator for the slice view, wraps an iterator returned by the
@@ -359,7 +359,7 @@ public final class MethodSlice {
* @param method method to slice
* @return read only slice
*/
- public ReadOnlyInsnList getSlice(MethodNode method) {
+ public InsnListReadOnly getSlice(MethodNode method) {
int max = method.instructions.size() - 1;
int start = this.find(method, this.from, 0, 0, this.name + "(from)");
int end = this.find(method, this.to, max, start, this.name + "(to)");
@@ -373,7 +373,7 @@ public final class MethodSlice {
}
if (start == 0 && end == max) {
- return new ReadOnlyInsnList(method.instructions);
+ return new InsnListReadOnly(method.instructions);
}
return new InsnListSlice(method.instructions, start, end);
@@ -398,7 +398,7 @@ public final class MethodSlice {
}
Deque nodes = new LinkedList();
- ReadOnlyInsnList insns = new ReadOnlyInsnList(method.instructions);
+ InsnListReadOnly insns = new InsnListReadOnly(method.instructions);
boolean result = injectionPoint.find(method.desc, insns, nodes);
Selector select = injectionPoint.getSelector();
if (nodes.size() != 1 && select == Selector.ONE) {
@@ -406,7 +406,7 @@ public final class MethodSlice {
}
if (!result) {
- if (this.owner.getContext().getOption(Option.DEBUG_VERBOSE)) {
+ if (this.owner.getMixin().getOption(Option.DEBUG_VERBOSE)) {
MethodSlice.logger.warn("{} did not match any instructions", this.describe(description));
}
return failValue;
@@ -432,9 +432,9 @@ public final class MethodSlice {
}
private static String describeSlice(String description, ISliceContext owner) {
- String annotation = Bytecode.getSimpleName(owner.getAnnotation());
+ String annotation = Annotations.getSimpleName(owner.getAnnotationNode());
MethodNode method = owner.getMethod();
- return String.format("%s->%s(%s)::%s%s", owner.getContext(), annotation, description, method.name, method.desc);
+ return String.format("%s->%s(%s)::%s%s", owner.getMixin(), annotation, description, method.name, method.desc);
}
private static String getSliceName(String id) {
@@ -469,12 +469,17 @@ public final class MethodSlice {
*/
public static MethodSlice parse(ISliceContext info, AnnotationNode node) {
String id = Annotations.getValue(node, "id");
+ String coord = "slice";
+ if (!Strings.isNullOrEmpty(id)) {
+ coord += "." + id;
+ }
+ InjectionPointAnnotationContext sliceContext = new InjectionPointAnnotationContext(info, node, coord);
AnnotationNode from = Annotations.getValue(node, "from");
AnnotationNode to = Annotations.getValue(node, "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(new InjectionPointAnnotationContext(sliceContext, from, "from"), from) : null;
+ InjectionPoint toPoint = to != null ? InjectionPoint.parse(new InjectionPointAnnotationContext(sliceContext, to, "to"), to) : null;
return new MethodSlice(info, id, fromPoint, toPoint);
}
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 3681ed5a..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
@@ -99,7 +99,7 @@ public final class MethodSlices {
public static MethodSlices parse(InjectionInfo info) {
MethodSlices slices = new MethodSlices(info);
- AnnotationNode annotation = info.getAnnotation();
+ AnnotationNode annotation = info.getAnnotationNode();
if (annotation != null) {
for (AnnotationNode node : Annotations.getValue(annotation, "slice", true)) {
MethodSlice slice = MethodSlice.parse(info, node);
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/package-info.java
new file mode 100644
index 00000000..1a505452
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Common base classes for injector implementations.
+ */
+package org.spongepowered.asm.mixin.injection.code;
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java
index 95a046b9..30a29cee 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java
@@ -32,16 +32,17 @@ import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.injection.struct.Target.Extension;
-import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.util.Bytecode;
/**
* A bytecode injector which allows a single argument of a chosen method call to
- * be altered.
+ * be altered. For details see javadoc for {@link ModifyArg @ModifyArg}.
*/
public class ModifyArgInjector extends InvokeInjector {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgsInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgsInjector.java
index b722d806..051831a0 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgsInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgsInjector.java
@@ -31,17 +31,18 @@ import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
+import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.ArgsClassGenerator;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.injection.struct.Target.Extension;
-import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.util.Bytecode;
/**
* A bytecode injector which allows a single argument of a chosen method call to
- * be altered.
+ * be altered. For details see javadoc for {@link ModifyArgs @ModifyArgs}.
*/
public class ModifyArgsInjector extends InvokeInjector {
@@ -53,7 +54,7 @@ public class ModifyArgsInjector extends InvokeInjector {
public ModifyArgsInjector(InjectionInfo info) {
super(info, "@ModifyArgs");
- this.argsClassGenerator = info.getContext().getExtensions().getGenerator(ArgsClassGenerator.class);
+ this.argsClassGenerator = info.getMixin().getExtensions().getGenerator(ArgsClassGenerator.class);
}
/* (non-Javadoc)
@@ -84,7 +85,7 @@ public class ModifyArgsInjector extends InvokeInjector {
+ targetMethod.name + targetMethod.desc + " with no arguments!");
}
- String clArgs = this.argsClassGenerator.getArgsClass(targetMethod.desc, this.info.getContext().getMixin()).getName();
+ String clArgs = this.argsClassGenerator.getArgsClass(targetMethod.desc, this.info.getMixin().getMixin()).getName();
boolean withArgs = this.verifyTarget(target);
InsnList insns = new InsnList();
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java
index 3f60bb30..3ef551e6 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java
@@ -36,6 +36,7 @@ import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
+import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.invoke.util.InsnFinder;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
@@ -49,7 +50,8 @@ import org.spongepowered.asm.util.SignaturePrinter;
/**
* A bytecode injector which allows a specific constant value to be identified
- * and replaced with a callback
+ * and replaced with a callback. For details see javadoc for
+ * {@link ModifyConstant @ModifyConstant}.
*/
public class ModifyConstantInjector extends RedirectInjector {
@@ -133,7 +135,7 @@ public class ModifyConstantInjector extends RedirectInjector {
private void injectConstantModifier(Target target, AbstractInsnNode constNode) {
final Type constantType = Bytecode.getConstantType(constNode);
- if (constantType.getSort() <= Type.INT && this.info.getContext().getOption(Option.DEBUG_VERBOSE)) {
+ if (constantType.getSort() <= Type.INT && this.info.getMixin().getOption(Option.DEBUG_VERBOSE)) {
this.checkNarrowing(target, constNode, constantType);
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java
index a8aa0f47..3a5b5fc7 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java
@@ -58,14 +58,17 @@ import com.google.common.primitives.Ints;
* method. For method redirects, the handler method signature must match the
* hooked method precisely but prepended with an arg of the owning
* object's type to accept the object instance the method was going to be
- * invoked upon. For example when hooking the following call:
+ * invoked upon. For more details see the javadoc for the {@link Redirect
+ * @Redirect} annotation.
+ *
+ * For example when hooking the following call:
*
*
* int abc = 0;
* int def = 1;
* Foo someObject = new Foo();
*
- * // Hooking this method
+ * // Hooking this method
* boolean xyz = someObject.bar(abc, def);
*
*
@@ -79,8 +82,8 @@ import com.google.common.primitives.Ints;
* methods it is sufficient that the signature simply match the hooked method.
*
*
- * For field redirections, see the details in {@link Redirect} for the
- * required signature of the handler method.
+ * For field redirections, see the details in {@link Redirect @Redirect}
+ * for the required signature of the handler method.
*
* For constructor redirections, the signature of the handler method should
* match the constructor itself, return type should be of the type of object
@@ -234,7 +237,7 @@ public class RedirectInjector extends InvokeInjector {
protected RedirectInjector(InjectionInfo info, String annotationType) {
super(info, annotationType);
- int priority = info.getContext().getPriority();
+ int priority = info.getMixin().getPriority();
boolean isFinal = Annotations.getVisible(this.methodNode, Final.class) != null;
this.meta = new Meta(priority, isFinal, this.info.toString(), this.methodNode.desc);
}
@@ -463,7 +466,7 @@ public class RedirectInjector extends InvokeInjector {
Type elementType = field.type.getElementType();
int valueArgIndex = field.getTotalDimensions();
if (this.checkCoerce(valueArgIndex, elementType, String.format("%s array setter method %s from %s",
- this.annotationType, this, this.info.getContext()), true)) {
+ this.annotationType, this, this.info.getMixin()), true)) {
elementType = this.methodArgs[valueArgIndex];
}
@@ -774,7 +777,7 @@ public class RedirectInjector extends InvokeInjector {
LabelNode nullCheckSucceeded = new LabelNode();
insns.add(new InsnNode(Opcodes.DUP));
insns.add(new JumpInsnNode(Opcodes.IFNONNULL, nullCheckSucceeded));
- this.throwException(insns, RedirectInjector.NPE, String.format("%s %s %s returned null for %s",
+ this.throwException(insns, extraStack, RedirectInjector.NPE, String.format("%s %s %s returned null for %s",
this.annotationType, type, this, value));
insns.add(nullCheckSucceeded);
extraStack.add();
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/arg/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/arg/package-info.java
new file mode 100644
index 00000000..e0a1adc5
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/arg/package-info.java
@@ -0,0 +1,32 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Support classes for
+ * {@link org.spongepowered.asm.mixin.injection.ModifyArgs @ModifyArgs}
+ * which handle argument bundles
+ * ({@link org.spongepowered.asm.mixin.injection.invoke.arg.Args}).
+ */
+package org.spongepowered.asm.mixin.injection.invoke.arg;
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/package-info.java
new file mode 100644
index 00000000..cbfaf69d
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Implementation of injectors which primarily mutate method invocations.
+ */
+package org.spongepowered.asm.mixin.injection.invoke;
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/util/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/util/package-info.java
new file mode 100644
index 00000000..3dd49622
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/util/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Utility classes for invoke injectors.
+ */
+package org.spongepowered.asm.mixin.injection.invoke.util;
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/BeforeLoadLocal.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/BeforeLoadLocal.java
index 1d2156ff..609fb55c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/modify/BeforeLoadLocal.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/BeforeLoadLocal.java
@@ -30,6 +30,7 @@ import java.util.ListIterator;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@@ -199,10 +200,10 @@ public class BeforeLoadLocal extends LocalVariableInjectionPoint {
}
@Override
- boolean find(InjectionInfo info, Target target, Collection nodes) {
+ boolean find(InjectionInfo info, InsnList insns, Collection nodes, Target target) {
SearchState state = new SearchState();
- ListIterator iter = target.method.instructions.iterator();
+ ListIterator iter = insns.iterator();
while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();
if (state.isPendingCheck()) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/LocalVariableDiscriminator.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/LocalVariableDiscriminator.java
index b5c5ad87..544e5184 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/modify/LocalVariableDiscriminator.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/LocalVariableDiscriminator.java
@@ -145,13 +145,16 @@ public class LocalVariableDiscriminator {
}
}
- Local[] lvt = new Local[this.baseArgIndex + target.arguments.length];
+ Local[] lvt = new Local[this.baseArgIndex + Bytecode.getArgsSize(target.arguments)];
if (!this.isStatic) {
lvt[0] = new Local("this", Type.getObjectType(target.classNode.name));
}
- for (int local = this.baseArgIndex; local < lvt.length; local++) {
- Type arg = target.arguments[local - this.baseArgIndex];
- lvt[local] = new Local("arg" + local, arg);
+ for (int local = this.baseArgIndex, arg = 0; local < lvt.length; local++) {
+ Type argType = target.arguments[arg++];
+ lvt[local] = new Local("arg" + local, argType);
+ if (argType.getSize() == 2) {
+ lvt[++local] = null;
+ }
}
return lvt;
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java
index 7e2916af..147d9076 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java
@@ -37,11 +37,13 @@ import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.code.Injector;
+import org.spongepowered.asm.mixin.injection.code.InjectorTarget;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
-import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
+import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.injection.struct.Target.Extension;
+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.util.Bytecode;
@@ -54,7 +56,7 @@ import org.spongepowered.asm.util.SignaturePrinter;
* {@link ModifyVariable}.
*/
public class ModifyVariableInjector extends Injector {
-
+
/**
* Target context information
*/
@@ -80,7 +82,7 @@ public class ModifyVariableInjector extends Injector {
LocalVariableInjectionPoint(InjectionPointData data) {
super(data);
- this.mixin = data.getContext();
+ this.mixin = data.getMixin();
}
@Override
@@ -88,15 +90,20 @@ public class ModifyVariableInjector extends Injector {
throw new InvalidInjectionException(this.mixin, this.getAtCode() + " injection point must be used in conjunction with @ModifyVariable");
}
- abstract boolean find(InjectionInfo info, Target target, Collection nodes);
+ abstract boolean find(InjectionInfo info, InsnList insns, Collection nodes, Target target);
}
+ /**
+ * Decorator key for Context decoration
+ */
+ private static final String LOCALS_CONTEXT_KEY = "localcontext";
+
/**
* True to consider only method args
*/
private final LocalVariableDiscriminator discriminator;
-
+
/**
* @param info Injection info
* @param discriminator discriminator
@@ -107,12 +114,13 @@ public class ModifyVariableInjector extends Injector {
}
@Override
- protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InsnList insns, Collection nodes) {
+ protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget,
+ Collection nodes) {
if (injectionPoint instanceof LocalVariableInjectionPoint) {
- Target target = this.info.getContext().getTargetMethod(into);
- return ((LocalVariableInjectionPoint)injectionPoint).find(this.info, target, nodes);
+ return ((LocalVariableInjectionPoint)injectionPoint).find(this.info, injectorTarget.getSlice(injectionPoint), nodes,
+ injectorTarget.getTarget());
}
- return injectionPoint.find(into.desc, insns, nodes);
+ return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes);
}
/* (non-Javadoc)
@@ -134,6 +142,12 @@ public class ModifyVariableInjector extends Injector {
}
}
+ @Override
+ protected void preInject(Target target, InjectionNode node) {
+ Context context = new Context(this.returnType, this.discriminator.isArgsOnly(), target, node.getCurrentTarget());
+ node.decorate(ModifyVariableInjector.LOCALS_CONTEXT_KEY, context);
+ }
+
/**
* Do the injection
*/
@@ -143,15 +157,27 @@ public class ModifyVariableInjector extends Injector {
throw new InvalidInjectionException(this.info, "Variable modifier target for " + this + " was removed by another injector");
}
- Context context = new Context(this.returnType, this.discriminator.isArgsOnly(), target, node.getCurrentTarget());
+ Context context = node.getDecoration(ModifyVariableInjector.LOCALS_CONTEXT_KEY);
+ if (context == null) {
+ throw new InjectionError(String.format(
+ "%s injector target is missing CONTEXT decoration for %s. PreInjection failure or illegal internal state change",
+ this.annotationType, this.info));
+ }
if (this.discriminator.printLVT()) {
this.printLocals(target, context);
}
-
+
this.checkTargetForNode(target, node, RestrictTargetLevel.ALLOW_ALL);
InjectorData handler = new InjectorData(target, "handler", false);
+
+ if (this.returnType == Type.VOID_TYPE) {
+ throw new InvalidInjectionException(this.info, String.format(
+ "%s %s method %s from %s has an invalid signature, cannot return a VOID type.",
+ this.annotationType, handler, this, this.info.getMixin()));
+ }
+
this.validateParams(handler, this.returnType, this.returnType);
Extension extraStack = target.extendStack();
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/package-info.java
new file mode 100644
index 00000000..20ceda6c
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/package-info.java
@@ -0,0 +1,31 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Implementation of variable modifier injector specified by
+ * {@link org.spongepowered.asm.mixin.injection.ModifyVariable
+ * @ModifyVariable}
+ */
+package org.spongepowered.asm.mixin.injection.modify;
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/package-info.java b/src/main/java/org/spongepowered/asm/mixin/injection/package-info.java
new file mode 100644
index 00000000..c1190db2
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/package-info.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of Mixin, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Injectors are class postprocessors which search for annotated methods merged
+ * by mixins and perform weaving operations as requested.
+ */
+package org.spongepowered.asm.mixin.injection;
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 8354bb58..1036cdc5 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
@@ -71,41 +71,41 @@ import com.google.common.primitives.Longs;
* ordinal
* The ordinal position of the constant opcode to match. The default value
* is -1 which supresses ordinal matching
- * named argument nullValue
+ * named argument: nullValue
* To match null literals in the method body, set this to
* true
- * named argument intValue
+ * named argument: intValue
* To match int literals in the method body. See also the
* expandZeroConditions argument below for concerns when matching
* conditional zeroes.
- * named argument floatValue
+ * named argument: floatValue
* To match float literals in the method body.
- * named argument longValue
+ * named argument: longValue
* To match long literals in the method body.
- * named argument doubleValue
+ * named argument: doubleValue
* To match double literals in the method body.
- * named argument stringValue
+ * named argument: stringValue
* To match {@link String} literals in the method body.
- * named argument classValue
+ * named argument: classValue
* To match {@link Class} literals in the method body.
- * named argument log
+ * named argument: log
* Enable debug logging when searching for matching opcodes.
- * named argument expandZeroConditions
+ * named argument: expandZeroConditions
* See the {@link Constant#expandZeroConditions} option, this argument
* should be a list of {@link Condition} names
*
*
* Examples:
*
- * // Find all integer constans with value 4
+ * // Find all integer constans with value 4
* @At(value = "CONSTANT", args = "intValue=4")
*
*
- * // Find the String literal "foo"
+ * // Find the String literal "foo"
* @At(value = "CONSTANT", args = "stringValue=foo"
*
*
- * // Find all integer constants with value 0 and expand conditionals
+ * // Find integer constants with value 0 and expand conditionals
* @At(
* value = "CONSTANT",
* args = {
@@ -182,9 +182,9 @@ public class BeforeConstant extends InjectionPoint {
String strClassValue = data.get("classValue", null);
this.typeValue = strClassValue != null ? Type.getObjectType(strClassValue.replace('.', '/')) : null;
- this.matchByType = this.validateDiscriminator(data.getContext(), "V", empty, "in @At(\"CONSTANT\") args");
+ this.matchByType = this.validateDiscriminator(data.getMixin(), "V", empty, "in @At(\"CONSTANT\") args");
if ("V".equals(this.matchByType)) {
- throw new InvalidInjectionException(data.getContext(), "No constant discriminator could be parsed in @At(\"CONSTANT\") args");
+ throw new InvalidInjectionException(data.getMixin(), "No constant discriminator could be parsed in @At(\"CONSTANT\") args");
}
List conditions = new ArrayList();
@@ -236,7 +236,7 @@ public class BeforeConstant extends InjectionPoint {
if (matchesInsn) {
this.log(" BeforeConstant found a matching constant{} at ordinal {}", this.matchByType != null ? " TYPE" : " value", ordinal);
if (this.ordinal == -1 || this.ordinal == ordinal) {
- this.log(" BeforeConstant found {}", Bytecode.describeNode(insn).trim());
+ this.log(" BeforeConstant found {}", Bytecode.describeNode(insn, false));
nodes.add(insn);
found = true;
}
@@ -280,7 +280,7 @@ public class BeforeConstant extends InjectionPoint {
}
Object value = Bytecode.getConstant(insn);
- if (value == null) {
+ if (value == Type.VOID_TYPE) {
this.log(" BeforeConstant found NULL constant: nullValue = {}", this.nullValue);
return this.nullValue || Constants.OBJECT_DESC.equals(this.matchByType);
} else if (value instanceof Integer) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeFieldAccess.java b/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeFieldAccess.java
index 0cc4b05d..5d3de468 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeFieldAccess.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/points/BeforeFieldAccess.java
@@ -49,21 +49,33 @@ import org.spongepowered.asm.util.Bytecode;
*
* - target
* - A {@link ITargetSelector Target Selector} which identifies the target
- * field.
+ * field.
* - opcode
* - The {@link Opcodes opcode} of the field access, must be one of
- * GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
+ * GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
* - ordinal
* - The ordinal position of the field access to match. For example if the
- * field is referenced 3 times and you want to match the 3rd then you can
- * specify an ordinal of 2 (ordinals are zero-indexed). The
- * default value is -1 which supresses ordinal matching
+ * field is referenced 3 times and you want to match the 3rd then you can
+ * specify an ordinal of 2 (ordinals are zero-indexed). The
+ * default value is -1 which supresses ordinal matching
+ * - named argument: array
+ * - For matching accesses to an array field element following a GETFIELD or
+ * GETSTATIC. Specify get, set or length to match
+ * the desired operation.
+ * - named argument: fuzz
+ * - When matching array operations using array the injection point
+ * will by default search up to 8 instructions after the matched field insn.
+ * However in some cases the array operation may be further from the matched
+ * GETFIELD or GETSTATIC and the amount to search (the "fuzz factor" can be
+ * specified using this argument. Likewise to optimise the search against
+ * false positives, this value can be specified as a lower value if desired.
+ * Has no effect if array is not specified.
*
*
* Example:
- *
+ *
* @At(value = "FIELD", target="field_59_z:I", opcode = Opcodes.GETFIELD)
- *
+ *