From 58f17c613b9be0b89d4537a4d39b8dabafa446a8 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Wed, 18 Feb 2015 17:56:43 +0000
Subject: [PATCH 01/25] Add javadoc note that shadow prefixes are not allowed
on shadow fields
---
src/main/java/org/spongepowered/asm/mixin/Shadow.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/org/spongepowered/asm/mixin/Shadow.java b/src/main/java/org/spongepowered/asm/mixin/Shadow.java
index b08369b6..c7805732 100644
--- a/src/main/java/org/spongepowered/asm/mixin/Shadow.java
+++ b/src/main/java/org/spongepowered/asm/mixin/Shadow.java
@@ -77,6 +77,10 @@ public @interface Shadow {
* failure state indicated by an {@link InvalidMixinException} at run
* time.
*
+ * Prefixes on shadow fields are considered an error condition and don't
+ * have any purpose either way, since the scenario described above cannot
+ * actually occur with fields.
+ *
* @return the shadow prefix
*/
public String prefix() default "shadow$";
From 5dba9e5848327ee2d9e62d9d295890202caf4739 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Wed, 18 Feb 2015 17:57:36 +0000
Subject: [PATCH 02/25] Wiring in ClassInfo for hierarchy traversal
---
.../asm/mixin/transformer/ClassInfo.java | 459 +++++++++++++++---
.../mixin/transformer/MixinClassWriter.java | 6 +-
2 files changed, 383 insertions(+), 82 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
index 9f86e2d7..beb9b74f 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
@@ -35,17 +35,184 @@ import java.util.Set;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
/**
* Information about a class, used as a way of keeping track of class hierarchy
- * information needed to support mixins with detached targets.
+ * information needed to support more complex mixin behaviour such as detached
+ * superclass and mixin inheritance.
*/
class ClassInfo extends TreeInfo {
+ /**
+ * To all intents and purposes, the "real" class hierarchy and the mixin
+ * class hierarchy exist in parallel, this means that for some hierarchy
+ * validation operations we need to walk across to the other
+ * hierarchy in order to allow meaningful validation to occur.
+ *
+ * This enum defines the type of traversal operations which are allowed
+ * for a particular lookup.
+ *
+ * Each traversal type has a next property which defines
+ * the traversal type to use on the next step of the hierarchy
+ * validation. For example, the type {@link #IMMEDIATE} which requires an
+ * immediate match falls through to {@link #NONE} on the next step, which
+ * prevents further traversals from occurring in the lookup.
+ */
+ static enum Traversal {
+
+ /**
+ * No traversals are allowed.
+ */
+ NONE(null, false),
+
+ /**
+ * Traversal is allowed at all stages.
+ */
+ ALL(null, true),
+
+ /**
+ * Traversal is allowed at the bottom of the hierarchy but no further.
+ */
+ IMMEDIATE(Traversal.NONE, true),
+
+ /**
+ * Traversal is allowed only on superclasses and not at the bottom of
+ * the hierarchy.
+ */
+ SUPER(Traversal.ALL, false);
+
+ private final Traversal next;
+
+ private final boolean traverse;
+
+ private Traversal(Traversal next, boolean traverse) {
+ this.next = next != null ? next : this;
+ this.traverse = true;
+ }
+
+ public Traversal next() {
+ return this.next;
+ }
+
+ public boolean canTraverse() {
+ return this.traverse;
+ }
+ }
+
+ /**
+ * Information about a method in this class
+ */
+ class Method {
+
+ /**
+ * The original name of the method
+ */
+ private final String methodName;
+
+ /**
+ * The method signature
+ */
+ private final String methodDesc;
+
+ /**
+ * True if this method was injected by a mixin, false if it was
+ * originally part of the class
+ */
+ private final boolean isInjected;
+
+ /**
+ * Current name of the method, may be different from {@link methodName}
+ * if the method has been renamed
+ */
+ private String currentName;
+
+ public Method(MethodNode method) {
+ this(method, false);
+ }
+
+ public Method(Method method) {
+ this(method.methodName, method.methodDesc, method.isInjected);
+ this.currentName = method.currentName;
+ }
+
+ public Method(MethodNode method, boolean injected) {
+ this(method.name, method.desc, injected);
+ }
+
+ public Method(String name, String desc) {
+ this(name, desc, false);
+ }
+
+ public Method(String name, String desc, boolean injected) {
+ this.methodName = name;
+ this.methodDesc = desc;
+ this.isInjected = injected;
+ this.currentName = name;
+ }
+
+ public String getOriginalName() {
+ return this.methodName;
+ }
+
+ public String getName() {
+ return this.currentName;
+ }
+
+ public String getDesc() {
+ return this.methodDesc;
+ }
+
+ public boolean isInjected() {
+ return this.isInjected;
+ }
+
+ public boolean isRenamed() {
+ return this.currentName != this.methodName;
+ }
+
+ public ClassInfo getOwner() {
+ return ClassInfo.this;
+ }
+
+ public void renameTo(String name) {
+ this.currentName = name;
+ }
+
+ public boolean equals(String name, String desc) {
+ return (this.methodName.equals(name)
+ || this.currentName.equals(name))
+ && this.methodDesc.equals(desc);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Method)) {
+ return false;
+ }
+
+ Method other = (Method)obj;
+ return (other.methodName.equals(this.methodName)
+ || other.currentName.equals(this.currentName))
+ && other.methodDesc.equals(this.methodDesc);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.toString().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return this.methodName + this.methodDesc;
+ }
+ }
+
private static final String JAVA_LANG_OBJECT = "java/lang/Object";
/**
@@ -83,7 +250,7 @@ class ClassInfo extends TreeInfo {
/**
* Public and protected methods (instance) methods in this class
*/
- private final List methods;
+ private final Set methods;
/**
* Public and protected fields in this class
@@ -132,18 +299,18 @@ class ClassInfo extends TreeInfo {
this.name = ClassInfo.JAVA_LANG_OBJECT;
this.superName = null;
this.outerName = null;
- this.methods = ImmutableList.of(
- "getClass()Ljava/lang/Class;",
- "hashCode()I",
- "equals(Ljava/lang/Object;)Z",
- "clone()Ljava/lang/Object;",
- "toString()Ljava/lang/String;",
- "notify()V",
- "notifyAll()V",
- "wait(J)V",
- "wait(JI)V",
- "wait()V",
- "finalize()V"
+ this.methods = ImmutableSet.of(
+ new Method("getClass", "()Ljava/lang/Class;"),
+ new Method("hashCode", "()I"),
+ new Method("equals", "(Ljava/lang/Object;)Z"),
+ new Method("clone", "()Ljava/lang/Object;"),
+ new Method("toString", "()Ljava/lang/String;"),
+ new Method("notify", "()V"),
+ new Method("notifyAll", "()V"),
+ new Method("wait", "(J)V"),
+ new Method("wait", "(JI)V"),
+ new Method("wait", "()V"),
+ new Method("finalize", "()V")
);
this.fields = Collections.emptyList();
this.isInterface = false;
@@ -161,7 +328,7 @@ class ClassInfo extends TreeInfo {
private ClassInfo(ClassNode classNode) {
this.name = classNode.name;
this.superName = classNode.superName != null ? classNode.superName : ClassInfo.JAVA_LANG_OBJECT;
- this.methods = new ArrayList();
+ this.methods = new HashSet();
this.fields = new ArrayList();
this.isInterface = ((classNode.access & Opcodes.ACC_INTERFACE) != 0);
this.interfaces = Collections.unmodifiableList(classNode.interfaces);
@@ -170,11 +337,7 @@ class ClassInfo extends TreeInfo {
this.mixin = this.isMixin ? ((MixinClassNode)classNode).getMixin() : null;
for (MethodNode method : classNode.methods) {
- if (!method.name.startsWith("<")
- && (method.access & Opcodes.ACC_PRIVATE) == 0
- && (method.access & Opcodes.ACC_STATIC) == 0) {
- this.methods.add(method.name + method.desc);
- }
+ this.addMethod(method, false);
}
String outerName = classNode.outerClass;
@@ -195,11 +358,23 @@ class ClassInfo extends TreeInfo {
this.outerName = outerName;
}
+
+ void addMethod(MethodNode method) {
+ this.addMethod(method, true);
+ }
+
+ private void addMethod(MethodNode method, boolean injected) {
+ if (!method.name.startsWith("<")
+ && (method.access & Opcodes.ACC_PRIVATE) == 0
+ && (method.access & Opcodes.ACC_STATIC) == 0) {
+ this.methods.add(new Method(method, injected));
+ }
+ }
/**
* Add a mixin which targets this class
*/
- public void addMixin(MixinInfo mixin) {
+ void addMixin(MixinInfo mixin) {
if (this.isMixin) {
throw new IllegalArgumentException("Cannot add target " + this.name + " for " + mixin.getClassName() + " because the target is a mixin");
}
@@ -213,6 +388,13 @@ class ClassInfo extends TreeInfo {
return Collections.unmodifiableSet(this.mixins);
}
+ /**
+ * Get whether this class is a mixin
+ */
+ public boolean isMixin() {
+ return this.isMixin;
+ }
+
/**
* Get whether this class has ACC_PUBLIC
*/
@@ -311,82 +493,175 @@ class ClassInfo extends TreeInfo {
/**
* Test whether this class has the specified superclass in its hierarchy
- *
+ *
+ * @param superClass Name of the superclass to search for in the hierarchy
* @return true if the specified class appears in the class's hierarchy
* anywhere
*/
public boolean hasSuperClass(String superClass) {
+ return this.hasSuperClass(superClass, Traversal.NONE);
+ }
+
+ /**
+ * Test whether this class has the specified superclass in its hierarchy
+ *
+ * @param superClass Name of the superclass to search for in the hierarchy
+ * @param traversal Traversal type to allow during this lookup
+ * @return true if the specified class appears in the class's hierarchy
+ * anywhere
+ */
+ public boolean hasSuperClass(String superClass, Traversal traversal) {
if (ClassInfo.JAVA_LANG_OBJECT.equals(superClass)) {
return true;
}
- return this.hasSuperClass0(superClass);
- }
-
- private boolean hasSuperClass0(String superClass) {
- ClassInfo superClassInfo = this.getSuperClass();
- if (superClassInfo != null) {
- if (superClass.equals(superClassInfo.getName())) {
- return true;
- }
-
- for (ClassInfo superTarget : superClassInfo.targets()) {
- if (superTarget.hasSuperClass0(superClass)) {
- return true;
- }
- }
- }
-
- return false;
+ return this.findSuperClass(superClass, traversal) != null;
}
- public boolean isAssignableFrom(ClassInfo superClass) {
- if (ClassInfo.OBJECT == superClass) {
- return true;
- }
-
- return this.isAssignableFrom0(superClass);
- }
-
- private boolean isAssignableFrom0(ClassInfo superClass) {
- ClassInfo superClassInfo = this.getSuperClass();
- if (superClassInfo != null) {
- if (superClass == superClassInfo) {
- return true;
- }
-
- for (ClassInfo superTarget : superClassInfo.targets()) {
- if (superTarget.isAssignableFrom0(superClass)) {
- return true;
- }
- }
- }
-
- return false;
+ /**
+ * Test whether this class has the specified superclass in its hierarchy
+ *
+ * @param superClass Superclass to search for in the hierarchy
+ * @return true if the specified class appears in the class's hierarchy
+ * anywhere
+ */
+ public boolean hasSuperClass(ClassInfo superClass) {
+ return this.hasSuperClass(superClass, Traversal.NONE);
}
/**
- * Finds the owner of the specified private or protected method in this
- * class's hierarchy
+ * Test whether this class has the specified superclass in its hierarchy
+ *
+ * @param superClass Superclass to search for in the hierarchy
+ * @param traversal Traversal type to allow during this lookup
+ * @return true if the specified class appears in the class's hierarchy
+ * anywhere
+ */
+ public boolean hasSuperClass(ClassInfo superClass, Traversal traversal) {
+ if (ClassInfo.OBJECT == superClass) {
+ return true;
+ }
+
+ return this.findSuperClass(superClass.name, traversal) != null;
+ }
+
+ /**
+ * Search for the specified superclass in this class's hierarchy. If found
+ * returns the ClassInfo, otherwise returns null
+ *
+ * @param superClass Superclass name to search for
+ * @return Matched superclass or null if not found
+ */
+ public ClassInfo findSuperClass(String superClass) {
+ return this.findSuperClass(superClass, Traversal.NONE);
+ }
+
+ /**
+ * Search for the specified superclass in this class's hierarchy. If found
+ * returns the ClassInfo, otherwise returns null
+ *
+ * @param superClass Superclass name to search for
+ * @param traversal Traversal type to allow during this lookup
+ * @return Matched superclass or null if not found
+ */
+ public ClassInfo findSuperClass(String superClass, Traversal traversal) {
+ ClassInfo superClassInfo = this.getSuperClass();
+ if (superClassInfo != null) {
+ List targets = superClassInfo.targets();
+ for (ClassInfo superTarget : targets) {
+ if (superClass.equals(superTarget.getName())) {
+ return superClassInfo;
+ }
+
+ ClassInfo found = superTarget.findSuperClass(superClass, traversal.next());
+ if (found != null) {
+ return found;
+ }
+ }
+ }
+
+ if (traversal.canTraverse()) {
+ for (MixinInfo mixin : this.mixins) {
+ ClassInfo targetSuper = mixin.getClassInfo().findSuperClass(superClass, traversal);
+ if (targetSuper != null) {
+ return targetSuper;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds the specified private or protected method in this class's hierarchy
+ *
+ * @param method Method to search for
+ * @param includeThisClass True to return this class if the method exists
+ * here, or false to search only superclasses
+ * @return the method object or null if the method could not be resolved
+ */
+ public Method findMethodInHierarchy(MethodNode method, boolean includeThisClass) {
+ return this.findMethodInHierarchy(method.name, method.desc, includeThisClass);
+ }
+
+ /**
+ * Finds the specified public or protected method in this class's hierarchy
+ *
+ * @param method Method to search for
+ * @param includeThisClass True to return this class if the method exists
+ * here, or false to search only superclasses
+ * @return the method object or null if the method could not be resolved
+ */
+ public Method findMethodInHierarchy(MethodInsnNode method, boolean includeThisClass) {
+ return this.findMethodInHierarchy(method.name, method.desc, includeThisClass);
+ }
+
+ /**
+ * Finds the specified public or protected method in this class's hierarchy
*
* @param name Method name to search for
* @param desc Method descriptor
* @param includeThisClass True to return this class if the method exists
* here, or false to search only superclasses
- * @return the name of the class which contains the specified method or null
- * if the method could not be resolved
+ * @return the method object or null if the method could not be resolved
*/
- public String findMethodInHierarchy(String name, String desc, boolean includeThisClass) {
- if (includeThisClass && this.hasMethod(name, desc)) {
- return this.name;
+ public Method findMethodInHierarchy(String name, String desc, boolean includeThisClass) {
+ return this.findMethodInHierarchy(name, desc, includeThisClass, Traversal.NONE);
+ }
+
+ /**
+ * Finds the specified public or protected method in this class's hierarchy
+ *
+ * @param name Method name to search for
+ * @param desc Method descriptor
+ * @param includeThisClass True to return this class if the method exists
+ * here, or false to search only superclasses
+ * @param traversal Traversal type to allow during this lookup
+ * @return the method object or null if the method could not be resolved
+ */
+ public Method findMethodInHierarchy(String name, String desc, boolean includeThisClass, Traversal traversal) {
+ if (includeThisClass) {
+ Method method = this.findMethod(name, desc);
+ if (method != null) {
+ return method;
+ }
+
+ if (traversal.canTraverse()) {
+ for (MixinInfo mixin : this.mixins) {
+ Method mixinMethod = mixin.getClassInfo().findMethod(name, desc);
+ if (mixinMethod != null) {
+ return new Method(mixinMethod);
+ }
+ }
+ }
}
ClassInfo superClassInfo = this.getSuperClass();
if (superClassInfo != null) {
for (ClassInfo superTarget : superClassInfo.targets()) {
- String owner = superTarget.findMethodInHierarchy(name, desc, true);
- if (owner != null) {
- return owner;
+ Method method = superTarget.findMethodInHierarchy(name, desc, true, traversal.next());
+ if (method != null) {
+ return method;
}
}
}
@@ -395,14 +670,40 @@ class ClassInfo extends TreeInfo {
}
/**
- * Get whether this class has a public or protected non-static method
+ * Finds the specified public or protected method in this class
*
- * @param name Method name to search for
- * @param desc Method descriptor
- * @return true if the method is defined in this class or false otherwise
+ * @param method Method to search for
+ * @return the method object or null if the method could not be resolved
*/
- public boolean hasMethod(String name, String desc) {
- return this.methods.contains(name + desc);
+ public Method findMethod(MethodNode method) {
+ return this.findMethod(method.name, method.desc);
+ }
+
+ /**
+ * Finds the specified public or protected method in this class
+ *
+ * @param method Method to search for
+ * @return the method object or null if the method could not be resolved
+ */
+ public Method findMethod(MethodInsnNode method) {
+ return this.findMethod(method.name, method.desc);
+ }
+
+ /**
+ * Finds the specified public or protected method in this class
+ *
+ * @param method Method name to search for
+ * @param desc Method signature to search for
+ * @return the method object or null if the method could not be resolved
+ */
+ public Method findMethod(String name, String desc) {
+ for (Method method : this.methods) {
+ if (method.equals(name, desc)) {
+ return method;
+ }
+ }
+
+ return null;
}
/* (non-Javadoc)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassWriter.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassWriter.java
index 8166fa8b..35d70acb 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassWriter.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassWriter.java
@@ -52,10 +52,10 @@ public class MixinClassWriter extends ClassWriter {
ClassInfo c = ClassInfo.forName(type1);
ClassInfo d = ClassInfo.forName(type2);
- if (c.isAssignableFrom(d)) {
+ if (c.hasSuperClass(d)) {
return type1;
}
- if (d.isAssignableFrom(c)) {
+ if (d.hasSuperClass(c)) {
return type2;
}
if (c.isInterface() || d.isInterface()) {
@@ -68,7 +68,7 @@ public class MixinClassWriter extends ClassWriter {
return MixinClassWriter.JAVA_LANG_OBJECT;
}
- } while (!c.isAssignableFrom(d));
+ } while (!c.hasSuperClass(d));
return c.getName();
}
From cd5f40a0b924005694ac4285dda59b26258c0ebb Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Wed, 18 Feb 2015 17:58:44 +0000
Subject: [PATCH 03/25] Invoke injected callbacks virtually if visible from
subclasses
---
.../asm/mixin/injection/callback/CallbackInjector.java | 4 +++-
.../asm/mixin/injection/invoke/InvokeInjector.java | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
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 742b9a2a..e23fc9f1 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
@@ -195,7 +195,9 @@ public class CallbackInjector extends Injector {
}
// Call the callback!
- insns.add(new MethodInsnNode(this.isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKESPECIAL,
+ boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
+ int invokeOpcode = this.isStatic ? Opcodes.INVOKESTATIC : isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL;
+ insns.add(new MethodInsnNode(invokeOpcode,
this.classNode.name, this.methodNode.name, this.methodNode.desc, false));
if (this.cancellable) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
index 45e0802b..05480a6a 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
@@ -122,7 +122,9 @@ public abstract class InvokeInjector extends Injector {
insns.add(new VarInsnNode(Opcodes.ALOAD, 0));
}
this.pushArgs(args, insns, argMap, startArg, endArg);
- insns.add(new MethodInsnNode(this.isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKESPECIAL,
+ boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
+ int invokeOpcode = this.isStatic ? Opcodes.INVOKESTATIC : isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL;
+ insns.add(new MethodInsnNode(invokeOpcode,
this.classNode.name, this.methodNode.name, this.methodNode.desc, false));
}
From be783986fc98f5fd11f4b3cdf2d192536a9fb4e9 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Wed, 18 Feb 2015 17:59:07 +0000
Subject: [PATCH 04/25] Supermixin support (WIP)
---
.../asm/mixin/MixinTransformerError.java | 47 +++++
.../asm/mixin/transformer/MixinData.java | 159 +++------------
.../asm/mixin/transformer/MixinInfo.java | 183 +++++++++++++++---
.../mixin/transformer/MixinTransformer.java | 31 ++-
.../org/spongepowered/asm/util/ASMHelper.java | 27 ++-
5 files changed, 282 insertions(+), 165 deletions(-)
create mode 100644 src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java
diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java b/src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java
new file mode 100644
index 00000000..80585b28
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java
@@ -0,0 +1,47 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.mixin;
+
+
+/**
+ * Error to throw for things which really shouldn't happen
+ */
+public class MixinTransformerError extends Error {
+
+ private static final long serialVersionUID = 1L;
+
+ public MixinTransformerError(String message) {
+ super(message);
+ }
+
+ public MixinTransformerError(Throwable cause) {
+ super(cause);
+ }
+
+ public MixinTransformerError(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
index bc464663..b8ac830a 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
@@ -24,25 +24,14 @@
*/
package org.spongepowered.asm.mixin.transformer;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.tree.AbstractInsnNode;
-import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
-import org.spongepowered.asm.mixin.Implements;
-import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.asm.mixin.injection.struct.Target;
-import org.spongepowered.asm.util.ASMHelper;
/**
@@ -55,7 +44,7 @@ public class MixinData implements IReferenceMapperContext {
/**
* Mixin info
*/
- private final MixinInfo info;
+ private final MixinInfo mixin;
/**
* Tree
@@ -68,19 +57,9 @@ public class MixinData implements IReferenceMapperContext {
private final ClassNode targetClass;
/**
- * Methods we need to rename
+ * Target ClassInfo
*/
- private final Map renamedMethods = new HashMap();
-
- /**
- * Interfaces soft-implemented using {@link Implements}
- */
- private final List softImplements = new ArrayList();
-
- /**
- * All interfaces implemented by this mixin, including soft implementations
- */
- private final Set interfaces = new HashSet();
+ private final ClassInfo targetClassInfo;
/**
* Information about methods in the target class, used to keep track of
@@ -92,13 +71,14 @@ public class MixinData implements IReferenceMapperContext {
* ctor
*
* @param info Mixin information
+ * @param mixin Mixin classnode
* @param target target class
*/
- MixinData(MixinInfo info, ClassNode target) {
- this.info = info;
- this.classNode = info.getClassNode(ClassReader.EXPAND_FRAMES);
+ MixinData(MixinInfo info, ClassNode mixin, ClassNode target) {
+ this.mixin = info;
+ this.classNode = mixin;
this.targetClass = target;
- this.prepare();
+ this.targetClassInfo = ClassInfo.forName(target.name);
}
/* (non-Javadoc)
@@ -106,7 +86,7 @@ public class MixinData implements IReferenceMapperContext {
*/
@Override
public String toString() {
- return String.format("%s:%s", this.info.getParent().getName(), this.info.getName());
+ return this.mixin.toString();
}
/**
@@ -124,7 +104,7 @@ public class MixinData implements IReferenceMapperContext {
* @return the mixin class name
*/
public String getClassName() {
- return this.info.getClassName();
+ return this.mixin.getClassName();
}
/* (non-Javadoc)
@@ -133,7 +113,7 @@ public class MixinData implements IReferenceMapperContext {
*/
@Override
public String getClassRef() {
- return this.info.getClassRef();
+ return this.mixin.getClassRef();
}
/**
@@ -155,6 +135,15 @@ public class MixinData implements IReferenceMapperContext {
return this.targetClass;
}
+ /**
+ * Get the target classinfo
+ *
+ * @return the target class info
+ */
+ public ClassInfo getTargetClassInfo() {
+ return this.targetClassInfo;
+ }
+
/**
* Get a target method handle from the target class
*
@@ -181,7 +170,7 @@ public class MixinData implements IReferenceMapperContext {
* @return the priority (only meaningful in relation to other mixins)
*/
public int getPriority() {
- return this.info.getPriority();
+ return this.mixin.getPriority();
}
/**
@@ -190,7 +179,7 @@ public class MixinData implements IReferenceMapperContext {
* @return mixin interfaces
*/
public Set getInterfaces() {
- return this.interfaces;
+ return this.mixin.getInterfaces();
}
/**
@@ -200,7 +189,7 @@ public class MixinData implements IReferenceMapperContext {
* @return true if the sourcefile property should be set on the target class
*/
public boolean shouldSetSourceFile() {
- return this.info.getParent().shouldSetSourceFile();
+ return this.mixin.getParent().shouldSetSourceFile();
}
/* (non-Javadoc)
@@ -209,103 +198,7 @@ public class MixinData implements IReferenceMapperContext {
*/
@Override
public ReferenceMapper getReferenceMapper() {
- return this.info.getParent().getReferenceMapper();
- }
-
- /**
- * Prepare the mixin, applies any pre-processing transformations
- */
- private void prepare() {
- this.readImplementations();
- this.findRenamedMethods();
- this.transformMethods();
- }
-
- /**
- * Read and process any {@link Implements} annotations on the mixin
- */
- private void readImplementations() {
- this.interfaces.addAll(this.classNode.interfaces);
-
- AnnotationNode implementsAnnotation = ASMHelper.getInvisibleAnnotation(this.classNode, Implements.class);
- if (implementsAnnotation == null) {
- return;
- }
-
- List interfaces = ASMHelper.getAnnotationValue(implementsAnnotation);
- if (interfaces == null) {
- return;
- }
-
- for (AnnotationNode interfaceNode : interfaces) {
- InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(interfaceNode);
- this.softImplements.add(interfaceInfo);
- this.interfaces.add(interfaceInfo.getInternalName());
- }
- }
-
- /**
- * Let's do this
- */
- private void findRenamedMethods() {
- for (MethodNode mixinMethod : this.classNode.methods) {
- String oldSignature = mixinMethod.name + mixinMethod.desc;
- AnnotationNode shadowAnnotation = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class);
- if (shadowAnnotation != null) {
- String prefix = MixinData.getAnnotationValue(shadowAnnotation, "prefix", Shadow.class);
- if (mixinMethod.name.startsWith(prefix)) {
- String newName = mixinMethod.name.substring(prefix.length());
- this.renamedMethods.put(oldSignature, newName);
- mixinMethod.name = newName;
- }
- }
-
- for (InterfaceInfo iface : this.softImplements) {
- if (iface.renameMethod(mixinMethod)) {
- this.renamedMethods.put(oldSignature, mixinMethod.name);
- }
- }
- }
- }
-
- /**
- * Apply discovered method renames to method invokations in the mixin
- */
- private void transformMethods() {
- for (MethodNode mixinMethod : this.classNode.methods) {
- for (Iterator iter = mixinMethod.instructions.iterator(); iter.hasNext();) {
- AbstractInsnNode insn = iter.next();
- if (insn instanceof MethodInsnNode) {
- MethodInsnNode methodNode = (MethodInsnNode)insn;
- String newName = this.renamedMethods.get(methodNode.name + methodNode.desc);
- if (newName != null) {
- methodNode.name = newName;
- }
- }
- }
- }
- }
-
- /**
- * Gets an annotation value or returns the default if the annotation value
- * is not present
- *
- * @param annotation
- * @param key
- * @param annotationClass
- * @return Value of the specified annotation node, default value if not
- * specified, or null if no value or default
- */
- private static String getAnnotationValue(AnnotationNode annotation, String key, Class> annotationClass) {
- String value = ASMHelper.getAnnotationValue(annotation, key);
- if (value == null) {
- try {
- value = (String)annotationClass.getDeclaredMethod(key).getDefaultValue();
- } catch (NoSuchMethodException ex) {
- // Don't care
- }
- }
- return value;
+ return this.mixin.getParent().getReferenceMapper();
}
/**
@@ -315,7 +208,7 @@ public class MixinData implements IReferenceMapperContext {
* @param targetClass Target class
*/
public void preApply(String transformedName, ClassNode targetClass) {
- this.info.preApply(transformedName, targetClass);
+ this.mixin.preApply(transformedName, targetClass);
}
/**
@@ -325,6 +218,6 @@ public class MixinData implements IReferenceMapperContext {
* @param targetClass Target class
*/
public void postApply(String transformedName, ClassNode targetClass) {
- this.info.postApply(transformedName, targetClass);
+ this.mixin.postApply(transformedName, targetClass);
}
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
index e5357f67..3ee5037c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
@@ -27,18 +27,30 @@ package org.spongepowered.asm.mixin.transformer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Overwrite;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.util.ASMHelper;
import com.google.common.base.Function;
@@ -116,6 +128,16 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
* Configuration plugin
*/
private final transient IMixinConfigPlugin plugin;
+
+ /**
+ * All interfaces implemented by this mixin, including soft implementations
+ */
+ private final transient Set interfaces = new HashSet();
+
+ /**
+ * Interfaces soft-implemented using {@link Implements}
+ */
+ private final transient List softImplements = new ArrayList();
/**
* Internal ctor, called by {@link MixinConfig}
@@ -138,29 +160,14 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
this.mixinBytes = this.loadMixinClass(this.className, runTransformers);
ClassNode classNode = this.getClassNode(0);
- this.classInfo = this.readInfo(classNode);
+ this.classInfo = ClassInfo.fromClassNode(classNode);
this.priority = this.readPriority(classNode);
this.targetClasses = this.readTargetClasses(classNode, suppressPlugin);
this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
this.detachedSuper = this.validateTargetClasses(classNode);
- }
-
- /**
- * Initialises the class info and performs some pre-flight checks on the
- * mixin
- *
- * @param classNode
- * @return
- */
- private ClassInfo readInfo(ClassNode classNode) {
- ClassInfo classInfo = ClassInfo.fromClassNode(classNode);
-
- // isInner (shouldn't) return true for static inner classes
- if (classInfo.isInner()) {
- throw new InvalidMixinException("Inner class mixin must be declared static");
- }
-
- return classInfo;
+ this.validateMixin(classNode);
+ this.readImplementations(classNode);
+ this.prepare(classNode);
}
/**
@@ -233,7 +240,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
Integer priority = ASMHelper.getAnnotationValue(mixin, "priority");
return priority == null ? 1000 : priority.intValue();
}
-
+
private boolean validateTargetClasses(ClassNode classNode) {
boolean detached = false;
@@ -243,7 +250,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
continue;
}
- if (!targetClass.hasSuperClass(classNode.superName)) {
+ if (!targetClass.hasSuperClass(classNode.superName, ClassInfo.Traversal.NONE)) {
throw new InvalidMixinException("Super class '" + classNode.superName.replace('/', '.') + "' of " + this.name
+ " was not found in the hierarchy of target class '" + targetClass + "'");
}
@@ -254,6 +261,118 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
return detached;
}
+ /**
+ * Performs pre-flight checks on the mixin
+ *
+ * @param classNode
+ */
+ private void validateMixin(ClassNode classNode) {
+ // isInner (shouldn't) return true for static inner classes
+ if (this.classInfo.isInner()) {
+ throw new InvalidMixinException("Inner class mixin must be declared static");
+ }
+
+ // Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names
+ if (this.targetClasses.size() > 1) {
+ for (FieldNode field : classNode.fields) {
+ this.checkRemappable(Shadow.class, field.name, ASMHelper.getVisibleAnnotation(field, Shadow.class));
+ }
+
+ for (MethodNode method : classNode.methods) {
+ this.checkRemappable(Shadow.class, method.name, ASMHelper.getVisibleAnnotation(method, Shadow.class));
+ AnnotationNode overwrite = ASMHelper.getVisibleAnnotation(method, Overwrite.class);
+ if (overwrite != null && ((method.access & Opcodes.ACC_STATIC) == 0 || (method.access & Opcodes.ACC_PUBLIC) == 0)) {
+ throw new InvalidMixinException("Found @Overwrite annotation on " + method.name + " in " + this);
+ }
+ }
+ }
+ }
+
+ private void checkRemappable(Class annotationClass, String name, AnnotationNode annotation) {
+ if (annotation != null && ASMHelper.getAnnotationValue(annotation, "remap", Boolean.TRUE)) {
+ throw new InvalidMixinException("Found a remappable @" + annotationClass.getSimpleName() + " annotation on " + name + " in " + this);
+ }
+ }
+
+ /**
+ * Prepare the mixin, applies any pre-processing transformations
+ */
+ private ClassNode prepare(ClassNode classNode) {
+ this.findRenamedMethods(classNode);
+ this.transformMethods(classNode);
+ return classNode;
+ }
+
+ /**
+ * Read and process any {@link Implements} annotations on the mixin
+ */
+ private void readImplementations(ClassNode classNode) {
+ this.interfaces.addAll(classNode.interfaces);
+
+ AnnotationNode implementsAnnotation = ASMHelper.getInvisibleAnnotation(classNode, Implements.class);
+ if (implementsAnnotation == null) {
+ return;
+ }
+
+ List interfaces = ASMHelper.getAnnotationValue(implementsAnnotation);
+ if (interfaces == null) {
+ return;
+ }
+
+ for (AnnotationNode interfaceNode : interfaces) {
+ InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(interfaceNode);
+ this.softImplements.add(interfaceInfo);
+ this.interfaces.add(interfaceInfo.getInternalName());
+ }
+ }
+
+ /**
+ * Let's do this
+ */
+ private void findRenamedMethods(ClassNode classNode) {
+ for (MethodNode mixinMethod : classNode.methods) {
+ Method method = this.classInfo.findMethod(mixinMethod);
+
+ AnnotationNode shadowAnnotation = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class);
+ if (shadowAnnotation != null) {
+ String prefix = ASMHelper.getAnnotationValue(shadowAnnotation, "prefix", Shadow.class);
+ if (mixinMethod.name.startsWith(prefix)) {
+ String newName = mixinMethod.name.substring(prefix.length());
+ method.renameTo(newName);
+ mixinMethod.name = newName;
+ }
+ }
+
+ for (InterfaceInfo iface : this.softImplements) {
+ if (iface.renameMethod(mixinMethod)) {
+ method.renameTo(mixinMethod.name);
+ }
+ }
+ }
+ }
+
+ /**
+ * Apply discovered method renames to method invokations in the mixin
+ */
+ private void transformMethods(ClassNode classNode) {
+ for (MethodNode mixinMethod : classNode.methods) {
+ for (Iterator iter = mixinMethod.instructions.iterator(); iter.hasNext();) {
+ AbstractInsnNode insn = iter.next();
+ if (insn instanceof MethodInsnNode) {
+ MethodInsnNode methodNode = (MethodInsnNode)insn;
+ Method method = this.classInfo.findMethodInHierarchy(methodNode, true);
+ if (method != null && method.isRenamed()) {
+ methodNode.name = method.getName();
+ }
+ }
+ }
+ }
+ }
+
+ ClassInfo getClassInfo() {
+ return this.classInfo;
+ }
+
/**
* Get the parent config which declares this mixin
*/
@@ -335,7 +454,16 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
public int getPriority() {
return this.priority;
}
-
+
+ /**
+ * Get all interfaces for this mixin
+ *
+ * @return mixin interfaces
+ */
+ public Set getInterfaces() {
+ return this.interfaces;
+ }
+
/**
* Get a new mixin data container for this info
*
@@ -343,7 +471,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
* @return
*/
public MixinData createData(ClassNode target) {
- return new MixinData(this, target);
+ ClassNode classNode = this.getClassNode(ClassReader.EXPAND_FRAMES);
+ return new MixinData(this, this.prepare(classNode), target);
}
/**
@@ -398,4 +527,12 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
this.plugin.postApply(transformedName, targetClass, this.className, this);
}
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return String.format("%s:%s", this.parent.getName(), this.name);
+ }
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 24c7b9b2..58a1eafb 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -57,10 +57,13 @@ import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.MixinEnvironment;
+import org.spongepowered.asm.mixin.MixinTransformerError;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
+import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
import org.spongepowered.asm.transformers.TreeTransformer;
import org.spongepowered.asm.util.ASMHelper;
@@ -246,7 +249,7 @@ public class MixinTransformer extends TreeTransformer {
for (MixinConfig config : this.configs) {
if (transformedName != null && transformedName.startsWith(config.getMixinPackage())) {
- throw new RuntimeException(String.format("%s is a mixin class and cannot be referenced directly", transformedName));
+ throw new NoClassDefFoundError(String.format("%s is a mixin class and cannot be referenced directly", transformedName));
}
if (config.hasMixinsFor(transformedName)) {
@@ -269,6 +272,8 @@ public class MixinTransformer extends TreeTransformer {
}
return basicClass;
+ } catch (Exception ex) {
+ throw new MixinTransformerError("An unexpected critical error was encountered", ex);
} finally {
this.reEntranceCheck--;
}
@@ -441,11 +446,16 @@ public class MixinTransformer extends TreeTransformer {
throw new InvalidMixinException(String.format("Mixin classes cannot contain visible static methods or fields, found %s", field.name));
}
+ AnnotationNode shadow = ASMHelper.getVisibleAnnotation(field, Shadow.class);
+ String prefix = ASMHelper.getAnnotationValue(shadow, "prefix", Shadow.class);
+ if (field.name.startsWith(prefix)) {
+ throw new InvalidMixinException(String.format("Shadow field %s in %s has a shadow prefix. This is not allowed.", field.name, mixin));
+ }
+
FieldNode target = this.findTargetField(targetClass, field);
if (target == null) {
// If this field is a shadow field but is NOT found in the target class, that's bad, mmkay
- boolean isShadow = ASMHelper.getVisibleAnnotation(field, Shadow.class) != null;
- if (isShadow) {
+ if (shadow != null) {
throw new InvalidMixinException(String.format("Shadow field %s was not located in the target class", field.name));
}
@@ -541,15 +551,21 @@ public class MixinTransformer extends TreeTransformer {
* @param method
* @param insn
*/
- private void updateStaticBindings(IReferenceMapperContext mixin, ClassNode target, MethodNode method, MethodInsnNode insn) {
+ private void updateStaticBindings(MixinData mixin, ClassNode target, MethodNode method, MethodInsnNode insn) {
if (INIT.equals(method.name) || insn.owner.equals(target.name) || target.name.startsWith("<")) {
return;
}
ClassInfo targetClass = ClassInfo.forName(target.name);
- String newOwner = targetClass.findMethodInHierarchy(insn.name, insn.desc, false);
- if (newOwner != null) {
- insn.owner = newOwner;
+ Method superMethod = targetClass.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
+ if (superMethod != null) {
+ if (superMethod.getOwner().isMixin()) {
+ throw new InvalidMixinException("Invalid INVOKESPECIAL in " + mixin + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ + " for " + insn.name + insn.desc);
+ }
+ insn.owner = superMethod.getOwner().getName();
+ } else if (ClassInfo.forName(insn.owner).isMixin()) {
+ throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + mixin);
}
}
@@ -589,6 +605,7 @@ public class MixinTransformer extends TreeTransformer {
}
targetClass.methods.add(method);
+ mixin.getTargetClassInfo().addMethod(method);
ASMHelper.setVisibleAnnotation(method, MixinMerged.class,
"mixin", mixin.getClassName(),
diff --git a/src/main/java/org/spongepowered/asm/util/ASMHelper.java b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
index 4beec5d1..0a271b99 100644
--- a/src/main/java/org/spongepowered/asm/util/ASMHelper.java
+++ b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
@@ -597,7 +597,30 @@ public class ASMHelper {
T returnValue = ASMHelper.getAnnotationValue(annotation, key);
return returnValue != null ? returnValue : defaultValue;
}
-
+
+ /**
+ * Gets an annotation value or returns the default value of the annotation
+ * if the annotation value is not present
+ *
+ * @param annotation
+ * @param key
+ * @param annotationClass
+ * @return Value of the specified annotation node, default value if not
+ * specified, or null if no value or default
+ */
+ @SuppressWarnings("unchecked")
+ public static T getAnnotationValue(AnnotationNode annotation, String key, Class> annotationClass) {
+ T value = ASMHelper.getAnnotationValue(annotation, key);
+ if (value == null) {
+ try {
+ value = (T)annotationClass.getDeclaredMethod(key).getDefaultValue();
+ } catch (NoSuchMethodException ex) {
+ // Don't care
+ }
+ }
+ return value;
+ }
+
/**
* Get the value of an annotation node and do pseudo-duck-typing via Java's
* crappy generics
@@ -612,7 +635,7 @@ public class ASMHelper {
public static T getAnnotationValue(AnnotationNode annotation, String key) {
boolean getNextValue = false;
- if (annotation.values == null) {
+ if (annotation == null || annotation.values == null) {
return null;
}
From 80e6639761102e54e06020634436b9a7d3a93151 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Wed, 18 Feb 2015 18:15:09 +0000
Subject: [PATCH 05/25] Pull up invokeHandler into Injector to remove
duplication
---
.../mixin/injection/callback/CallbackInjector.java | 5 +----
.../asm/mixin/injection/code/Injector.java | 14 ++++++++++++++
.../asm/mixin/injection/invoke/InvokeInjector.java | 5 +----
3 files changed, 16 insertions(+), 8 deletions(-)
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 e23fc9f1..3e569171 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
@@ -195,10 +195,7 @@ public class CallbackInjector extends Injector {
}
// Call the callback!
- boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
- int invokeOpcode = this.isStatic ? Opcodes.INVOKESTATIC : isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL;
- insns.add(new MethodInsnNode(invokeOpcode,
- this.classNode.name, this.methodNode.name, this.methodNode.desc, false));
+ this.invokeHandler(insns);
if (this.cancellable) {
// Inject the if (e.isCancelled()) return e.getReturnValue();
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 16a1c469..a6b1973c 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
@@ -30,9 +30,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
@@ -133,6 +136,17 @@ public abstract class Injector {
protected abstract void inject(Target target, AbstractInsnNode node);
+ /**
+ * Invoke the handler method
+ *
+ * @param insns
+ */
+ protected void invokeHandler(InsnList insns) {
+ boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
+ int invokeOpcode = this.isStatic ? Opcodes.INVOKESTATIC : isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL;
+ insns.add(new MethodInsnNode(invokeOpcode, this.classNode.name, this.methodNode.name, this.methodNode.desc, false));
+ }
+
protected static String printArgs(Type[] args) {
return "(" + Joiner.on("").join(args) + ")";
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
index 05480a6a..ac20408e 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
@@ -122,10 +122,7 @@ public abstract class InvokeInjector extends Injector {
insns.add(new VarInsnNode(Opcodes.ALOAD, 0));
}
this.pushArgs(args, insns, argMap, startArg, endArg);
- boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
- int invokeOpcode = this.isStatic ? Opcodes.INVOKESTATIC : isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL;
- insns.add(new MethodInsnNode(invokeOpcode,
- this.classNode.name, this.methodNode.name, this.methodNode.desc, false));
+ this.invokeHandler(insns);
}
/**
From ce4ac1b800157bb8526f2428e469ab85ecd7e68d Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Thu, 19 Feb 2015 15:29:15 +0000
Subject: [PATCH 06/25] Implement new hierarchy validation logic for
supermixins in the AP
---
.../tools/obfuscation/AnnotatedMixin.java | 19 +++++--
.../tools/obfuscation/AnnotatedMixins.java | 45 ++++++++++++++++-
.../{validation => }/IMixinValidator.java | 14 ++++--
.../InjectionObfuscationProcessor.java | 10 +++-
.../tools/obfuscation/MixinProcessor.java | 6 +++
.../{validation => }/MixinValidator.java | 36 +++++++++++++-
.../TargetObfuscationProcessor.java | 10 +++-
.../validation/ParentValidator.java | 5 +-
.../validation/TargetValidator.java | 49 +++++++++++++++++--
9 files changed, 171 insertions(+), 23 deletions(-)
rename src/ap/java/org/spongepowered/tools/obfuscation/{validation => }/IMixinValidator.java (86%)
rename src/ap/java/org/spongepowered/tools/obfuscation/{validation => }/MixinValidator.java (66%)
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
index 0f23c0db..fcd34f05 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java
@@ -50,7 +50,7 @@ import net.minecraftforge.srg2source.rangeapplier.MethodData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.tools.MirrorUtils;
-import org.spongepowered.tools.obfuscation.validation.IMixinValidator;
+import org.spongepowered.tools.obfuscation.IMixinValidator.ValidationPass;
/**
@@ -168,7 +168,7 @@ class AnnotatedMixin {
*/
private final Set methodMappings = new LinkedHashSet();
- public AnnotatedMixin(AnnotatedMixins mixins, TypeElement type, Collection validators) {
+ public AnnotatedMixin(AnnotatedMixins mixins, TypeElement type) {
this.annotation = MirrorUtils.getAnnotation(type, Mixin.class);
this.mixins = mixins;
@@ -185,12 +185,16 @@ class AnnotatedMixin {
}
this.remap = AnnotatedMixins.getRemapValue(this.annotation) && this.targets.size() > 0;
-
+ }
+
+ AnnotatedMixin runValidators(ValidationPass pass, Collection validators) {
for (IMixinValidator validator : validators) {
- if (!validator.validate(type, this.annotation, this.targets)) {
- return;
+ if (!validator.validate(pass, this.mixin, this.annotation, this.targets)) {
+ break;
}
}
+
+ return this;
}
private TypeHandle initTargets() {
@@ -246,6 +250,11 @@ class AnnotatedMixin {
return primaryTarget;
}
+ @Override
+ public String toString() {
+ return this.mixin.getSimpleName().toString();
+ }
+
public AnnotationMirror getAnnotation() {
return this.annotation;
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
index bea01410..1f40df47 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixins.java
@@ -27,6 +27,8 @@ package org.spongepowered.tools.obfuscation;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -43,6 +45,8 @@ import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
@@ -51,7 +55,7 @@ import javax.tools.StandardLocation;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.tools.MirrorUtils;
-import org.spongepowered.tools.obfuscation.validation.IMixinValidator;
+import org.spongepowered.tools.obfuscation.IMixinValidator.ValidationPass;
import org.spongepowered.tools.obfuscation.validation.ParentValidator;
import org.spongepowered.tools.obfuscation.validation.TargetValidator;
@@ -96,6 +100,11 @@ class AnnotatedMixins implements Messager {
*/
private final Map mixins = new HashMap();
+ /**
+ * Mixins created during this AP pass
+ */
+ private final List mixinsForPass = new ArrayList();
+
/**
* Name of the resource to write generated srgs to
*/
@@ -291,7 +300,10 @@ class AnnotatedMixins implements Messager {
String name = mixinType.getQualifiedName().toString();
if (!this.mixins.containsKey(name)) {
- this.mixins.put(name, new AnnotatedMixin(this, mixinType, this.validators));
+ AnnotatedMixin mixin = new AnnotatedMixin(this, mixinType);
+ mixin.runValidators(ValidationPass.EARLY, this.validators);
+ this.mixins.put(name, mixin);
+ this.mixinsForPass.add(mixin);
}
}
@@ -308,6 +320,25 @@ class AnnotatedMixins implements Messager {
public AnnotatedMixin getMixin(String mixinType) {
return this.mixins.get(mixinType);
}
+
+ public Collection getMixinsTargeting(TypeMirror targetType) {
+ return this.getMixinsTargeting((TypeElement)((DeclaredType)targetType).asElement());
+ }
+
+ public Collection getMixinsTargeting(TypeElement targetType) {
+ List minions = new ArrayList();
+
+ for (AnnotatedMixin mixin : this.mixins.values()) {
+ for (TypeHandle mixinTarget : mixin.getTargets()) {
+ if (targetType.equals(mixinTarget.getElement())) {
+ minions.add(mixin.getMixin().asType());
+ break;
+ }
+ }
+ }
+
+ return minions;
+ }
/**
* Register an {@link org.spongepowered.asm.mixin.Overwrite} method
@@ -409,6 +440,16 @@ class AnnotatedMixins implements Messager {
}
}
}
+
+ public void onPassStarted() {
+ this.mixinsForPass.clear();
+ }
+
+ public void onPassCompleted() {
+ for (AnnotatedMixin mixin : this.mixinsForPass) {
+ mixin.runValidators(ValidationPass.LATE, this.validators);
+ }
+ }
private boolean shouldRemap(AnnotatedMixin mixinClass, AnnotationMirror annotation) {
return mixinClass.remap() && AnnotatedMixins.getRemapValue(annotation);
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/validation/IMixinValidator.java b/src/ap/java/org/spongepowered/tools/obfuscation/IMixinValidator.java
similarity index 86%
rename from src/ap/java/org/spongepowered/tools/obfuscation/validation/IMixinValidator.java
rename to src/ap/java/org/spongepowered/tools/obfuscation/IMixinValidator.java
index 62a7921b..9e078162 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/validation/IMixinValidator.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/IMixinValidator.java
@@ -22,15 +22,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.tools.obfuscation.validation;
+package org.spongepowered.tools.obfuscation;
import java.util.Collection;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.TypeElement;
-import org.spongepowered.tools.obfuscation.TypeHandle;
-
/**
* A mixin validator module, basically just a way of making the various sanity
@@ -38,14 +36,20 @@ import org.spongepowered.tools.obfuscation.TypeHandle;
*/
public interface IMixinValidator {
+ public enum ValidationPass {
+ EARLY,
+ LATE
+ }
+
/**
* Validate all the things, return false to halt processing of further
* validators. Raise compiler errors/warnings directly.
- *
+ * @param pass TODO
* @param mixin Mixin being validated
* @param annotation Mixin annotation
* @param targets Mixin targets
+ *
* @return False to halt processing of further validators
*/
- public abstract boolean validate(TypeElement mixin, AnnotationMirror annotation, Collection targets);
+ public abstract boolean validate(ValidationPass pass, TypeElement mixin, AnnotationMirror annotation, Collection targets);
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/InjectionObfuscationProcessor.java b/src/ap/java/org/spongepowered/tools/obfuscation/InjectionObfuscationProcessor.java
index 8b2214f4..3eb0c53f 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/InjectionObfuscationProcessor.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/InjectionObfuscationProcessor.java
@@ -73,14 +73,20 @@ public class InjectionObfuscationProcessor extends MixinProcessor {
this.processInjectors(roundEnv, Inject.class);
this.processInjectors(roundEnv, ModifyArg.class);
this.processInjectors(roundEnv, Redirect.class);
+ this.postProcess(roundEnv);
+ return true;
+ }
+
+ @Override
+ protected void postProcess(RoundEnvironment roundEnv) {
+ super.postProcess(roundEnv);
+
try {
this.mixins.writeRefs();
} catch (Exception ex) {
ex.printStackTrace();
}
-
- return true;
}
/**
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/MixinProcessor.java b/src/ap/java/org/spongepowered/tools/obfuscation/MixinProcessor.java
index 92b34eb7..27eeaaf9 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/MixinProcessor.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/MixinProcessor.java
@@ -55,6 +55,8 @@ public abstract class MixinProcessor extends AbstractProcessor {
* Searches and catalogues all annotated mixin classes
*/
protected void processMixins(RoundEnvironment roundEnv) {
+ this.mixins.onPassStarted();
+
for (Element elem1 : roundEnv.getElementsAnnotatedWith(Mixin.class)) {
if (elem1.getKind() == ElementKind.CLASS) {
this.mixins.registerMixin((TypeElement)elem1);
@@ -64,5 +66,9 @@ public abstract class MixinProcessor extends AbstractProcessor {
}
}
}
+
+ protected void postProcess(RoundEnvironment roundEnv) {
+ this.mixins.onPassCompleted();
+ }
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/validation/MixinValidator.java b/src/ap/java/org/spongepowered/tools/obfuscation/MixinValidator.java
similarity index 66%
rename from src/ap/java/org/spongepowered/tools/obfuscation/validation/MixinValidator.java
rename to src/ap/java/org/spongepowered/tools/obfuscation/MixinValidator.java
index 9819c919..da863830 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/validation/MixinValidator.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/MixinValidator.java
@@ -22,10 +22,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.tools.obfuscation.validation;
+package org.spongepowered.tools.obfuscation;
+
+import java.util.Collection;
import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic.Kind;
@@ -39,16 +44,39 @@ public abstract class MixinValidator implements IMixinValidator {
* errors and warnings
*/
protected final ProcessingEnvironment processingEnv;
+
+ /**
+ * Pass to run this validator in
+ */
+ protected final ValidationPass pass;
/**
* ctor
*
* @param processingEnv Processing environment
*/
- public MixinValidator(ProcessingEnvironment processingEnv) {
+ public MixinValidator(ProcessingEnvironment processingEnv, ValidationPass pass) {
this.processingEnv = processingEnv;
+ this.pass = pass;
}
+ /* (non-Javadoc)
+ * @see org.spongepowered.tools.obfuscation.IMixinValidator#validate(
+ * org.spongepowered.tools.obfuscation.IMixinValidator.ValidationPass,
+ * javax.lang.model.element.TypeElement,
+ * javax.lang.model.element.AnnotationMirror, java.util.Collection)
+ */
+ @Override
+ public final boolean validate(ValidationPass pass, TypeElement mixin, AnnotationMirror annotation, Collection targets) {
+ if (pass != this.pass) {
+ return true;
+ }
+
+ return this.validate(mixin, annotation, targets);
+ }
+
+ protected abstract boolean validate(TypeElement mixin, AnnotationMirror annotation, Collection targets);
+
/**
* Output a compiler note
*
@@ -78,4 +106,8 @@ public abstract class MixinValidator implements IMixinValidator {
protected final void error(String error, Element element) {
this.processingEnv.getMessager().printMessage(Kind.ERROR, error, element);
}
+
+ protected final Collection getMixinsTargeting(TypeMirror targetType) {
+ return AnnotatedMixins.getMixinsForEnvironment(this.processingEnv).getMixinsTargeting(targetType);
+ }
}
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationProcessor.java b/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationProcessor.java
index a8b7c232..5770157f 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationProcessor.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationProcessor.java
@@ -66,14 +66,20 @@ public class TargetObfuscationProcessor extends MixinProcessor {
this.processMixins(roundEnv);
this.processShadows(roundEnv);
this.processOverwrites(roundEnv);
+ this.postProcess(roundEnv);
+
+ return true;
+ }
+
+ @Override
+ protected void postProcess(RoundEnvironment roundEnv) {
+ super.postProcess(roundEnv);
try {
this.mixins.writeSrgs();
} catch (Exception ex) {
ex.printStackTrace();
}
-
- return true;
}
/**
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/validation/ParentValidator.java b/src/ap/java/org/spongepowered/tools/obfuscation/validation/ParentValidator.java
index db01678c..b41180e7 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/validation/ParentValidator.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/validation/ParentValidator.java
@@ -32,6 +32,7 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
+import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.TypeHandle;
@@ -46,11 +47,11 @@ public class ParentValidator extends MixinValidator {
* @param processingEnv Processing environment
*/
public ParentValidator(ProcessingEnvironment processingEnv) {
- super(processingEnv);
+ super(processingEnv, ValidationPass.EARLY);
}
/* (non-Javadoc)
- * @see org.spongepowered.tools.obfuscation.validation.IMixinValidator
+ * @see org.spongepowered.tools.obfuscation.MixinValidator
* #validate(javax.lang.model.element.TypeElement,
* javax.lang.model.element.AnnotationMirror, java.util.Collection)
*/
diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/validation/TargetValidator.java b/src/ap/java/org/spongepowered/tools/obfuscation/validation/TargetValidator.java
index db4f82f0..d681691e 100644
--- a/src/ap/java/org/spongepowered/tools/obfuscation/validation/TargetValidator.java
+++ b/src/ap/java/org/spongepowered/tools/obfuscation/validation/TargetValidator.java
@@ -29,8 +29,11 @@ import java.util.Collection;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
+import org.spongepowered.tools.obfuscation.MixinValidator;
import org.spongepowered.tools.obfuscation.TypeHandle;
@@ -45,11 +48,11 @@ public class TargetValidator extends MixinValidator {
* @param processingEnv Processing environment
*/
public TargetValidator(ProcessingEnvironment processingEnv) {
- super(processingEnv);
+ super(processingEnv, ValidationPass.LATE);
}
/* (non-Javadoc)
- * @see org.spongepowered.tools.obfuscation.validation.IMixinValidator
+ * @see org.spongepowered.tools.obfuscation.MixinValidator
* #validate(javax.lang.model.element.TypeElement,
* javax.lang.model.element.AnnotationMirror, java.util.Collection)
*/
@@ -59,11 +62,51 @@ public class TargetValidator extends MixinValidator {
for (TypeHandle target : targets) {
TypeMirror targetType = target.getType();
- if (targetType != null && !this.processingEnv.getTypeUtils().isAssignable(targetType, superClass)) {
+ if (targetType != null && !this.validateSuperClass(targetType, superClass)) {
this.error("Superclass " + superClass + " of " + mixin + " was not found in the hierarchy of target class " + targetType, mixin);
}
}
return true;
}
+
+ private boolean validateSuperClass(TypeMirror targetType, TypeMirror superClass) {
+ if (this.isAssignable(targetType, superClass)) {
+ return true;
+ }
+
+ return this.validateSuperClassRecursive(targetType, superClass);
+ }
+
+ private boolean validateSuperClassRecursive(TypeMirror targetType, TypeMirror superClass) {
+ if (!(targetType instanceof DeclaredType)) {
+ return false;
+ }
+
+ TypeElement targetElement = (TypeElement)((DeclaredType)targetType).asElement();
+ TypeMirror targetSuper = targetElement.getSuperclass();
+ if (targetSuper.getKind() == TypeKind.NONE) {
+ return false;
+ }
+
+ if (this.checkMixinsFor(targetSuper, superClass)) {
+ return true;
+ }
+
+ return this.validateSuperClassRecursive(targetSuper, superClass);
+ }
+
+ private boolean checkMixinsFor(TypeMirror targetType, TypeMirror superClass) {
+ for (TypeMirror mixinType : this.getMixinsTargeting(targetType)) {
+ if (this.isAssignable(mixinType, superClass)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected final boolean isAssignable(TypeMirror targetType, TypeMirror superClass) {
+ return this.processingEnv.getTypeUtils().isAssignable(targetType, superClass);
+ }
}
From f4c80263e9ae61d6c164cad66a16392cd52e02fb Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Thu, 19 Feb 2015 15:31:31 +0000
Subject: [PATCH 07/25] Fix some JDK8 javadoc warnings
---
.../spongepowered/asm/mixin/injection/code/Injector.java | 2 +-
src/main/java/org/spongepowered/asm/util/ASMHelper.java | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
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 a6b1973c..1b033ec1 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
@@ -139,7 +139,7 @@ public abstract class Injector {
/**
* Invoke the handler method
*
- * @param insns
+ * @param insns Instruction list to inject into
*/
protected void invokeHandler(InsnList insns) {
boolean isPrivate = (this.methodNode.access & Opcodes.ACC_PRIVATE) != 0;
diff --git a/src/main/java/org/spongepowered/asm/util/ASMHelper.java b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
index 0a271b99..b5cf2699 100644
--- a/src/main/java/org/spongepowered/asm/util/ASMHelper.java
+++ b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
@@ -602,9 +602,11 @@ public class ASMHelper {
* Gets an annotation value or returns the default value of the annotation
* if the annotation value is not present
*
- * @param annotation
- * @param key
- * @param annotationClass
+ * @param duck type
+ * @param annotation Annotation node to query
+ * @param key Key to search for
+ * @param annotationClass Annotation class to query reflectively for the
+ * default value
* @return Value of the specified annotation node, default value if not
* specified, or null if no value or default
*/
From 55653f325da7bc9c7106009f2716d038758d7dfa Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Fri, 20 Feb 2015 17:26:53 +0000
Subject: [PATCH 08/25] Handle remapping of field/method/cast/whatever insns in
inherited mixins
---
.../asm/mixin/MixinEnvironment.java | 2 +-
.../struct/CallbackInjectionInfo.java | 4 +-
.../mixin/injection/struct/InjectionInfo.java | 8 +-
.../struct/ModifyArgInjectionInfo.java | 4 +-
.../struct/RedirectInjectionInfo.java | 4 +-
.../asm/mixin/transformer/ClassInfo.java | 73 +++
.../asm/mixin/transformer/MixinConfig.java | 2 -
.../asm/mixin/transformer/MixinData.java | 223 ---------
.../asm/mixin/transformer/MixinInfo.java | 31 +-
.../mixin/transformer/MixinTargetContext.java | 445 ++++++++++++++++++
.../mixin/transformer/MixinTransformer.java | 116 ++---
11 files changed, 589 insertions(+), 323 deletions(-)
delete mode 100644 src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
create mode 100644 src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
index 74dd6671..43d42a61 100644
--- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
+++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
@@ -158,7 +158,7 @@ public class MixinEnvironment {
}
public void setActiveTransformer(IClassTransformer transformer) {
- Launch.blackboard.put(MixinEnvironment.TRANSFORMER_KEY, this);
+ Launch.blackboard.put(MixinEnvironment.TRANSFORMER_KEY, transformer);
}
public MixinEnvironment setSide(Side side) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/CallbackInjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/CallbackInjectionInfo.java
index 48850e51..7b111a51 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/CallbackInjectionInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/CallbackInjectionInfo.java
@@ -28,12 +28,12 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.callback.CallbackInjector;
import org.spongepowered.asm.mixin.injection.code.Injector;
-import org.spongepowered.asm.mixin.transformer.MixinData;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
public class CallbackInjectionInfo extends InjectionInfo {
- protected CallbackInjectionInfo(MixinData mixin, MethodNode method, AnnotationNode annotation) {
+ protected CallbackInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
}
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 2290e7dd..0161905e 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
@@ -40,7 +40,7 @@ import org.spongepowered.asm.mixin.injection.InvalidInjectionException;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.code.Injector;
-import org.spongepowered.asm.mixin.transformer.MixinData;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
@@ -65,7 +65,7 @@ public abstract class InjectionInfo {
/**
* Mixin data
*/
- protected final MixinData mixin;
+ protected final MixinTargetContext mixin;
/**
@@ -96,7 +96,7 @@ public abstract class InjectionInfo {
* @param method Injector method
* @param annotation Annotation to parse
*/
- protected InjectionInfo(MixinData mixin, MethodNode method, AnnotationNode annotation) {
+ protected InjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
this.annotation = annotation;
this.method = method;
this.mixin = mixin;
@@ -236,7 +236,7 @@ public abstract class InjectionInfo {
}
@SuppressWarnings("unchecked")
- public static InjectionInfo parse(MixinData mixin, MethodNode method) {
+ public static InjectionInfo parse(MixinTargetContext mixin, MethodNode method) {
AnnotationNode annotation = null;
try {
annotation = ASMHelper.getSingleVisibleAnnotation(method, Inject.class, ModifyArg.class, Redirect.class);
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyArgInjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyArgInjectionInfo.java
index 85378c98..c6b7f25e 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyArgInjectionInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyArgInjectionInfo.java
@@ -28,12 +28,12 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.invoke.ModifyArgInjector;
-import org.spongepowered.asm.mixin.transformer.MixinData;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
public class ModifyArgInjectionInfo extends InjectionInfo {
- public ModifyArgInjectionInfo(MixinData mixin, MethodNode method, AnnotationNode annotation) {
+ public ModifyArgInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/RedirectInjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/RedirectInjectionInfo.java
index b39948ed..28f5375c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/RedirectInjectionInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/RedirectInjectionInfo.java
@@ -28,11 +28,11 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.invoke.RedirectInjector;
-import org.spongepowered.asm.mixin.transformer.MixinData;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
public class RedirectInjectionInfo extends InjectionInfo {
- public RedirectInjectionInfo(MixinData mixin, MethodNode method, AnnotationNode annotation) {
+ public RedirectInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
index beb9b74f..9979c5c9 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
@@ -262,6 +262,12 @@ class ClassInfo extends TreeInfo {
*/
private final Set mixins = new HashSet();
+ /**
+ * Map of mixin types to corresponding supertypes, to avoid repeated
+ * lookups
+ */
+ private final Map correspondingTypes = new HashMap();
+
/**
* Mixin info if this class is a mixin itself
*/
@@ -592,6 +598,73 @@ class ClassInfo extends TreeInfo {
return null;
}
+ /**
+ * Walks up this class's hierarchy to find the first class targetted by the
+ * specified mixin. This is used during mixin application to translate a
+ * mixin reference to a "real class" reference in the context of this
+ * class.
+ *
+ * @param mixin Mixin class to search for
+ * @return corresponding (target) class for the specified mixin or null if
+ * no corresponding mixin was found
+ */
+ ClassInfo findCorrespondingType(ClassInfo mixin) {
+ if (mixin == null || !mixin.isMixin || this.isMixin) {
+ return null;
+ }
+
+ ClassInfo correspondingType = this.correspondingTypes.get(mixin);
+ if (correspondingType == null) {
+ correspondingType = this.findSuperTypeForMixin(mixin);
+ this.correspondingTypes.put(mixin, correspondingType);
+ }
+ return correspondingType;
+ }
+
+ /* (non-Javadoc)
+ * Only used by findCorrespondingType(), used as a convenience so that
+ * sanity checks and caching can be handled more elegantly
+ */
+ private ClassInfo findSuperTypeForMixin(ClassInfo mixin) {
+ ClassInfo superClass = this;
+
+ while (superClass != null && superClass != ClassInfo.OBJECT) {
+ for (MixinInfo minion : superClass.mixins) {
+ if (minion.getClassInfo().equals(mixin)) {
+ return superClass;
+ }
+ }
+
+ superClass = superClass.getSuperClass();
+ }
+
+ return null;
+ }
+
+ /**
+ * Find out whether this (mixin) class has another mixin in its superclass
+ * hierarchy. This method always returns false for non-mixin classes.
+ *
+ * @return true if and only if one or more mixins are found in the hierarchy
+ * of this mixin
+ */
+ public boolean hasMixinInHierarchy() {
+ if (!this.isMixin) {
+ return false;
+ }
+
+ ClassInfo superClass = this.getSuperClass();
+
+ while (superClass != null && superClass != ClassInfo.OBJECT) {
+ if (superClass.isMixin) {
+ return true;
+ }
+ superClass = superClass.getSuperClass();
+ }
+
+ return false;
+ }
+
/**
* Finds the specified private or protected method in this class's hierarchy
*
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
index 2e2803bf..12da31ee 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
@@ -174,8 +174,6 @@ class MixinConfig implements Comparable {
this.mixinPackage += ".";
}
- Launch.classLoader.addClassLoaderExclusion(this.mixinPackage);
-
if (this.refMapperConfig == null) {
if (this.plugin != null) {
this.refMapperConfig = this.plugin.getRefMapperConfig();
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
deleted file mode 100644
index b8ac830a..00000000
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinData.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * This file is part of Sponge, licensed under the MIT License (MIT).
- *
- * Copyright (c) SpongePowered.org
- * 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.
- */
-package org.spongepowered.asm.mixin.transformer;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.MethodNode;
-import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
-import org.spongepowered.asm.mixin.injection.struct.Target;
-
-
-/**
- * Data for applying a mixin. Keeps a copy of the mixin tree and also handles
- * any pre-transformations required by the mixin class itself such as method
- * renaming and any other pre-processing of the mixin bytecode.
- */
-public class MixinData implements IReferenceMapperContext {
-
- /**
- * Mixin info
- */
- private final MixinInfo mixin;
-
- /**
- * Tree
- */
- private final ClassNode classNode;
-
- /**
- *
- */
- private final ClassNode targetClass;
-
- /**
- * Target ClassInfo
- */
- private final ClassInfo targetClassInfo;
-
- /**
- * Information about methods in the target class, used to keep track of
- * transformations we apply
- */
- private final Map targetMethods = new HashMap();
-
- /**
- * ctor
- *
- * @param info Mixin information
- * @param mixin Mixin classnode
- * @param target target class
- */
- MixinData(MixinInfo info, ClassNode mixin, ClassNode target) {
- this.mixin = info;
- this.classNode = mixin;
- this.targetClass = target;
- this.targetClassInfo = ClassInfo.forName(target.name);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return this.mixin.toString();
- }
-
- /**
- * Get the mixin tree
- *
- * @return mixin tree
- */
- public ClassNode getClassNode() {
- return this.classNode;
- }
-
- /**
- * Get the mixin class name
- *
- * @return the mixin class name
- */
- public String getClassName() {
- return this.mixin.getClassName();
- }
-
- /* (non-Javadoc)
- * @see org.spongepowered.asm.mixin.transformer.IReferenceMapperContext
- * #getClassRef()
- */
- @Override
- public String getClassRef() {
- return this.mixin.getClassRef();
- }
-
- /**
- * Get the target class reference
- *
- * @return the reference of the target class (only valid on single-target
- * mixins)
- */
- public String getTargetClassRef() {
- return this.targetClass.name;
- }
-
- /**
- * Get the target class
- *
- * @return the target class
- */
- public ClassNode getTargetClass() {
- return this.targetClass;
- }
-
- /**
- * Get the target classinfo
- *
- * @return the target class info
- */
- public ClassInfo getTargetClassInfo() {
- return this.targetClassInfo;
- }
-
- /**
- * Get a target method handle from the target class
- *
- * @param method method to get a target handle for
- * @return new or existing target handle for the supplied method
- */
- public Target getTargetMethod(MethodNode method) {
- if (!this.targetClass.methods.contains(method)) {
- throw new IllegalArgumentException("Invalid target method supplied to getTargetMethod()");
- }
-
- String targetName = method.name + method.desc;
- Target target = this.targetMethods.get(targetName);
- if (target == null) {
- target = new Target(method);
- this.targetMethods.put(targetName, target);
- }
- return target;
- }
-
- /**
- * Get the mixin priority
- *
- * @return the priority (only meaningful in relation to other mixins)
- */
- public int getPriority() {
- return this.mixin.getPriority();
- }
-
- /**
- * Get all interfaces for this mixin
- *
- * @return mixin interfaces
- */
- public Set getInterfaces() {
- return this.mixin.getInterfaces();
- }
-
- /**
- * Get whether to propogate the source file attribute from a mixin onto the
- * target class
- *
- * @return true if the sourcefile property should be set on the target class
- */
- public boolean shouldSetSourceFile() {
- return this.mixin.getParent().shouldSetSourceFile();
- }
-
- /* (non-Javadoc)
- * @see org.spongepowered.asm.mixin.transformer.IReferenceMapperContext
- * #getReferenceMapper()
- */
- @Override
- public ReferenceMapper getReferenceMapper() {
- return this.mixin.getParent().getReferenceMapper();
- }
-
- /**
- * Called immediately before the mixin is applied to targetClass
- *
- * @param transformedName Target class's transformed name
- * @param targetClass Target class
- */
- public void preApply(String transformedName, ClassNode targetClass) {
- this.mixin.preApply(transformedName, targetClass);
- }
-
- /**
- * Called immediately after the mixin is applied to targetClass
- *
- * @param transformedName Target class's transformed name
- * @param targetClass Target class
- */
- public void postApply(String transformedName, ClassNode targetClass) {
- this.mixin.postApply(transformedName, targetClass);
- }
-}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
index 3ee5037c..196c9810 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
@@ -25,6 +25,7 @@
package org.spongepowered.asm.mixin.transformer;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -32,6 +33,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
@@ -68,6 +72,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
*/
static int mixinOrder = 0;
+ static final Set invalidClasses = MixinInfo.$getInvalidClassesSet();
+
/**
* Logger
*/
@@ -465,14 +471,14 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
}
/**
- * Get a new mixin data container for this info
+ * Get a new mixin target context object for the specified target
*
* @param target
* @return
*/
- public MixinData createData(ClassNode target) {
+ public MixinTargetContext createContextForTarget(ClassNode target) {
ClassNode classNode = this.getClassNode(ClassReader.EXPAND_FRAMES);
- return new MixinData(this, this.prepare(classNode), target);
+ return new MixinTargetContext(this, this.prepare(classNode), target);
}
/**
@@ -492,6 +498,13 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
this.logger.warn("Failed to load mixin %s, the specified mixin will not be applied", mixinClassName);
throw new InvalidMixinException("An error was encountered whilst loading the mixin class", ex);
}
+
+ // Inject the mixin class name into the LaunchClassLoader's invalid
+ // classes set so that any classes referencing the mixin directly will
+ // cause the game to crash
+ if (MixinInfo.invalidClasses != null) {
+ MixinInfo.invalidClasses.add(mixinClassName);
+ }
return mixinBytes;
}
@@ -535,4 +548,16 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
public String toString() {
return String.format("%s:%s", this.parent.getName(), this.name);
}
+
+ @SuppressWarnings("unchecked")
+ private static Set $getInvalidClassesSet() {
+ try {
+ Field invalidClasses = LaunchClassLoader.class.getDeclaredField("invalidClasses");
+ invalidClasses.setAccessible(true);
+ return (Set)invalidClasses.get(Launch.classLoader);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
new file mode 100644
index 00000000..bf0bb30d
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -0,0 +1,445 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.mixin.transformer;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldInsnNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.tree.TypeInsnNode;
+import org.spongepowered.asm.mixin.InvalidMixinException;
+import org.spongepowered.asm.mixin.MixinTransformerError;
+import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
+import org.spongepowered.asm.mixin.injection.struct.Target;
+import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
+import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
+
+
+/**
+ * This object keeps track of data for applying a mixin to a specific target
+ * class during a mixin application. This is a single-use object which
+ * acts as both a handle information we need when applying the mixin (such as
+ * the actual mixin ClassNode and the target ClassNode) and a gateway to
+ * 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 {
+
+ private static final String INIT = "";
+
+ /**
+ * Mixin info
+ */
+ private final MixinInfo mixin;
+
+ /**
+ * Tree
+ */
+ private final ClassNode classNode;
+
+ /**
+ *
+ */
+ private final ClassNode targetClass;
+
+ /**
+ * Target ClassInfo
+ */
+ private final ClassInfo targetClassInfo;
+
+ /**
+ * Information about methods in the target class, used to keep track of
+ * transformations we apply
+ */
+ private final Map targetMethods = new HashMap();
+
+ /**
+ * True if this mixin inherits from a mixin at any point in its hierarchy
+ */
+ private final boolean inheritsFromMixin;
+
+ /**
+ * ctor
+ *
+ * @param info Mixin information
+ * @param mixin Mixin classnode
+ * @param target target class
+ */
+ MixinTargetContext(MixinInfo info, ClassNode mixin, ClassNode target) {
+ this.mixin = info;
+ this.classNode = mixin;
+ this.targetClass = target;
+ this.targetClassInfo = ClassInfo.forName(target.name);
+ this.inheritsFromMixin = info.getClassInfo().hasMixinInHierarchy();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return this.mixin.toString();
+ }
+
+ /**
+ * Get the mixin tree
+ *
+ * @return mixin tree
+ */
+ public ClassNode getClassNode() {
+ return this.classNode;
+ }
+
+ /**
+ * Get the mixin class name
+ *
+ * @return the mixin class name
+ */
+ public String getClassName() {
+ return this.mixin.getClassName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.spongepowered.asm.mixin.transformer.IReferenceMapperContext
+ * #getClassRef()
+ */
+ @Override
+ public String getClassRef() {
+ return this.mixin.getClassRef();
+ }
+
+ /**
+ * Get the target class reference
+ *
+ * @return the reference of the target class (only valid on single-target
+ * mixins)
+ */
+ public String getTargetClassRef() {
+ return this.targetClass.name;
+ }
+
+ /**
+ * Get the target class
+ *
+ * @return the target class
+ */
+ public ClassNode getTargetClass() {
+ return this.targetClass;
+ }
+
+ /**
+ * Get the target classinfo
+ *
+ * @return the target class info
+ */
+ public ClassInfo getTargetClassInfo() {
+ return this.targetClassInfo;
+ }
+
+ /**
+ * Find the corresponding class type for the supplied mixin class in this
+ * mixin target's hierarchy
+ *
+ * @param mixin Mixin class to discover
+ * @return Transformed
+ */
+ public ClassInfo findRealType(ClassInfo mixin) {
+ if (mixin == this.mixin.getClassInfo()) {
+ return this.targetClassInfo;
+ }
+
+ ClassInfo type = this.targetClassInfo.findCorrespondingType(mixin);
+ if (type == null) {
+ throw new InvalidMixinException("Resolution error: unable to find corresponding type for "
+ + mixin + " in hierarchy of " + this.targetClassInfo);
+ }
+
+ return type;
+ }
+
+ /**
+ * Transforms field descriptors which contain mixin types to their
+ * appropriate target type
+ *
+ * @param field
+ */
+ public void transformField(FieldNode field) {
+ this.transformDescriptor(field);
+ }
+
+ /**
+ * Handles "re-parenting" the method supplied, changes all references to the
+ * mixin class to refer to the target class (for field accesses and method
+ * invokations) and also handles fixing up the targets of INVOKESPECIAL
+ * opcodes for mixins with detached targets.
+ *
+ * @param targetClass
+ * @param mixin
+ * @param method
+ */
+ public void transformMethod(MethodNode method) {
+ this.transformDescriptor(method);
+
+ String fromClass = this.getClassRef();
+ boolean detached = !this.getClassNode().superName.equals(this.targetClass.superName);
+
+ Iterator iter = method.instructions.iterator();
+ while (iter.hasNext()) {
+ AbstractInsnNode insn = iter.next();
+
+ if (insn instanceof MethodInsnNode) {
+ MethodInsnNode methodInsn = (MethodInsnNode)insn;
+ this.transformDescriptor(methodInsn);
+ if (methodInsn.owner.equals(fromClass)) {
+ methodInsn.owner = this.targetClass.name;
+ } else if (detached && methodInsn.getOpcode() == Opcodes.INVOKESPECIAL) {
+ this.updateStaticBindings(this.targetClass, this, method, methodInsn);
+ }
+ } else if (insn instanceof FieldInsnNode) {
+ FieldInsnNode fieldInsn = (FieldInsnNode)insn;
+ this.transformDescriptor(fieldInsn);
+ if (fieldInsn.owner.equals(fromClass)) {
+ fieldInsn.owner = this.targetClass.name;
+ }
+ } else if (insn instanceof TypeInsnNode) {
+ this.transformDescriptor((TypeInsnNode)insn);
+ }
+ }
+ }
+
+ /**
+ * Update INVOKESPECIAL opcodes to target the topmost class in the hierarchy
+ * which contains the specified method.
+ *
+ * @param targetClass
+ * @param mixin
+ * @param method
+ * @param insn
+ */
+ private void updateStaticBindings(ClassNode targetClass, MixinTargetContext mixin, MethodNode method, MethodInsnNode insn) {
+ if (INIT.equals(method.name) || insn.owner.equals(targetClass.name) || targetClass.name.startsWith("<")) {
+ return;
+ }
+
+ ClassInfo targetClassInfo = ClassInfo.forName(targetClass.name);
+ Method superMethod = targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
+ if (superMethod != null) {
+ if (superMethod.getOwner().isMixin()) {
+ throw new InvalidMixinException("Invalid INVOKESPECIAL in " + mixin + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ + " for " + insn.name + insn.desc);
+ }
+ insn.owner = superMethod.getOwner().getName();
+ } else if (ClassInfo.forName(insn.owner).isMixin()) {
+ throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + mixin);
+ }
+ }
+
+ /**
+ * Transforms a field descriptor in the context of this mixin target
+ *
+ * @param field
+ */
+ public void transformDescriptor(FieldNode field) {
+ if (!this.inheritsFromMixin) {
+ return;
+ }
+ field.desc = this.transformSingleDescriptor(field.desc, false);
+ }
+
+ /**
+ * Transforms a field insn descriptor in the context of this mixin target
+ *
+ * @param field
+ */
+ public void transformDescriptor(FieldInsnNode field) {
+ if (!this.inheritsFromMixin) {
+ return;
+ }
+ field.desc = this.transformSingleDescriptor(field.desc, false);
+ }
+
+ /**
+ * Transforms a method descriptor in the context of this mixin target
+ *
+ * @param method
+ */
+ public void transformDescriptor(MethodNode method) {
+ if (!this.inheritsFromMixin) {
+ return;
+ }
+ method.desc = this.transformMethodDescriptor(method.desc);
+ }
+
+ /**
+ * Transforms a method insn descriptor in the context of this mixin target
+ *
+ * @param method
+ */
+ public void transformDescriptor(MethodInsnNode method) {
+ if (!this.inheritsFromMixin) {
+ return;
+ }
+ method.desc = this.transformMethodDescriptor(method.desc);
+ }
+
+ /**
+ * Transforms a type insn descriptor in the context of this mixin target
+ *
+ * @param typeInsn
+ */
+ public void transformDescriptor(TypeInsnNode typeInsn) {
+ if (!this.inheritsFromMixin) {
+ return;
+ }
+ typeInsn.desc = this.transformSingleDescriptor(typeInsn.desc, true);
+ }
+
+ private String transformSingleDescriptor(Type type) {
+ if (type.getSort() < Type.ARRAY) {
+ return type.toString();
+ }
+
+ return this.transformSingleDescriptor(type.toString(), false);
+ }
+
+ private String transformSingleDescriptor(String desc, boolean isObject) {
+ String type = desc;
+ while (type.startsWith("[") || type.startsWith("L")) {
+ if (type.startsWith("[")) {
+ type = type.substring(1);
+ continue;
+ }
+ type = type.substring(1, type.indexOf(";"));
+ isObject = true;
+ }
+
+ if (!isObject) {
+ return desc;
+ }
+
+ ClassInfo typeInfo = ClassInfo.forName(type);
+
+ if (!typeInfo.isMixin()) {
+ return desc;
+ }
+
+ return desc.replace(type, this.findRealType(typeInfo).toString());
+ }
+
+ private String transformMethodDescriptor(String desc) {
+ StringBuilder newDesc = new StringBuilder();
+ newDesc.append('(');
+ for (Type arg : Type.getArgumentTypes(desc)) {
+ newDesc.append(this.transformSingleDescriptor(arg));
+ }
+ return newDesc.append(')').append(this.transformSingleDescriptor(Type.getReturnType(desc))).toString();
+ }
+
+ /**
+ * Get a target method handle from the target class
+ *
+ * @param method method to get a target handle for
+ * @return new or existing target handle for the supplied method
+ */
+ public Target getTargetMethod(MethodNode method) {
+ if (!this.targetClass.methods.contains(method)) {
+ throw new IllegalArgumentException("Invalid target method supplied to getTargetMethod()");
+ }
+
+ String targetName = method.name + method.desc;
+ Target target = this.targetMethods.get(targetName);
+ if (target == null) {
+ target = new Target(method);
+ this.targetMethods.put(targetName, target);
+ }
+ return target;
+ }
+
+ /**
+ * Get the mixin priority
+ *
+ * @return the priority (only meaningful in relation to other mixins)
+ */
+ public int getPriority() {
+ return this.mixin.getPriority();
+ }
+
+ /**
+ * Get all interfaces for this mixin
+ *
+ * @return mixin interfaces
+ */
+ public Set getInterfaces() {
+ return this.mixin.getInterfaces();
+ }
+
+ /**
+ * Get whether to propogate the source file attribute from a mixin onto the
+ * target class
+ *
+ * @return true if the sourcefile property should be set on the target class
+ */
+ public boolean shouldSetSourceFile() {
+ return this.mixin.getParent().shouldSetSourceFile();
+ }
+
+ /* (non-Javadoc)
+ * @see org.spongepowered.asm.mixin.transformer.IReferenceMapperContext
+ * #getReferenceMapper()
+ */
+ @Override
+ public ReferenceMapper getReferenceMapper() {
+ return this.mixin.getParent().getReferenceMapper();
+ }
+
+ /**
+ * Called immediately before the mixin is applied to targetClass
+ *
+ * @param transformedName Target class's transformed name
+ * @param targetClass Target class
+ */
+ public void preApply(String transformedName, ClassNode targetClass) {
+ this.mixin.preApply(transformedName, targetClass);
+ }
+
+ /**
+ * Called immediately after the mixin is applied to targetClass
+ *
+ * @param transformedName Target class's transformed name
+ * @param targetClass Target class
+ */
+ public void postApply(String transformedName, ClassNode targetClass) {
+ this.mixin.postApply(transformedName, targetClass);
+ }
+}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 58a1eafb..decde152 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -48,7 +48,6 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.LabelNode;
@@ -62,8 +61,6 @@ import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
-import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
-import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
import org.spongepowered.asm.transformers.TreeTransformer;
import org.spongepowered.asm.util.ASMHelper;
@@ -352,7 +349,7 @@ public class MixinTransformer extends TreeTransformer {
for (MixinInfo mixin : mixins) {
this.logger.info("Mixing {} into {}", mixin.getName(), transformedName);
- this.applyMixin(transformedName, targetClass, mixin.createData(targetClass));
+ this.applyMixin(transformedName, targetClass, mixin.createContextForTarget(targetClass));
}
// Extension point
@@ -389,7 +386,7 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass Target class
* @param mixin Mixin to apply
*/
- protected void applyMixin(String transformedName, ClassNode targetClass, MixinData mixin) {
+ protected void applyMixin(String transformedName, ClassNode targetClass, MixinTargetContext mixin) {
try {
mixin.preApply(transformedName, targetClass);
this.applyMixinInterfaces(targetClass, mixin);
@@ -410,7 +407,7 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass
* @param mixin
*/
- private void applyMixinInterfaces(ClassNode targetClass, MixinData mixin) {
+ private void applyMixinInterfaces(ClassNode targetClass, MixinTargetContext mixin) {
for (String interfaceName : mixin.getInterfaces()) {
if (!targetClass.interfaces.contains(interfaceName)) {
targetClass.interfaces.add(interfaceName);
@@ -424,7 +421,7 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass
* @param mixin
*/
- private void applyMixinAttributes(ClassNode targetClass, MixinData mixin) {
+ private void applyMixinAttributes(ClassNode targetClass, MixinTargetContext mixin) {
if (mixin.shouldSetSourceFile()) {
targetClass.sourceFile = mixin.getClassNode().sourceFile;
}
@@ -439,18 +436,11 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass
* @param mixin
*/
- private void applyMixinFields(ClassNode targetClass, MixinData mixin) {
+ private void applyMixinFields(ClassNode targetClass, MixinTargetContext mixin) {
for (FieldNode field : mixin.getClassNode().fields) {
- // Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition
- if (MixinTransformer.hasFlag(field, Opcodes.ACC_STATIC) && !MixinTransformer.hasFlag(field, Opcodes.ACC_PRIVATE)) {
- throw new InvalidMixinException(String.format("Mixin classes cannot contain visible static methods or fields, found %s", field.name));
- }
-
AnnotationNode shadow = ASMHelper.getVisibleAnnotation(field, Shadow.class);
- String prefix = ASMHelper.getAnnotationValue(shadow, "prefix", Shadow.class);
- if (field.name.startsWith(prefix)) {
- throw new InvalidMixinException(String.format("Shadow field %s in %s has a shadow prefix. This is not allowed.", field.name, mixin));
- }
+ this.validateField(mixin, field, shadow);
+ mixin.transformField(field);
FieldNode target = this.findTargetField(targetClass, field);
if (target == null) {
@@ -470,16 +460,35 @@ public class MixinTransformer extends TreeTransformer {
}
}
+ /**
+ * Field sanity checks
+ * @param mixin
+ * @param field
+ * @param shadow
+ */
+ private void validateField(MixinTargetContext mixin, FieldNode field, AnnotationNode shadow) {
+ // Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition
+ if (MixinTransformer.hasFlag(field, Opcodes.ACC_STATIC) && !MixinTransformer.hasFlag(field, Opcodes.ACC_PRIVATE)) {
+ throw new InvalidMixinException(String.format("Mixin classes cannot contain visible static methods or fields, found %s", field.name));
+ }
+
+ // Shadow fields can't have prefixes, it's meaningless for them anyway
+ String prefix = ASMHelper.getAnnotationValue(shadow, "prefix", Shadow.class);
+ if (field.name.startsWith(prefix)) {
+ throw new InvalidMixinException(String.format("Shadow field %s in %s has a shadow prefix. This is not allowed.", field.name, mixin));
+ }
+ }
+
/**
* Mixin methods from the mixin class into the target class
*
* @param targetClass
* @param mixin
*/
- private void applyMixinMethods(ClassNode targetClass, MixinData mixin) {
+ private void applyMixinMethods(ClassNode targetClass, MixinTargetContext mixin) {
for (MethodNode mixinMethod : mixin.getClassNode().methods) {
// Reparent all mixin methods into the target class
- this.transformMethod(mixin, targetClass, mixinMethod);
+ mixin.transformMethod(mixinMethod);
boolean isShadow = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class) != null;
boolean isOverwrite = ASMHelper.getVisibleAnnotation(mixinMethod, Overwrite.class) != null;
@@ -508,67 +517,6 @@ public class MixinTransformer extends TreeTransformer {
}
}
- /**
- * Handles "re-parenting" the method supplied, changes all references to the
- * mixin class to refer to the target class (for field accesses and method
- * invokations) and also handles fixing up the targets of INVOKESPECIAL
- * opcodes for mixins with detached targets.
- *
- * @param mixin
- * @param target
- * @param method
- */
- private void transformMethod(MixinData mixin, ClassNode target, MethodNode method) {
- String fromClass = mixin.getClassRef();
- boolean detached = !mixin.getClassNode().superName.equals(target.superName);
-
- Iterator iter = method.instructions.iterator();
- while (iter.hasNext()) {
- AbstractInsnNode insn = iter.next();
-
- if (insn instanceof MethodInsnNode) {
- MethodInsnNode methodInsn = (MethodInsnNode) insn;
- if (methodInsn.owner.equals(fromClass)) {
- methodInsn.owner = target.name;
- } else if (detached && methodInsn.getOpcode() == Opcodes.INVOKESPECIAL) {
- this.updateStaticBindings(mixin, target, method, methodInsn);
- }
- } else if (insn instanceof FieldInsnNode) {
- FieldInsnNode fieldInsn = (FieldInsnNode) insn;
- if (fieldInsn.owner.equals(fromClass)) {
- fieldInsn.owner = target.name;
- }
- }
- }
- }
-
- /**
- * Update INVOKESPECIAL opcodes to target the topmost class in the hierarchy
- * which contains the specified method.
- *
- * @param mixin
- * @param target
- * @param method
- * @param insn
- */
- private void updateStaticBindings(MixinData mixin, ClassNode target, MethodNode method, MethodInsnNode insn) {
- if (INIT.equals(method.name) || insn.owner.equals(target.name) || target.name.startsWith("<")) {
- return;
- }
-
- ClassInfo targetClass = ClassInfo.forName(target.name);
- Method superMethod = targetClass.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
- if (superMethod != null) {
- if (superMethod.getOwner().isMixin()) {
- throw new InvalidMixinException("Invalid INVOKESPECIAL in " + mixin + " resolved " + insn.owner + " -> " + superMethod.getOwner()
- + " for " + insn.name + insn.desc);
- }
- insn.owner = superMethod.getOwner().getName();
- } else if (ClassInfo.forName(insn.owner).isMixin()) {
- throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + mixin);
- }
- }
-
/**
* Attempts to merge the supplied method into the target class
*
@@ -578,7 +526,7 @@ public class MixinTransformer extends TreeTransformer {
* @param isOverwrite true if the method is annotated with an
* {@link Overwrite} annotation
*/
- private void mergeMethod(ClassNode targetClass, MixinData mixin, MethodNode method, boolean isOverwrite) {
+ private void mergeMethod(ClassNode targetClass, MixinTargetContext mixin, MethodNode method, boolean isOverwrite) {
MethodNode target = this.findTargetMethod(targetClass, method);
if (target != null) {
@@ -667,7 +615,7 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass
* @param mixin
*/
- private void applyInitialisers(ClassNode targetClass, MixinData mixin) {
+ private void applyInitialisers(ClassNode targetClass, MixinTargetContext mixin) {
// Try to find a suitable constructor, we need a constructor with line numbers in order to extract the initialiser
MethodNode ctor = this.getConstructor(mixin);
if (ctor == null) {
@@ -691,7 +639,7 @@ public class MixinTransformer extends TreeTransformer {
/**
* Finds a suitable ctor for reading the instance initialiser bytecode
*/
- private MethodNode getConstructor(MixinData mixin) {
+ private MethodNode getConstructor(MixinTargetContext mixin) {
MethodNode ctor = null;
for (MethodNode mixinMethod : mixin.getClassNode().methods) {
@@ -828,7 +776,7 @@ public class MixinTransformer extends TreeTransformer {
* @param targetClass
* @param mixin
*/
- private void applyInjections(ClassNode targetClass, MixinData mixin) {
+ private void applyInjections(ClassNode targetClass, MixinTargetContext mixin) {
for (MethodNode method : targetClass.methods) {
InjectionInfo injectInfo = InjectionInfo.parse(mixin, method);
if (injectInfo == null) {
From e88f5b72ee481658b83b0c58e28d27a44c3b588d Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Fri, 20 Feb 2015 17:38:43 +0000
Subject: [PATCH 09/25] Disable verbose logging by default
---
.../asm/mixin/transformer/MixinConfig.java | 16 ++++++++++++++++
.../asm/mixin/transformer/MixinInfo.java | 8 ++++++++
.../asm/mixin/transformer/MixinTransformer.java | 5 +++--
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
index 12da31ee..4cf6821f 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
@@ -34,8 +34,10 @@ import java.util.Set;
import net.minecraft.launchwrapper.Launch;
+import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.helpers.Booleans;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
@@ -114,6 +116,12 @@ class MixinConfig implements Comparable {
@SerializedName("refmap")
private String refMapperConfig;
+ /**
+ * True to output "mixing in" messages at INFO level rather than DEBUG
+ */
+ @SerializedName("verbose")
+ private boolean verboseLogging;
+
/**
* Intrinsic order (for sorting configurations with identical priority)
*/
@@ -185,6 +193,7 @@ class MixinConfig implements Comparable {
}
this.refMapper = ReferenceMapper.read(this.refMapperConfig);
+ this.verboseLogging |= Booleans.parseBoolean(System.getProperty("mixin.debug.verbose"), false) | MixinTransformer.DEBUG_ALL;
}
/**
@@ -304,6 +313,13 @@ class MixinConfig implements Comparable {
public Set getTargets() {
return this.mixinMapping.keySet();
}
+
+ /**
+ * Get the logging level for this config
+ */
+ public Level getLoggingLevel() {
+ return this.verboseLogging ? Level.INFO : Level.DEBUG;
+ }
/**
* Check whether this configuration bundle has a mixin for the specified
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
index 196c9810..9d0619ff 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
@@ -36,6 +36,7 @@ import java.util.Set;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
+import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
@@ -427,6 +428,13 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
return this.detachedSuper;
}
+ /**
+ * Get the logging level for this mixin
+ */
+ public Level getLoggingLevel() {
+ return this.parent.getLoggingLevel();
+ }
+
/**
* Get a new tree for the class bytecode
*/
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index decde152..794ac759 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -158,7 +158,8 @@ public class MixinTransformer extends TreeTransformer {
Opcodes.SASTORE
};
- private static final boolean DEBUG_EXPORT = Booleans.parseBoolean(System.getProperty("mixin.debug.export"), false);
+ public static final boolean DEBUG_ALL = Booleans.parseBoolean(System.getProperty("mixin.debug"), false);
+ private static final boolean DEBUG_EXPORT = Booleans.parseBoolean(System.getProperty("mixin.debug.export"), false) | MixinTransformer.DEBUG_ALL;
/**
* Log all the things
@@ -348,7 +349,7 @@ public class MixinTransformer extends TreeTransformer {
ClassNode targetClass = this.readClass(basicClass, true);
for (MixinInfo mixin : mixins) {
- this.logger.info("Mixing {} into {}", mixin.getName(), transformedName);
+ this.logger.log(mixin.getLoggingLevel(), "Mixing {} into {}", mixin.getName(), transformedName);
this.applyMixin(transformedName, targetClass, mixin.createContextForTarget(targetClass));
}
From 76a37fc4124ee435bd7cce62dc998ec6802b44e2 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Fri, 20 Feb 2015 17:47:23 +0000
Subject: [PATCH 10/25] Add debugging option for running CheckClassAdapter
---
.../asm/mixin/transformer/MixinTransformer.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 794ac759..97bbc16c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -43,6 +43,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.helpers.Booleans;
+import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
@@ -54,6 +55,7 @@ import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LineNumberNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.util.CheckClassAdapter;
import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinTransformerError;
@@ -160,6 +162,7 @@ public class MixinTransformer extends TreeTransformer {
public static final boolean DEBUG_ALL = Booleans.parseBoolean(System.getProperty("mixin.debug"), false);
private static final boolean DEBUG_EXPORT = Booleans.parseBoolean(System.getProperty("mixin.debug.export"), false) | MixinTransformer.DEBUG_ALL;
+ private static final boolean DEBUG_VERIFY = Booleans.parseBoolean(System.getProperty("mixin.debug.verify"), false) | MixinTransformer.DEBUG_ALL;
/**
* Log all the things
@@ -356,6 +359,11 @@ public class MixinTransformer extends TreeTransformer {
// Extension point
this.postTransform(transformedName, targetClass, mixins);
+ // Run CheckClassAdapter on the mixin bytecode if debug option is enabled
+ if (MixinTransformer.DEBUG_VERIFY) {
+ targetClass.accept(new CheckClassAdapter(new ClassWriter(ClassWriter.COMPUTE_FRAMES)));
+ }
+
// Collapse tree to bytes
byte[] bytes = this.writeClass(targetClass);
From f679568c7cda5545e3639fae2fd83a2fabbd0c44 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Fri, 20 Feb 2015 18:29:12 +0000
Subject: [PATCH 11/25] Fix some stack size calculation issues
---
.../asm/mixin/injection/invoke/ModifyArgInjector.java | 9 ++++-----
.../asm/mixin/transformer/MixinTransformer.java | 1 +
2 files changed, 5 insertions(+), 5 deletions(-)
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 379d505e..5498ab2a 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
@@ -89,7 +89,6 @@ public class ModifyArgInjector extends InvokeInjector {
protected void inject(Target target, MethodInsnNode node) {
Type[] args = Type.getArgumentTypes(node.desc);
int argIndex = this.findArgIndex(target, args);
-
InsnList insns = new InsnList();
int extraLocals = 0;
@@ -100,8 +99,8 @@ public class ModifyArgInjector extends InvokeInjector {
}
target.method.instructions.insertBefore(node, insns);
- target.method.maxLocals = Math.max(target.method.maxLocals, target.maxLocals + extraLocals);
- target.method.maxStack = Math.max(target.method.maxStack, target.maxStack + 2 - extraLocals);
+ target.method.maxLocals = Math.max(target.maxLocals, target.method.maxLocals + extraLocals);
+ target.method.maxStack = Math.max(target.maxStack, target.method.maxStack + 2 - (extraLocals - 1));
}
/**
@@ -111,7 +110,7 @@ public class ModifyArgInjector extends InvokeInjector {
int[] argMap = this.storeArgs(target, args, insns, argIndex);
this.invokeHandlerWithArgs(args, insns, argMap, argIndex, argIndex + 1);
this.pushArgs(args, insns, argMap, argIndex + 1, args.length);
- return target.method.maxLocals - argMap[argMap.length - 1] - 1 + args[args.length - 1].getSize();
+ return (target.method.maxLocals - argMap[argMap.length - 1]) + 1 + args[args.length - 1].getSize();
}
/**
@@ -127,7 +126,7 @@ public class ModifyArgInjector extends InvokeInjector {
this.pushArgs(args, insns, argMap, 0, argIndex);
this.invokeHandlerWithArgs(args, insns, argMap, 0, args.length);
this.pushArgs(args, insns, argMap, argIndex + 1, args.length);
- return target.method.maxLocals - argMap[argMap.length - 1] - 1 + args[args.length - 1].getSize();
+ return (target.method.maxLocals - argMap[argMap.length - 1]) + 1 + args[args.length - 1].getSize();
}
protected int findArgIndex(Target target, Type[] args) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 97bbc16c..e42a381e 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -640,6 +640,7 @@ public class MixinTransformer extends TreeTransformer {
// Patch the initialiser into the target class ctors
for (MethodNode method : targetClass.methods) {
if (MixinTransformer.INIT.equals(method.name)) {
+ method.maxStack = Math.max(method.maxStack, ctor.maxStack);
this.injectInitialiser(method, initialiser);
}
}
From 0ec4505748e6f7bf28ca9da4459f1008b974e381 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sat, 21 Feb 2015 14:09:28 +0000
Subject: [PATCH 12/25] Fix some JDK8 javadoc errors
---
.../mixin/transformer/MixinTargetContext.java | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index bf0bb30d..ac8667d0 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -192,7 +192,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
* Transforms field descriptors which contain mixin types to their
* appropriate target type
*
- * @param field
+ * @param field Field to transform
*/
public void transformField(FieldNode field) {
this.transformDescriptor(field);
@@ -204,9 +204,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
* invokations) and also handles fixing up the targets of INVOKESPECIAL
* opcodes for mixins with detached targets.
*
- * @param targetClass
- * @param mixin
- * @param method
+ * @param method Method to transform
*/
public void transformMethod(MethodNode method) {
this.transformDescriptor(method);
@@ -268,7 +266,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
/**
* Transforms a field descriptor in the context of this mixin target
*
- * @param field
+ * @param field Field node to transform
*/
public void transformDescriptor(FieldNode field) {
if (!this.inheritsFromMixin) {
@@ -280,7 +278,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
/**
* Transforms a field insn descriptor in the context of this mixin target
*
- * @param field
+ * @param field Field instruction node to transform
*/
public void transformDescriptor(FieldInsnNode field) {
if (!this.inheritsFromMixin) {
@@ -292,7 +290,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
/**
* Transforms a method descriptor in the context of this mixin target
*
- * @param method
+ * @param method Method node to transform
*/
public void transformDescriptor(MethodNode method) {
if (!this.inheritsFromMixin) {
@@ -304,7 +302,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
/**
* Transforms a method insn descriptor in the context of this mixin target
*
- * @param method
+ * @param method Method instruction node to transform
*/
public void transformDescriptor(MethodInsnNode method) {
if (!this.inheritsFromMixin) {
@@ -316,7 +314,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
/**
* Transforms a type insn descriptor in the context of this mixin target
*
- * @param typeInsn
+ * @param typeInsn Type instruction node to transform
*/
public void transformDescriptor(TypeInsnNode typeInsn) {
if (!this.inheritsFromMixin) {
From 7850fb3ee169cda67ebf8dfad92a96e0dc3803f5 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sat, 21 Feb 2015 14:09:49 +0000
Subject: [PATCH 13/25] Add a few debugging methods to ASMHelper
---
.../org/spongepowered/asm/util/ASMHelper.java | 121 ++++++++++++++----
1 file changed, 99 insertions(+), 22 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/util/ASMHelper.java b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
index b5cf2699..b3f719df 100644
--- a/src/main/java/org/spongepowered/asm/util/ASMHelper.java
+++ b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
@@ -36,17 +36,7 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
-import org.objectweb.asm.tree.AbstractInsnNode;
-import org.objectweb.asm.tree.AnnotationNode;
-import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.FieldNode;
-import org.objectweb.asm.tree.InsnList;
-import org.objectweb.asm.tree.InsnNode;
-import org.objectweb.asm.tree.IntInsnNode;
-import org.objectweb.asm.tree.LdcInsnNode;
-import org.objectweb.asm.tree.MethodInsnNode;
-import org.objectweb.asm.tree.MethodNode;
-import org.objectweb.asm.tree.VarInsnNode;
+import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.CheckClassAdapter;
public class ASMHelper {
@@ -65,7 +55,7 @@ public class ASMHelper {
MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()Z", null, null);
InsnList code = method.instructions;
- code.add(pushIntConstant(retval ? 1 : 0));
+ code.add(ASMHelper.pushIntConstant(retval ? 1 : 0));
code.add(new InsnNode(Opcodes.IRETURN));
clazz.methods.add(method);
@@ -82,7 +72,7 @@ public class ASMHelper {
MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I", null, null);
InsnList code = method.instructions;
- code.add(pushIntConstant(retval));
+ code.add(ASMHelper.pushIntConstant(retval));
code.add(new InsnNode(Opcodes.IRETURN));
clazz.methods.add(method);
@@ -101,7 +91,7 @@ public class ASMHelper {
MethodNode method =
new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()" + rettype.getDescriptor(), null, null);
- populateSelfForwardingMethod(method, forwardname, rettype, Type.getObjectType(clazz.name));
+ ASMHelper.populateSelfForwardingMethod(method, forwardname, rettype, Type.getObjectType(clazz.name));
clazz.methods.add(method);
}
@@ -121,7 +111,7 @@ public class ASMHelper {
Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
"()" + rettype.getDescriptor(), null, null);
- populateSelfForwardingMethod(method, forwardname, rettype, argtype);
+ ASMHelper.populateSelfForwardingMethod(method, forwardname, rettype, argtype);
clazz.methods.add(method);
}
@@ -140,7 +130,7 @@ public class ASMHelper {
MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
"()" + rettype.getDescriptor(), null, null);
- populateForwardingToStaticMethod(method, forwardname, rettype, Type.getObjectType(clazz.name), fowardtype);
+ ASMHelper.populateForwardingToStaticMethod(method, forwardname, rettype, Type.getObjectType(clazz.name), fowardtype);
clazz.methods.add(method);
}
@@ -162,7 +152,7 @@ public class ASMHelper {
method =
new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()" + rettype.getDescriptor(), null, null);
- populateForwardingToStaticMethod(method, forwardname, rettype, thistype, fowardtype);
+ ASMHelper.populateForwardingToStaticMethod(method, forwardname, rettype, thistype, fowardtype);
clazz.methods.add(method);
}
@@ -181,7 +171,7 @@ public class ASMHelper {
method.instructions.clear();
- populateSelfForwardingMethod(method, forwardname, methodType.getReturnType(), thistype);
+ ASMHelper.populateSelfForwardingMethod(method, forwardname, methodType.getReturnType(), thistype);
}
/**
@@ -199,7 +189,7 @@ public class ASMHelper {
method =
new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()" + rettype.getDescriptor(), null, null);
- populateForwardingMethod(method, forwardname, rettype, argtype, Type.getObjectType(clazz.name));
+ ASMHelper.populateForwardingMethod(method, forwardname, rettype, argtype, Type.getObjectType(clazz.name));
clazz.methods.add(method);
}
@@ -217,7 +207,7 @@ public class ASMHelper {
method.instructions.clear();
- populateForwardingMethod(method, forwardname, methodType.getReturnType(), methodType.getArgumentTypes()[0], thistype);
+ ASMHelper.populateForwardingMethod(method, forwardname, methodType.getReturnType(), methodType.getArgumentTypes()[0], thistype);
}
/**
@@ -323,7 +313,7 @@ public class ASMHelper {
* @param method the method to add
*/
public static void addAndReplaceMethod(ClassNode clazz, MethodNode method) {
- MethodNode m = findMethod(clazz, method.name, method.desc);
+ MethodNode m = ASMHelper.findMethod(clazz, method.name, method.desc);
if (m != null) {
clazz.methods.remove(m);
}
@@ -338,7 +328,7 @@ public class ASMHelper {
public static void dumpClass(ClassNode classNode) {
ClassWriter cw = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES);
classNode.accept(cw);
- dumpClass(cw.toByteArray());
+ ASMHelper.dumpClass(cw.toByteArray());
}
/**
@@ -351,6 +341,93 @@ public class ASMHelper {
CheckClassAdapter.verify(cr, true, new PrintWriter(System.out));
}
+ /**
+ * Prints a representation of a method's instructions to stderr
+ *
+ * @param method Method to print
+ */
+ public static void printMethod(MethodNode method) {
+ System.err.printf("%s%s\n", method.name, method.desc);
+ for (Iterator iter = method.instructions.iterator(); iter.hasNext();) {
+ System.err.print(" ");
+ ASMHelper.printNode(iter.next());
+ }
+ }
+
+ /**
+ * Prints a representation of the specified insn node to stderr
+ *
+ * @param node Node to print
+ */
+ public static void printNode(AbstractInsnNode node) {
+ System.err.printf("%s ", node.getClass().getSimpleName());
+ if (node instanceof LabelNode) {
+ System.err.printf("[%s]", ((LabelNode)node).getLabel());
+ } else if (node instanceof JumpInsnNode) {
+ System.err.printf("[%s]", ((JumpInsnNode)node).label.getLabel());
+ } else if (node instanceof VarInsnNode) {
+ System.err.printf("[%s] %d", ASMHelper.getOpcodeName(node), ((VarInsnNode)node).var);
+ } else if (node instanceof MethodInsnNode) {
+ MethodInsnNode mth = (MethodInsnNode)node;
+ System.err.printf("[%s] %s %s %s", ASMHelper.getOpcodeName(node), mth.owner, mth.name, mth.desc);
+ } else if (node instanceof FieldInsnNode) {
+ FieldInsnNode fld = (FieldInsnNode)node;
+ System.err.printf("[%s] %s %s %s", ASMHelper.getOpcodeName(node), fld.owner, fld.name, fld.desc);
+ } else if (node instanceof LineNumberNode) {
+ LineNumberNode ln = (LineNumberNode)node;
+ System.err.printf("LINE=%d LABEL=[%s]", ln.line, ln.start.getLabel());
+ } else if (node instanceof LdcInsnNode) {
+ System.err.print(((LdcInsnNode)node).cst);
+ } else if (node instanceof IntInsnNode) {
+ System.err.print(((IntInsnNode)node).operand);
+ } else {
+ System.err.printf("[%s] ", ASMHelper.getOpcodeName(node));
+ }
+ System.err.print("\n");
+ }
+
+ /**
+ * Uses reflection to find an approximate constant name match for the
+ * supplied node's opcode
+ *
+ * @param node Node to query for opcode
+ * @return Approximate opcode name (approximate because some constants in
+ * the {@link Opcodes} class have the same value as opcodes
+ */
+ public static String getOpcodeName(AbstractInsnNode node) {
+ return ASMHelper.getOpcodeName(node.getOpcode());
+ }
+
+ /**
+ * Uses reflection to find an approximate constant name match for the
+ * supplied opcode
+ *
+ * @param opcode Opcode to look up
+ * @return Approximate opcode name (approximate because some constants in
+ * the {@link Opcodes} class have the same value as opcodes
+ */
+ private static String getOpcodeName(int opcode) {
+ if (opcode > 0) {
+ boolean found = false;
+
+ try {
+ for (java.lang.reflect.Field f : Opcodes.class.getDeclaredFields()) {
+ if (!found && f.getName() != "UNINITIALIZED_THIS") {
+ continue;
+ }
+ found = true;
+ if (f.getType() == Integer.TYPE && f.getInt(null) == opcode) {
+ return f.getName();
+ }
+ }
+ } catch (Exception ex) {
+ // derp
+ }
+ }
+
+ return String.valueOf(opcode);
+ }
+
/**
* Set a runtime-visible annotation of the specified class on the supplied
* field node
From 9d9c2238e890398d26b1ac64d9e77b1e60f6fb88 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sat, 21 Feb 2015 14:37:09 +0000
Subject: [PATCH 14/25] Fixed (probably) the ctor/initialiser overlap issue
with JDK8 classes
---
.../asm/mixin/transformer/MixinTransformer.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index e42a381e..36764275 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -724,12 +724,20 @@ public class MixinTransformer extends TreeTransformer {
int line = 0;
InsnList initialiser = new InsnList();
boolean gatherNodes = false;
+ int trimAtOpcode = -1;
LabelNode optionalInsn = null;
for (Iterator iter = ctor.instructions.iterator(init.marker); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
if (insn instanceof LineNumberNode) {
line = ((LineNumberNode)insn).line;
- gatherNodes = init.excludes(line);
+ AbstractInsnNode next = ctor.instructions.get(ctor.instructions.indexOf(insn) + 1);
+ if (line == init.end && next.getOpcode() != Opcodes.RETURN) {
+ gatherNodes = true;
+ trimAtOpcode = Opcodes.RETURN;
+ } else {
+ gatherNodes = init.excludes(line);
+ trimAtOpcode = -1;
+ }
} else if (gatherNodes) {
if (optionalInsn != null) {
initialiser.add(optionalInsn);
@@ -740,6 +748,10 @@ public class MixinTransformer extends TreeTransformer {
optionalInsn = (LabelNode)insn;
} else {
int opcode = insn.getOpcode();
+ if (opcode == trimAtOpcode) {
+ trimAtOpcode = -1;
+ continue;
+ }
for (int ivalidOp : MixinTransformer.INITIALISER_OPCODE_BLACKLIST) {
if (opcode == ivalidOp) {
// At the moment I don't handle any transient locals because I haven't seen any in the wild, but let's avoid writing
From 09448540a61d1e735f527d55a2a0bc7b2e1aa01e Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sun, 22 Feb 2015 14:58:43 +0000
Subject: [PATCH 15/25] Print opcode name in initialiser error message
---
.../spongepowered/asm/mixin/transformer/MixinTransformer.java | 3 ++-
src/main/java/org/spongepowered/asm/util/ASMHelper.java | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 36764275..320e7a4f 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -756,7 +756,8 @@ public class MixinTransformer extends TreeTransformer {
if (opcode == ivalidOp) {
// At the moment I don't handle any transient locals because I haven't seen any in the wild, but let's avoid writing
// code which will likely break things and fix it if a real test case ever appears
- throw new InvalidMixinException("Cannot handle opcode 0x" + Integer.toHexString(opcode) + " in class initialiser");
+ throw new InvalidMixinException("Cannot handle " + ASMHelper.getOpcodeName(opcode) +" opcode (0x"
+ + Integer.toHexString(opcode).toUpperCase() + ") in class initialiser");
}
}
diff --git a/src/main/java/org/spongepowered/asm/util/ASMHelper.java b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
index b3f719df..1a432c3d 100644
--- a/src/main/java/org/spongepowered/asm/util/ASMHelper.java
+++ b/src/main/java/org/spongepowered/asm/util/ASMHelper.java
@@ -406,7 +406,7 @@ public class ASMHelper {
* @return Approximate opcode name (approximate because some constants in
* the {@link Opcodes} class have the same value as opcodes
*/
- private static String getOpcodeName(int opcode) {
+ public static String getOpcodeName(int opcode) {
if (opcode > 0) {
boolean found = false;
From 67e33532c2e5f29a8f08a68817a8b18621077c1d Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sun, 22 Feb 2015 17:49:56 +0000
Subject: [PATCH 16/25] Add basic "imaginary super" support
---
.../spongepowered/asm/mixin/SoftOverride.java | 41 ++++++++
.../mixin/transformer/MixinTargetContext.java | 93 +++++++++++++++++--
.../mixin/transformer/MixinTransformer.java | 10 +-
3 files changed, 131 insertions(+), 13 deletions(-)
create mode 100644 src/main/java/org/spongepowered/asm/mixin/SoftOverride.java
diff --git a/src/main/java/org/spongepowered/asm/mixin/SoftOverride.java b/src/main/java/org/spongepowered/asm/mixin/SoftOverride.java
new file mode 100644
index 00000000..2be3016a
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/SoftOverride.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.mixin;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * Decorator for methods which override a method in a supermixin which the
+ * containing mixin does not directly extend
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.CLASS)
+public @interface SoftOverride {
+
+}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index ac8667d0..f354c590 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -40,10 +40,12 @@ import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.MixinTransformerError;
+import org.spongepowered.asm.mixin.SoftOverride;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
+import org.spongepowered.asm.util.ASMHelper;
/**
@@ -57,6 +59,7 @@ import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
public class MixinTargetContext implements IReferenceMapperContext {
private static final String INIT = "";
+ private static final String IMAGINARY_SUPER = "super$";
/**
* Mixin info
@@ -193,9 +196,21 @@ public class MixinTargetContext implements IReferenceMapperContext {
* appropriate target type
*
* @param field Field to transform
+ * @return true if the field should be processed further, false to remove it
*/
- public void transformField(FieldNode field) {
+ public boolean transformField(FieldNode field) {
+ if (MixinTargetContext.IMAGINARY_SUPER.equals(field.name)) {
+ if (field.access != Opcodes.ACC_PRIVATE) {
+ throw new InvalidMixinException("Imaginary super field " + field.name + " must be private and non-final");
+ }
+ if (!field.desc.equals("L" + this.mixin.getClassRef() + ";")) {
+ throw new InvalidMixinException("Imaginary super field " + field.name + " must have the same type as the parent mixin");
+ }
+ return false;
+ }
+
this.transformDescriptor(field);
+ return true;
}
/**
@@ -207,6 +222,15 @@ public class MixinTargetContext implements IReferenceMapperContext {
* @param method Method to transform
*/
public void transformMethod(MethodNode method) {
+ // Any method tagged with @SoftOverride must have an implementation visible from
+ if (ASMHelper.getInvisibleAnnotation(method, SoftOverride.class) != null) {
+ Method superMethod = this.targetClassInfo.findMethodInHierarchy(method.name, method.desc, false, Traversal.SUPER);
+ if (superMethod == null || !superMethod.isInjected()) {
+ throw new InvalidMixinException("Mixin method " + method.name + method.desc + " is tagged with @SoftOverride but no "
+ + "valid method was found in superclasses of " + this.targetClass.name);
+ }
+ }
+
this.transformDescriptor(method);
String fromClass = this.getClassRef();
@@ -222,10 +246,14 @@ public class MixinTargetContext implements IReferenceMapperContext {
if (methodInsn.owner.equals(fromClass)) {
methodInsn.owner = this.targetClass.name;
} else if (detached && methodInsn.getOpcode() == Opcodes.INVOKESPECIAL) {
- this.updateStaticBindings(this.targetClass, this, method, methodInsn);
+ this.updateStaticBindings(method, methodInsn);
}
} else if (insn instanceof FieldInsnNode) {
FieldInsnNode fieldInsn = (FieldInsnNode)insn;
+ if (MixinTargetContext.IMAGINARY_SUPER.equals(fieldInsn.name)) {
+ this.processImaginarySuper(method, fieldInsn);
+ iter.remove();
+ }
this.transformDescriptor(fieldInsn);
if (fieldInsn.owner.equals(fromClass)) {
fieldInsn.owner = this.targetClass.name;
@@ -236,30 +264,75 @@ public class MixinTargetContext implements IReferenceMapperContext {
}
}
+ /**
+ * Handle "imaginary super" invokations, these are invokations in
+ * non-derived mixins for accessing methods known to exist in a supermixin
+ * which is not directly inherited by this mixix. The method can only call
+ * its own super-implmentation and the methd must also be tagged with
+ * {@link SoftOverride} to indicate that the method must exist in a super
+ * class.
+ *
+ * @param method Method being processed
+ * @param fieldInsn the GETFIELD insn which access the pseudo-field which is
+ * used as a handle to the superclass
+ */
+ private void processImaginarySuper(MethodNode method, FieldInsnNode fieldInsn) {
+ if (fieldInsn.getOpcode() != Opcodes.GETFIELD) {
+ if (MixinTargetContext.INIT.equals(method.name)) {
+ throw new InvalidMixinException("Illegal imaginary super declaration: field " + fieldInsn.name
+ + " must not specify an initialiser");
+ }
+
+ throw new InvalidMixinException("Illegal imaginary super access: found " + ASMHelper.getOpcodeName(fieldInsn.getOpcode())
+ + " opcode in " + method.name + method.desc);
+ }
+
+ if ((method.access & Opcodes.ACC_PRIVATE) != 0 || (method.access & Opcodes.ACC_STATIC) != 0) {
+ throw new InvalidMixinException("Illegal imaginary super access: method " + method.name + method.desc
+ + " is private or static");
+ }
+
+ if (ASMHelper.getInvisibleAnnotation(method, SoftOverride.class) == null) {
+ throw new InvalidMixinException("Illegal imaginary super access: method " + method.name + method.desc
+ + " is not decorated with @SoftOverride");
+ }
+
+ for (Iterator methodIter = method.instructions.iterator(method.instructions.indexOf(fieldInsn)); methodIter.hasNext();) {
+ AbstractInsnNode insn = methodIter.next();
+ if (insn instanceof MethodInsnNode) {
+ MethodInsnNode methodNode = (MethodInsnNode)insn;
+ if (methodNode.owner.equals(this.getClassRef()) && methodNode.name.equals(method.name) && methodNode.desc.equals(method.desc)) {
+ methodNode.setOpcode(Opcodes.INVOKESPECIAL);
+ this.updateStaticBindings(method, methodNode);
+ return;
+ }
+ }
+ }
+
+ throw new InvalidMixinException("Illegal imaginary super access: could not find INVOKE for " + method.name + method.desc);
+ }
+
/**
* Update INVOKESPECIAL opcodes to target the topmost class in the hierarchy
* which contains the specified method.
*
- * @param targetClass
- * @param mixin
* @param method
* @param insn
*/
- private void updateStaticBindings(ClassNode targetClass, MixinTargetContext mixin, MethodNode method, MethodInsnNode insn) {
- if (INIT.equals(method.name) || insn.owner.equals(targetClass.name) || targetClass.name.startsWith("<")) {
+ private void updateStaticBindings(MethodNode method, MethodInsnNode insn) {
+ if (INIT.equals(method.name) || insn.owner.equals(this.targetClass.name) || this.targetClass.name.startsWith("<")) {
return;
}
- ClassInfo targetClassInfo = ClassInfo.forName(targetClass.name);
- Method superMethod = targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
+ Method superMethod = this.targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
if (superMethod != null) {
if (superMethod.getOwner().isMixin()) {
- throw new InvalidMixinException("Invalid INVOKESPECIAL in " + mixin + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ throw new InvalidMixinException("Invalid INVOKESPECIAL in " + this + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ " for " + insn.name + insn.desc);
}
insn.owner = superMethod.getOwner().getName();
} else if (ClassInfo.forName(insn.owner).isMixin()) {
- throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + mixin);
+ throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + this);
}
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 320e7a4f..0bbeed0b 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -446,10 +446,14 @@ public class MixinTransformer extends TreeTransformer {
* @param mixin
*/
private void applyMixinFields(ClassNode targetClass, MixinTargetContext mixin) {
- for (FieldNode field : mixin.getClassNode().fields) {
+ for (Iterator iter = mixin.getClassNode().fields.iterator(); iter.hasNext();) {
+ FieldNode field = iter.next();
AnnotationNode shadow = ASMHelper.getVisibleAnnotation(field, Shadow.class);
this.validateField(mixin, field, shadow);
- mixin.transformField(field);
+ if (!mixin.transformField(field)) {
+ iter.remove();
+ continue;
+ }
FieldNode target = this.findTargetField(targetClass, field);
if (target == null) {
@@ -517,7 +521,7 @@ public class MixinTransformer extends TreeTransformer {
throw new InvalidMixinException(
String.format("Mixin classes cannot contain visible static methods or fields, found %s", mixinMethod.name));
}
-
+
this.mergeMethod(targetClass, mixin, mixinMethod, isOverwrite);
} else if (MixinTransformer.CLINIT.equals(mixinMethod.name)) {
// Class initialiser insns get appended
From 9afaa6ba0f147db803b13aa6779b007260b24b6a Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sun, 22 Feb 2015 21:30:18 +0000
Subject: [PATCH 17/25] Remove order-sensitivity in MixinConfig
---
.../asm/mixin/transformer/MixinConfig.java | 28 +++++++++++++++++
.../asm/mixin/transformer/MixinInfo.java | 31 +++++++++++++------
2 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
index 4cf6821f..8459c4a1 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
@@ -28,6 +28,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -71,6 +72,11 @@ class MixinConfig implements Comparable {
*/
private final transient Map> mixinMapping = new HashMap>();
+ /**
+ * All mixins loaded by this config
+ */
+ private final transient List mixins = new ArrayList();
+
/**
* Configuration priority
*/
@@ -237,6 +243,27 @@ class MixinConfig implements Comparable {
List pluginMixins = this.plugin.getMixins();
this.initialiseMixins(pluginMixins, true);
}
+
+ for (Iterator iter = this.mixins.iterator(); iter.hasNext();) {
+ MixinInfo mixin = iter.next();
+ try {
+ mixin.validate();
+ } catch (Exception ex) {
+ this.logger.error(ex.getMessage(), ex);
+ this.removeMixin(mixin);
+ iter.remove();
+ }
+ }
+ }
+
+ private void removeMixin(MixinInfo remove) {
+ for (List mixinsFor : this.mixinMapping.values()) {
+ for (Iterator iter = mixinsFor.iterator(); iter.hasNext();) {
+ if (remove == iter.next()) {
+ iter.remove();
+ }
+ }
+ }
}
private void initialiseMixins(List mixinClasses, boolean suppressPlugin) {
@@ -256,6 +283,7 @@ class MixinConfig implements Comparable {
for (String targetClass : mixin.getTargetClasses()) {
this.mixinsFor(targetClass.replace('/', '.')).add(mixin);
}
+ this.mixins.add(mixin);
}
} catch (Exception ex) {
this.logger.error(ex.getMessage(), ex);
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
index 9d0619ff..2778638c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
@@ -115,12 +115,6 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
*/
private final List targetClassNames;
- /**
- * True if the superclass of the mixin is not the direct superclass
- * of one or more targets
- */
- private final boolean detachedSuper;
-
/**
* Intrinsic order (for sorting mixins with identical priority)
*/
@@ -145,6 +139,18 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
* Interfaces soft-implemented using {@link Implements}
*/
private final transient List softImplements = new ArrayList();
+
+ /**
+ * Initial ClassNode created for mixin validation, not used for actual
+ * application
+ */
+ private ClassNode validationClassNode;
+
+ /**
+ * True if the superclass of the mixin is not the direct superclass
+ * of one or more targets
+ */
+ private boolean detachedSuper;
/**
* Internal ctor, called by {@link MixinConfig}
@@ -171,10 +177,15 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
this.priority = this.readPriority(classNode);
this.targetClasses = this.readTargetClasses(classNode, suppressPlugin);
this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
- this.detachedSuper = this.validateTargetClasses(classNode);
- this.validateMixin(classNode);
- this.readImplementations(classNode);
- this.prepare(classNode);
+ this.validationClassNode = classNode;
+ }
+
+ void validate() {
+ this.detachedSuper = this.validateTargetClasses(this.validationClassNode);
+ this.validateMixin(this.validationClassNode);
+ this.readImplementations(this.validationClassNode);
+ this.prepare(this.validationClassNode);
+ this.validationClassNode = null;
}
/**
From 1eab9929bb885fdf9ce5c0d303065b56fe0aabc2 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Fri, 27 Feb 2015 17:58:19 +0000
Subject: [PATCH 18/25] Add concept of version to mixin config, for forward
compatibility checks
---
checkstyle.xml | 2 +-
.../asm/launch/MixinBootstrap.java | 8 +-
.../asm/launch/MixinInitialisationError.java | 47 ++++
.../asm/mixin/MixinEnvironment.java | 4 +
.../asm/mixin/transformer/MixinConfig.java | 33 ++-
.../mixin/transformer/MixinTransformer.java | 7 +-
.../spongepowered/asm/util/VersionNumber.java | 213 ++++++++++++++++++
7 files changed, 306 insertions(+), 8 deletions(-)
create mode 100644 src/main/java/org/spongepowered/asm/launch/MixinInitialisationError.java
create mode 100644 src/main/java/org/spongepowered/asm/util/VersionNumber.java
diff --git a/checkstyle.xml b/checkstyle.xml
index 95d53e93..25b8ebfd 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -51,7 +51,7 @@
-
+
diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java
index e7fe725f..b5760fdb 100644
--- a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java
+++ b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java
@@ -31,7 +31,7 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
public abstract class MixinBootstrap {
- public static final String VERSION = "0.1";
+ public static final String VERSION = "0.2";
public static final String INIT_KEY = "mixin.initialised";
public static final String MIXIN_PACKAGE = "org.spongepowered.asm.mixin.";
@@ -52,6 +52,12 @@ public abstract class MixinBootstrap {
private MixinBootstrap() {}
public static void init() {
+ Object registeredVersion = Launch.blackboard.get(MixinBootstrap.INIT_KEY);
+ if (registeredVersion != null && !registeredVersion.equals(MixinBootstrap.VERSION)) {
+ throw new MixinInitialisationError("Mixin subsystem version " + registeredVersion
+ + " was already initialised. Cannot bootstrap version " + MixinBootstrap.VERSION);
+ }
+
Launch.blackboard.put(MixinBootstrap.INIT_KEY, MixinBootstrap.VERSION);
MixinEnvironment.getCurrentEnvironment();
}
diff --git a/src/main/java/org/spongepowered/asm/launch/MixinInitialisationError.java b/src/main/java/org/spongepowered/asm/launch/MixinInitialisationError.java
new file mode 100644
index 00000000..44effb89
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/launch/MixinInitialisationError.java
@@ -0,0 +1,47 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.launch;
+
+
+public class MixinInitialisationError extends Error {
+
+ private static final long serialVersionUID = 1L;
+
+ public MixinInitialisationError() {
+ }
+
+ public MixinInitialisationError(String message) {
+ super(message);
+ }
+
+ public MixinInitialisationError(Throwable cause) {
+ super(cause);
+ }
+
+ public MixinInitialisationError(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
index 43d42a61..7d348369 100644
--- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
+++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
@@ -180,6 +180,10 @@ public class MixinEnvironment {
return this.side != null ? this.side : Side.UNKNOWN;
}
+
+ public String getVersion() {
+ return (String)Launch.blackboard.get(MixinBootstrap.INIT_KEY);
+ }
public static MixinEnvironment getCurrentEnvironment() {
if (MixinEnvironment.env == null) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
index 8459c4a1..218e46d7 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
@@ -42,6 +42,7 @@ import org.apache.logging.log4j.core.helpers.Booleans;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
+import org.spongepowered.asm.util.VersionNumber;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
@@ -77,6 +78,13 @@ class MixinConfig implements Comparable {
*/
private final transient List mixins = new ArrayList();
+ /**
+ * Minimum version of the mixin subsystem required to correctly apply mixins
+ * in this configuration.
+ */
+ @SerializedName("minVersion")
+ private String version;
+
/**
* Configuration priority
*/
@@ -165,11 +173,24 @@ class MixinConfig implements Comparable {
private MixinConfig() {}
/**
- * Called immediately after deserialisation
+ * Called immediately after deserialisation
+ *
+ * @param name Mixin config name
+ * @return true if the config was successfully initialised and should be
+ * returned, or false if initialisation failed and the config should
+ * be discarded
*/
- private void onLoad(String name) {
+ private boolean onLoad(String name) {
this.name = name;
+ VersionNumber minVersion = VersionNumber.parse(this.version);
+ VersionNumber curVersion = VersionNumber.parse(MixinEnvironment.getCurrentEnvironment().getVersion());
+ if (minVersion.compareTo(curVersion) > 0) {
+ this.logger.warn("Mixin config {} requires mixin subsystem version {} but {} was found. The mixin config will not be applied.",
+ this.name, minVersion, curVersion);
+ return false;
+ }
+
if (this.pluginClassName != null) {
try {
Class> pluginClass = Class.forName(this.pluginClassName, true, Launch.classLoader);
@@ -200,6 +221,8 @@ class MixinConfig implements Comparable {
this.refMapper = ReferenceMapper.read(this.refMapperConfig);
this.verboseLogging |= Booleans.parseBoolean(System.getProperty("mixin.debug.verbose"), false) | MixinTransformer.DEBUG_ALL;
+
+ return true;
}
/**
@@ -403,8 +426,10 @@ class MixinConfig implements Comparable {
static MixinConfig create(String configFile) {
try {
MixinConfig config = new Gson().fromJson(new InputStreamReader(Launch.classLoader.getResourceAsStream(configFile)), MixinConfig.class);
- config.onLoad(configFile);
- return config;
+ if (config.onLoad(configFile)) {
+ return config;
+ }
+ return null;
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalArgumentException(String.format("The specified configuration file '%s' was invalid or could not be read", configFile));
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 0bbeed0b..672470ed 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -214,7 +214,10 @@ public class MixinTransformer extends TreeTransformer {
if (configs != null) {
for (String configFile : configs) {
try {
- this.configs.add(MixinConfig.create(configFile));
+ MixinConfig config = MixinConfig.create(configFile);
+ if (config != null) {
+ this.configs.add(config);
+ }
} catch (Exception ex) {
this.logger.warn(String.format("Failed to load mixin config: %s", configFile), ex);
}
@@ -760,7 +763,7 @@ public class MixinTransformer extends TreeTransformer {
if (opcode == ivalidOp) {
// At the moment I don't handle any transient locals because I haven't seen any in the wild, but let's avoid writing
// code which will likely break things and fix it if a real test case ever appears
- throw new InvalidMixinException("Cannot handle " + ASMHelper.getOpcodeName(opcode) +" opcode (0x"
+ throw new InvalidMixinException("Cannot handle " + ASMHelper.getOpcodeName(opcode) + " opcode (0x"
+ Integer.toHexString(opcode).toUpperCase() + ") in class initialiser");
}
}
diff --git a/src/main/java/org/spongepowered/asm/util/VersionNumber.java b/src/main/java/org/spongepowered/asm/util/VersionNumber.java
new file mode 100644
index 00000000..bc9d66a2
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/util/VersionNumber.java
@@ -0,0 +1,213 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.util;
+
+import java.io.Serializable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * Represents a software version number in major.minor.revision.build
+ * format as a sequence of four shorts packed into a long. This is to
+ * facilitate meaningful comparison between version numbers.
+ */
+public class VersionNumber implements Comparable, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Represents no version number or a version number which could not be
+ * parsed
+ */
+ public static final VersionNumber NONE = new VersionNumber();
+
+ /**
+ * Regex for matching a version number specified as a string
+ */
+ private static final Pattern versionNumberPattern =
+ Pattern.compile("^(\\d{1,5})(?:\\.(\\d{1,5})(?:\\.(\\d{1,5})(?:\\.(\\d{1,5}))?)?)?(-[a-zA-Z0-9_\\-]+)?$");
+
+ /**
+ * The version number, packed as four shorts into a long
+ */
+ private final long value;
+
+ /**
+ * suffix such as -BETA or -SNAPSHOT, must be prefixed with "-" to be
+ * matched
+ */
+ private final String suffix;
+
+ private VersionNumber() {
+ this.value = 0;
+ this.suffix = "";
+ }
+
+ private VersionNumber(short[] parts) {
+ this(parts, null);
+ }
+
+ private VersionNumber(short[] parts, String suffix) {
+ this.value = VersionNumber.pack(parts);
+ this.suffix = suffix != null ? suffix : "";
+ }
+
+ private VersionNumber(short major, short minor, short revision, short build) {
+ this(major, minor, revision, build, null);
+ }
+
+ private VersionNumber(short major, short minor, short revision, short build, String suffix) {
+ this.value = VersionNumber.pack(major, minor, revision, build);
+ this.suffix = suffix != null ? suffix : "";
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ short[] parts = VersionNumber.unpack(this.value);
+
+ return String.format("%d.%d%3$s%4$s%5$s",
+ parts[0],
+ parts[1],
+ (this.value & Integer.MAX_VALUE) > 0 ? String.format(".%d", parts[2]) : "",
+ (this.value & Short.MAX_VALUE) > 0 ? String.format(".%d", parts[3]) : "",
+ this.suffix);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(VersionNumber other) {
+ if (other == null) {
+ return 1;
+ }
+ long delta = this.value - other.value;
+ return delta > 0 ? 1 : delta < 0 ? -1 : 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof VersionNumber)) {
+ return false;
+ }
+
+ return ((VersionNumber)other).value == this.value;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return (int)(this.value >> 32) ^ (int)(this.value & 0xFFFFFFFF);
+ }
+
+ /**
+ * Packs the supplied array of shorts into a long
+ *
+ * @param shorts short values to pack
+ * @return supplied shorts packed into a long
+ */
+ private static long pack(short... shorts) {
+ return (long)shorts[0] << 48 | (long)shorts[1] << 32 | shorts[2] << 16 | shorts[3];
+ }
+
+ /**
+ * Unpacks a long into an array of four shorts
+ *
+ * @param along Long to unpack
+ * @return Unpacked array of four shorts
+ */
+ private static short[] unpack(long along) {
+ return new short[] {
+ (short)(along >> 48),
+ (short)(along >> 32 & Short.MAX_VALUE),
+ (short)(along >> 16 & Short.MAX_VALUE),
+ (short)(along & Short.MAX_VALUE)
+ };
+ }
+
+ /**
+ * Parse a version number specified as a string
+ *
+ * @param version Version number to parse
+ * @return Version number
+ */
+ public static final VersionNumber parse(String version) {
+ return VersionNumber.parse(version, VersionNumber.NONE);
+ }
+
+ /**
+ * Parse a version number specified as a string and return default if
+ * parsing fails
+ *
+ * @param version Version number to parse
+ * @param defaultVersion Version number to return if parse fails
+ * @return Version number
+ */
+ public static VersionNumber parse(String version, String defaultVersion) {
+ return VersionNumber.parse(version, VersionNumber.parse(defaultVersion));
+ }
+
+ /**
+ * Parse a version number specified as a string and return default if
+ * parsing fails
+ *
+ * @param version Version number to parse
+ * @param defaultVersion Version number to return if parse fails
+ * @return Version number
+ */
+ private static VersionNumber parse(String version, VersionNumber defaultVersion) {
+ if (version == null) {
+ return defaultVersion;
+ }
+
+ Matcher versionNumberPatternMatcher = VersionNumber.versionNumberPattern.matcher(version);
+ if (!versionNumberPatternMatcher.matches()) {
+ return defaultVersion;
+ }
+
+ short[] parts = new short[4];
+ for (int pos = 0; pos < 4; pos++) {
+ String part = versionNumberPatternMatcher.group(pos + 1);
+ if (part != null) {
+ int value = Integer.parseInt(part);
+ if (value > Short.MAX_VALUE) {
+ throw new IllegalArgumentException("Version parts cannot exceed " + Short.MAX_VALUE + ", found " + value);
+ }
+ parts[pos] = (short)value;
+ }
+ }
+
+ return new VersionNumber(parts, versionNumberPatternMatcher.group(5));
+ }
+}
From 8748534d18c8f8db7209e3393def72c2b4bdfc40 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sat, 28 Feb 2015 20:28:09 +0000
Subject: [PATCH 19/25] Add concept of "required" mixin configs and make their
failure critical
---
...xinException.java => MixinApplyError.java} | 15 +++--
.../org/spongepowered/asm/mixin/Shadow.java | 2 +
.../asm/mixin/injection/InjectionPoint.java | 13 ++--
.../injection/InvalidInjectionException.java | 28 ++++++--
.../injection/callback/CallbackInjector.java | 7 +-
.../asm/mixin/injection/code/Injector.java | 6 ++
.../injection/invoke/InvokeInjector.java | 4 +-
.../injection/invoke/ModifyArgInjector.java | 10 +--
.../injection/invoke/RedirectInjector.java | 2 +-
.../mixin/injection/struct/InjectionInfo.java | 20 ++++--
.../asm/mixin/transformer/InterfaceInfo.java | 24 ++++---
.../transformer/InvalidMixinException.java | 66 +++++++++++++++++++
.../asm/mixin/transformer/MixinConfig.java | 27 ++++++++
.../asm/mixin/transformer/MixinInfo.java | 23 +++----
.../mixin/transformer/MixinTargetContext.java | 29 ++++----
.../mixin/transformer/MixinTransformer.java | 42 +++++++-----
.../MixinTransformerError.java | 2 +-
17 files changed, 237 insertions(+), 83 deletions(-)
rename src/main/java/org/spongepowered/asm/mixin/{InvalidMixinException.java => MixinApplyError.java} (82%)
create mode 100644 src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java
rename src/main/java/org/spongepowered/asm/mixin/{ => transformer}/MixinTransformerError.java (97%)
diff --git a/src/main/java/org/spongepowered/asm/mixin/InvalidMixinException.java b/src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java
similarity index 82%
rename from src/main/java/org/spongepowered/asm/mixin/InvalidMixinException.java
rename to src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java
index 84574a2e..8ecb80f5 100644
--- a/src/main/java/org/spongepowered/asm/mixin/InvalidMixinException.java
+++ b/src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java
@@ -24,19 +24,24 @@
*/
package org.spongepowered.asm.mixin;
-public class InvalidMixinException extends RuntimeException {
+
+/**
+ * Error to throw for required mixins when mixing of the mixin fails
+ */
+public class MixinApplyError extends Error {
private static final long serialVersionUID = 1L;
- public InvalidMixinException(String message) {
+ public MixinApplyError(String message) {
super(message);
}
- public InvalidMixinException(Throwable message) {
- super(message);
+ public MixinApplyError(Throwable cause) {
+ super(cause);
}
- public InvalidMixinException(String message, Throwable cause) {
+ public MixinApplyError(String message, Throwable cause) {
super(message, cause);
}
+
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/Shadow.java b/src/main/java/org/spongepowered/asm/mixin/Shadow.java
index c7805732..5002b391 100644
--- a/src/main/java/org/spongepowered/asm/mixin/Shadow.java
+++ b/src/main/java/org/spongepowered/asm/mixin/Shadow.java
@@ -29,6 +29,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.spongepowered.asm.mixin.transformer.InvalidMixinException;
+
/**
* Used to indicate a Mixin class member which is acting as a placeholder for a
* method or field in the target class
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 24f04f05..a9c5f1e8 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java
@@ -42,7 +42,7 @@ import org.spongepowered.asm.mixin.injection.points.BeforeStringInvoke;
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.transformer.IReferenceMapperContext;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
import com.google.common.base.Joiner;
@@ -295,7 +295,7 @@ public abstract class InjectionPoint {
* @return InjectionPoint parsed from the supplied data or null if parsing
* failed
*/
- public static InjectionPoint parse(IReferenceMapperContext mixin, At at) {
+ public static InjectionPoint parse(MixinTargetContext mixin, At at) {
return InjectionPoint.parse(mixin, at.value(), at.shift(), at.by(), Arrays.asList(at.args()), at.target(), at.ordinal(), at.opcode());
}
@@ -309,7 +309,7 @@ public abstract class InjectionPoint {
* @return InjectionPoint parsed from the supplied data or null if parsing
* failed
*/
- public static InjectionPoint parse(IReferenceMapperContext mixin, AnnotationNode node) {
+ public static InjectionPoint parse(MixinTargetContext mixin, AnnotationNode node) {
String at = ASMHelper.getAnnotationValue(node, "value");
List args = ASMHelper.>getAnnotationValue(node, "args");
String target = ASMHelper.getAnnotationValue(node, "target", "");
@@ -341,7 +341,7 @@ public abstract class InjectionPoint {
* @return InjectionPoint parsed from the supplied data or null if parsing
* failed
*/
- public static InjectionPoint parse(IReferenceMapperContext mixin, String at, At.Shift shift, int by,
+ public static InjectionPoint parse(MixinTargetContext mixin, String at, At.Shift shift, int by,
List args, String target, int ordinal, int opcode) {
InjectionPointData data = new InjectionPointData(mixin, args, target, ordinal, opcode);
InjectionPoint point = null;
@@ -367,10 +367,11 @@ public abstract class InjectionPoint {
ctor.setAccessible(true);
point = ctor.newInstance(data);
} catch (Exception ex) {
- throw new InvalidInjectionException("The specified class " + at + " could not be instanced or is not a valid InjectionPoint", ex);
+ throw new InvalidInjectionException(mixin, "The specified class " + at
+ + " could not be instanced or is not a valid InjectionPoint", ex);
}
} else {
- throw new InvalidInjectionException(at + " is not a valid injection point specifier");
+ throw new InvalidInjectionException(mixin, at + " is not a valid injection point specifier");
}
if (point != null) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java b/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java
index 985fe21f..f1ff9e3e 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java
@@ -24,23 +24,37 @@
*/
package org.spongepowered.asm.mixin.injection;
-import org.spongepowered.asm.mixin.InvalidMixinException;
+import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.transformer.InvalidMixinException;
+import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
public class InvalidInjectionException extends InvalidMixinException {
private static final long serialVersionUID = 1L;
- public InvalidInjectionException(String message) {
- super(message);
+ public InvalidInjectionException(MixinTargetContext mixin, String message) {
+ super(mixin, message);
}
- public InvalidInjectionException(Throwable cause) {
- super(cause);
+ public InvalidInjectionException(InjectionInfo info, String message) {
+ super(info.getContext(), message);
}
- public InvalidInjectionException(String message, Throwable cause) {
- super(message, cause);
+ public InvalidInjectionException(MixinTargetContext mixin, Throwable cause) {
+ super(mixin, cause);
}
+ public InvalidInjectionException(InjectionInfo info, Throwable cause) {
+ super(info.getContext(), cause);
+ }
+
+ public InvalidInjectionException(MixinTargetContext mixin, String message, Throwable cause) {
+ super(mixin, message, cause);
+ }
+
+ public InvalidInjectionException(InjectionInfo info, String message, Throwable cause) {
+ super(info.getContext(), message, cause);
+ }
+
}
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 3e569171..b7383a5a 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
@@ -85,13 +85,13 @@ public class CallbackInjector extends Injector {
@Override
protected void sanityCheck(Target target, List injectionPoints) {
if (ASMHelper.methodIsStatic(target.method) != this.isStatic) {
- throw new InvalidInjectionException("'static' modifier of callback method does not match target in " + this.methodNode.name);
+ throw new InvalidInjectionException(this.info, "'static' modifier of callback method does not match target in " + this.methodNode.name);
}
if (Injector.CTOR.equals(target.method.name)) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (!injectionPoint.getClass().equals(BeforeReturn.class)) {
- throw new InvalidInjectionException("Found injection point type " + injectionPoint.getClass().getSimpleName()
+ throw new InvalidInjectionException(this.info, "Found injection point type " + injectionPoint.getClass().getSimpleName()
+ " targetting a ctor in " + this.classNode.name + ". Only RETURN allowed for a ctor target");
}
}
@@ -142,7 +142,8 @@ public class CallbackInjector extends Injector {
// If it doesn't match, then cry
if (!callbackDescriptor.equals(this.methodNode.desc)) {
- throw new InvalidInjectionException("Invalid descriptor on callback: expected " + callbackDescriptor + " found " + this.methodNode.desc);
+ throw new InvalidInjectionException(this.info, "Invalid descriptor on callback: expected " + callbackDescriptor + " found "
+ + this.methodNode.desc);
}
// These two variables keep track of the (additional) stack size required for the two actions we're going to be injecting insns to perform,
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 1b033ec1..81e13d52 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
@@ -52,6 +52,11 @@ public abstract class Injector {
protected static final String CTOR = "";
+ /**
+ * Injection info
+ */
+ protected InjectionInfo info;
+
/**
* Class node
*/
@@ -74,6 +79,7 @@ public abstract class Injector {
*/
public Injector(InjectionInfo info) {
this(info.getClassNode(), info.getMethod());
+ this.info = info;
}
/**
diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
index ac20408e..2d605de5 100644
--- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
+++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java
@@ -74,7 +74,7 @@ public abstract class InvokeInjector extends Injector {
@Override
protected void sanityCheck(Target target, List injectionPoints) {
if (target.isStatic != this.isStatic) {
- throw new InvalidInjectionException("'static' modifier of callback method does not match target in " + this.methodNode.name);
+ throw new InvalidInjectionException(this.info, "'static' modifier of callback method does not match target in " + this.methodNode.name);
}
}
@@ -86,7 +86,7 @@ public abstract class InvokeInjector extends Injector {
@Override
protected void inject(Target target, AbstractInsnNode node) {
if (!(node instanceof MethodInsnNode)) {
- throw new InvalidInjectionException(this.annotationType + " annotation is targetting a non-method insn in " + target
+ throw new InvalidInjectionException(this.info, this.annotationType + " annotation is targetting a non-method insn in " + target
+ " in " + this.classNode.name);
}
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 5498ab2a..8710caa9 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
@@ -76,7 +76,7 @@ public class ModifyArgInjector extends InvokeInjector {
if (this.singleArgMode) {
if (!this.methodArgs[0].equals(this.returnType)) {
- throw new InvalidInjectionException("@ModifyArg return type must match the parameter type."
+ throw new InvalidInjectionException(this.info, "@ModifyArg return type must match the parameter type."
+ " ARG=" + this.methodArgs[0] + " RETURN=" + this.returnType);
}
}
@@ -118,7 +118,7 @@ public class ModifyArgInjector extends InvokeInjector {
*/
private int injectMultiArgHandler(Target target, Type[] args, int argIndex, InsnList insns) {
if (!Arrays.equals(args, this.methodArgs)) {
- throw new InvalidInjectionException("@ModifyArg method targets a method with an invalid signature "
+ throw new InvalidInjectionException(this.info, "@ModifyArg method targets a method with an invalid signature "
+ Injector.printArgs(args) + ", expected " + Injector.printArgs(this.methodArgs));
}
@@ -132,7 +132,7 @@ public class ModifyArgInjector extends InvokeInjector {
protected int findArgIndex(Target target, Type[] args) {
if (this.index > -1) {
if (this.index >= args.length || !args[this.index].equals(this.returnType)) {
- throw new InvalidInjectionException("Specified index " + this.index + " for @ModifyArg is invalid for args "
+ throw new InvalidInjectionException(this.info, "Specified index " + this.index + " for @ModifyArg is invalid for args "
+ Injector.printArgs(args) + ", expected " + this.returnType);
}
return this.index;
@@ -146,7 +146,7 @@ public class ModifyArgInjector extends InvokeInjector {
}
if (argIndex != -1) {
- throw new InvalidInjectionException("Found duplicate args with index [" + argIndex + ", " + arg + "] matching type "
+ throw new InvalidInjectionException(this.info, "Found duplicate args with index [" + argIndex + ", " + arg + "] matching type "
+ this.returnType + " for @ModifyArg target " + target + " in " + this.classNode.name
+ ". Please specify index of desired arg.");
}
@@ -155,7 +155,7 @@ public class ModifyArgInjector extends InvokeInjector {
}
if (argIndex == -1) {
- throw new InvalidInjectionException("Could not find arg matching type " + this.returnType + " for @ModifyArg target "
+ throw new InvalidInjectionException(this.info, "Could not find arg matching type " + this.returnType + " for @ModifyArg target "
+ target + " in " + this.classNode.name);
}
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 f38ea73f..0fc4d711 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
@@ -90,7 +90,7 @@ public class RedirectInjector extends InvokeInjector {
if (alternateDesc.equals(this.methodNode.desc)) {
injectTargetParams = true;
} else {
- throw new InvalidInjectionException("@Redirect handler method has an invalid signature "
+ throw new InvalidInjectionException(this.info, "@Redirect handler method has an invalid signature "
+ ", expected " + desc + " found " + this.methodNode.desc);
}
}
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 0161905e..b88cb062 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
@@ -33,13 +33,13 @@ import java.util.List;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
-import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.InvalidInjectionException;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.code.Injector;
+import org.spongepowered.asm.mixin.transformer.InvalidMixinException;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
@@ -118,7 +118,7 @@ public abstract class InjectionInfo {
String method = ASMHelper.getAnnotationValue(this.annotation, "method");
if (method == null) {
- throw new InvalidInjectionException(type + " annotation on " + this.method.name + " is missing method name");
+ throw new InvalidInjectionException(this, type + " annotation on " + this.method.name + " is missing method name");
}
List ats = null;
@@ -129,20 +129,20 @@ public abstract class InjectionInfo {
ats = new ArrayList();
ats.add((AnnotationNode)atValue);
} else {
- throw new InvalidInjectionException(type + " annotation on " + this.method.name + " is missing 'at' value(s)");
+ throw new InvalidInjectionException(this, type + " annotation on " + this.method.name + " is missing 'at' value(s)");
}
MemberInfo targetMember = MemberInfo.parse(method, this.mixin);
if (targetMember.owner != null && !targetMember.owner.equals(this.mixin.getTargetClassRef())) {
- throw new InvalidInjectionException(type + " annotation on " + this.method.name + " specifies a target class '"
+ throw new InvalidInjectionException(this, type + " annotation on " + this.method.name + " specifies a target class '"
+ targetMember.owner + "', which is not supported");
}
this.findMethods(targetMember);
if (this.targets.size() == 0) {
- throw new InvalidInjectionException(type + " annotation on " + this.method.name + " could not find '" + targetMember.name + "'");
+ throw new InvalidInjectionException(this, type + " annotation on " + this.method.name + " could not find '" + targetMember.name + "'");
}
for (AnnotationNode at : ats) {
@@ -178,6 +178,13 @@ public abstract class InjectionInfo {
}
}
+ /**
+ * Get the mixin target context for this injection
+ */
+ public MixinTargetContext getContext() {
+ return this.mixin;
+ }
+
/**
* Get the annotation which this InjectionInfo was created from
*
@@ -241,7 +248,8 @@ public abstract class InjectionInfo {
try {
annotation = ASMHelper.getSingleVisibleAnnotation(method, Inject.class, ModifyArg.class, Redirect.class);
} catch (IllegalArgumentException ex) {
- throw new InvalidMixinException("Error parsing annotations on " + method.name + " in " + mixin.getClassName() + ": " + ex.getMessage());
+ throw new InvalidMixinException(mixin, "Error parsing annotations on " + method.name + " in " + mixin.getClassName() + ": "
+ + ex.getMessage());
}
if (annotation == null) {
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
index 340c2880..72af7c2c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
@@ -32,8 +32,6 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
-import org.spongepowered.asm.mixin.Implements;
-import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.util.ASMHelper;
@@ -43,6 +41,11 @@ import org.spongepowered.asm.util.ASMHelper;
*/
public class InterfaceInfo extends TreeInfo {
+ /**
+ * Parent mixin
+ */
+ private final MixinInfo mixin;
+
/**
* Prefix for interface methods. Any methods using this prefix must exist in
* the target interface
@@ -62,14 +65,16 @@ public class InterfaceInfo extends TreeInfo {
/**
* Make with the new thing already
*
+ * @param mixin Parent mixin
* @param prefix Method prefix
* @param iface Interface to load
*/
- private InterfaceInfo(String prefix, Type iface) {
+ private InterfaceInfo(MixinInfo mixin, String prefix, Type iface) {
if (prefix == null || prefix.length() < 2 || !prefix.endsWith("$")) {
- throw new InvalidMixinException(String.format("Prefix %s for iface %s is not valid", prefix, iface.toString()));
+ throw new InvalidMixinException(mixin, String.format("Prefix %s for iface %s is not valid", prefix, iface.toString()));
}
+ this.mixin = mixin;
this.prefix = prefix;
this.iface = iface;
}
@@ -94,7 +99,7 @@ public class InterfaceInfo extends TreeInfo {
ClassReader classReader = new ClassReader(TreeInfo.loadClass(ifaceName, true));
classReader.accept(ifaceNode, 0);
} catch (Exception ex) {
- throw new InvalidMixinException("An error was encountered parsing the interface " + this.iface.toString());
+ throw new InvalidMixinException(this.mixin, "An error was encountered parsing the interface " + this.iface.toString());
}
for (MethodNode ifaceMethod : ifaceNode.methods) {
@@ -156,7 +161,7 @@ public class InterfaceInfo extends TreeInfo {
String realName = method.name.substring(this.prefix.length());
String signature = realName + method.desc;
if (!this.methods.contains(signature)) {
- throw new InvalidMixinException(String.format("%s does not exist in target interface %s", realName, this.iface.toString()));
+ throw new InvalidMixinException(this.mixin, String.format("%s does not exist in target interface %s", realName, this.iface.toString()));
}
method.name = realName;
@@ -167,17 +172,18 @@ public class InterfaceInfo extends TreeInfo {
* Convert an {@link Interface} annotation node into an
* {@link InterfaceInfo}
*
+ * @param mixin Parent mixin
* @param node Annotation node to process
* @return parsed InterfaceInfo object
*/
- static InterfaceInfo fromAnnotation(AnnotationNode node) {
+ static InterfaceInfo fromAnnotation(MixinInfo mixin, AnnotationNode node) {
String prefix = ASMHelper.getAnnotationValue(node, "prefix");
Type iface = ASMHelper.getAnnotationValue(node, "iface");
if (prefix == null || iface == null) {
- throw new InvalidMixinException(String.format("@Interface annotation on is missing a required parameter"));
+ throw new InvalidMixinException(mixin, String.format("@Interface annotation on is missing a required parameter"));
}
- return new InterfaceInfo(prefix, iface);
+ return new InterfaceInfo(mixin, prefix, iface);
}
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java
new file mode 100644
index 00000000..e7d9ee98
--- /dev/null
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java
@@ -0,0 +1,66 @@
+/*
+ * This file is part of Sponge, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered.org
+ * 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.
+ */
+package org.spongepowered.asm.mixin.transformer;
+
+public class InvalidMixinException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final MixinInfo mixin;
+
+ public InvalidMixinException(MixinInfo mixin, String message) {
+ super(message);
+ this.mixin = mixin;
+ }
+
+ public InvalidMixinException(MixinTargetContext mixin, String message) {
+ super(message);
+ this.mixin = mixin.getInfo();
+ }
+
+ public InvalidMixinException(MixinInfo mixin, Throwable message) {
+ super(message);
+ this.mixin = mixin;
+ }
+
+ public InvalidMixinException(MixinTargetContext mixin, Throwable message) {
+ super(message);
+ this.mixin = mixin.getInfo();
+ }
+
+ public InvalidMixinException(MixinInfo mixin, String message, Throwable cause) {
+ super(message, cause);
+ this.mixin = mixin;
+ }
+
+ public InvalidMixinException(MixinTargetContext mixin, String message, Throwable cause) {
+ super(message, cause);
+ this.mixin = mixin.getInfo();
+ }
+
+ public MixinInfo getMixin() {
+ return this.mixin;
+ }
+}
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
index 218e46d7..d38e57c0 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java
@@ -39,6 +39,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.helpers.Booleans;
+import org.spongepowered.asm.launch.MixinInitialisationError;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
@@ -85,6 +86,14 @@ class MixinConfig implements Comparable {
@SerializedName("minVersion")
private String version;
+ /**
+ * Determines whether failures in this mixin config are considered terminal
+ * errors. Use this setting to indicate that failing to apply a mixin in
+ * this config is a critical error and should cause the game to shutdown.
+ */
+ @SerializedName("required")
+ private boolean required;
+
/**
* Configuration priority
*/
@@ -188,6 +197,11 @@ class MixinConfig implements Comparable {
if (minVersion.compareTo(curVersion) > 0) {
this.logger.warn("Mixin config {} requires mixin subsystem version {} but {} was found. The mixin config will not be applied.",
this.name, minVersion, curVersion);
+
+ if (this.required) {
+ throw new MixinInitialisationError("Required mixin config " + this.name + " requires mixin subsystem version " + minVersion);
+ }
+
return false;
}
@@ -313,6 +327,14 @@ class MixinConfig implements Comparable {
}
}
}
+
+ /**
+ * True if this mixin is required (failure to apply a defined mixin
+ * is an error condition).
+ */
+ public boolean isRequired() {
+ return this.required;
+ }
/**
* Get the name of the file from which this configuration object was
@@ -401,6 +423,11 @@ class MixinConfig implements Comparable {
}
return mixins;
}
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
index 2778638c..507a5c9e 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
@@ -49,7 +49,6 @@ import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.Implements;
-import org.spongepowered.asm.mixin.InvalidMixinException;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@@ -198,7 +197,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
private List readTargetClasses(ClassNode classNode, boolean suppressPlugin) {
AnnotationNode mixin = ASMHelper.getInvisibleAnnotation(classNode, Mixin.class);
if (mixin == null) {
- throw new InvalidMixinException(String.format("The mixin '%s' is missing an @Mixin annotation", this.className));
+ throw new InvalidMixinException(this, String.format("The mixin '%s' is missing an @Mixin annotation", this.className));
}
List targets = new ArrayList();
@@ -230,10 +229,11 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
if (this.plugin == null || suppressPlugin || this.plugin.shouldApplyMixin(targetClassName, this.className)) {
ClassInfo targetInfo = ClassInfo.forName(targetClassName);
if (targetInfo.isInterface()) {
- throw new InvalidMixinException("@Mixin target " + targetClassName + " is an interface in " + this);
+ throw new InvalidMixinException(this, "@Mixin target " + targetClassName + " is an interface in " + this);
}
if (checkPublic && targetInfo.isPublic()) {
- throw new InvalidMixinException("@Mixin target " + targetClassName + " is public in " + this + " and must be specified in value");
+ throw new InvalidMixinException(this, "@Mixin target " + targetClassName + " is public in " + this
+ + " and must be specified in value");
}
if (!outTargets.contains(targetInfo)) {
outTargets.add(targetInfo);
@@ -252,7 +252,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
private int readPriority(ClassNode classNode) {
AnnotationNode mixin = ASMHelper.getInvisibleAnnotation(classNode, Mixin.class);
if (mixin == null) {
- throw new InvalidMixinException(String.format("The mixin '%s' is missing an @Mixin annotation", this.className));
+ throw new InvalidMixinException(this, String.format("The mixin '%s' is missing an @Mixin annotation", this.className));
}
Integer priority = ASMHelper.getAnnotationValue(mixin, "priority");
@@ -269,7 +269,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
}
if (!targetClass.hasSuperClass(classNode.superName, ClassInfo.Traversal.NONE)) {
- throw new InvalidMixinException("Super class '" + classNode.superName.replace('/', '.') + "' of " + this.name
+ throw new InvalidMixinException(this, "Super class '" + classNode.superName.replace('/', '.') + "' of " + this.name
+ " was not found in the hierarchy of target class '" + targetClass + "'");
}
@@ -287,7 +287,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
private void validateMixin(ClassNode classNode) {
// isInner (shouldn't) return true for static inner classes
if (this.classInfo.isInner()) {
- throw new InvalidMixinException("Inner class mixin must be declared static");
+ throw new InvalidMixinException(this, "Inner class mixin must be declared static");
}
// Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names
@@ -300,7 +300,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
this.checkRemappable(Shadow.class, method.name, ASMHelper.getVisibleAnnotation(method, Shadow.class));
AnnotationNode overwrite = ASMHelper.getVisibleAnnotation(method, Overwrite.class);
if (overwrite != null && ((method.access & Opcodes.ACC_STATIC) == 0 || (method.access & Opcodes.ACC_PUBLIC) == 0)) {
- throw new InvalidMixinException("Found @Overwrite annotation on " + method.name + " in " + this);
+ throw new InvalidMixinException(this, "Found @Overwrite annotation on " + method.name + " in " + this);
}
}
}
@@ -308,7 +308,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
private void checkRemappable(Class annotationClass, String name, AnnotationNode annotation) {
if (annotation != null && ASMHelper.getAnnotationValue(annotation, "remap", Boolean.TRUE)) {
- throw new InvalidMixinException("Found a remappable @" + annotationClass.getSimpleName() + " annotation on " + name + " in " + this);
+ throw new InvalidMixinException(this, "Found a remappable @" + annotationClass.getSimpleName() + " annotation on " + name
+ + " in " + this);
}
}
@@ -338,7 +339,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
}
for (AnnotationNode interfaceNode : interfaces) {
- InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(interfaceNode);
+ InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(this, interfaceNode);
this.softImplements.add(interfaceInfo);
this.interfaces.add(interfaceInfo.getInternalName());
}
@@ -515,7 +516,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo {
throw new ClassNotFoundException(String.format("The specified mixin '%s' was not found", mixinClassName));
} catch (IOException ex) {
this.logger.warn("Failed to load mixin %s, the specified mixin will not be applied", mixinClassName);
- throw new InvalidMixinException("An error was encountered whilst loading the mixin class", ex);
+ throw new InvalidMixinException(this, "An error was encountered whilst loading the mixin class", ex);
}
// Inject the mixin class name into the LaunchClassLoader's invalid
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index f354c590..15ff52cf 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -38,8 +38,6 @@ import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;
-import org.spongepowered.asm.mixin.InvalidMixinException;
-import org.spongepowered.asm.mixin.MixinTransformerError;
import org.spongepowered.asm.mixin.SoftOverride;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.asm.mixin.injection.struct.Target;
@@ -184,7 +182,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
ClassInfo type = this.targetClassInfo.findCorrespondingType(mixin);
if (type == null) {
- throw new InvalidMixinException("Resolution error: unable to find corresponding type for "
+ throw new InvalidMixinException(this, "Resolution error: unable to find corresponding type for "
+ mixin + " in hierarchy of " + this.targetClassInfo);
}
@@ -201,10 +199,10 @@ public class MixinTargetContext implements IReferenceMapperContext {
public boolean transformField(FieldNode field) {
if (MixinTargetContext.IMAGINARY_SUPER.equals(field.name)) {
if (field.access != Opcodes.ACC_PRIVATE) {
- throw new InvalidMixinException("Imaginary super field " + field.name + " must be private and non-final");
+ throw new InvalidMixinException(this, "Imaginary super field " + field.name + " must be private and non-final");
}
if (!field.desc.equals("L" + this.mixin.getClassRef() + ";")) {
- throw new InvalidMixinException("Imaginary super field " + field.name + " must have the same type as the parent mixin");
+ throw new InvalidMixinException(this, "Imaginary super field " + field.name + " must have the same type as the parent mixin");
}
return false;
}
@@ -226,7 +224,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
if (ASMHelper.getInvisibleAnnotation(method, SoftOverride.class) != null) {
Method superMethod = this.targetClassInfo.findMethodInHierarchy(method.name, method.desc, false, Traversal.SUPER);
if (superMethod == null || !superMethod.isInjected()) {
- throw new InvalidMixinException("Mixin method " + method.name + method.desc + " is tagged with @SoftOverride but no "
+ throw new InvalidMixinException(this, "Mixin method " + method.name + method.desc + " is tagged with @SoftOverride but no "
+ "valid method was found in superclasses of " + this.targetClass.name);
}
}
@@ -279,21 +277,21 @@ public class MixinTargetContext implements IReferenceMapperContext {
private void processImaginarySuper(MethodNode method, FieldInsnNode fieldInsn) {
if (fieldInsn.getOpcode() != Opcodes.GETFIELD) {
if (MixinTargetContext.INIT.equals(method.name)) {
- throw new InvalidMixinException("Illegal imaginary super declaration: field " + fieldInsn.name
+ throw new InvalidMixinException(this, "Illegal imaginary super declaration: field " + fieldInsn.name
+ " must not specify an initialiser");
}
- throw new InvalidMixinException("Illegal imaginary super access: found " + ASMHelper.getOpcodeName(fieldInsn.getOpcode())
+ throw new InvalidMixinException(this, "Illegal imaginary super access: found " + ASMHelper.getOpcodeName(fieldInsn.getOpcode())
+ " opcode in " + method.name + method.desc);
}
if ((method.access & Opcodes.ACC_PRIVATE) != 0 || (method.access & Opcodes.ACC_STATIC) != 0) {
- throw new InvalidMixinException("Illegal imaginary super access: method " + method.name + method.desc
+ throw new InvalidMixinException(this, "Illegal imaginary super access: method " + method.name + method.desc
+ " is private or static");
}
if (ASMHelper.getInvisibleAnnotation(method, SoftOverride.class) == null) {
- throw new InvalidMixinException("Illegal imaginary super access: method " + method.name + method.desc
+ throw new InvalidMixinException(this, "Illegal imaginary super access: method " + method.name + method.desc
+ " is not decorated with @SoftOverride");
}
@@ -309,7 +307,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
}
}
- throw new InvalidMixinException("Illegal imaginary super access: could not find INVOKE for " + method.name + method.desc);
+ throw new InvalidMixinException(this, "Illegal imaginary super access: could not find INVOKE for " + method.name + method.desc);
}
/**
@@ -327,7 +325,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
Method superMethod = this.targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
if (superMethod != null) {
if (superMethod.getOwner().isMixin()) {
- throw new InvalidMixinException("Invalid INVOKESPECIAL in " + this + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ throw new InvalidMixinException(this, "Invalid INVOKESPECIAL in " + this + " resolved " + insn.owner + " -> " + superMethod.getOwner()
+ " for " + insn.name + insn.desc);
}
insn.owner = superMethod.getOwner().getName();
@@ -456,6 +454,13 @@ public class MixinTargetContext implements IReferenceMapperContext {
}
return target;
}
+
+ /**
+ * Get the mixin info for this mixin
+ */
+ MixinInfo getInfo() {
+ return this.mixin;
+ }
/**
* Get the mixin priority
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
index 672470ed..555b3655 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java
@@ -40,6 +40,7 @@ import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.Launch;
import org.apache.commons.io.FileUtils;
+import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.helpers.Booleans;
@@ -56,9 +57,8 @@ import org.objectweb.asm.tree.LineNumberNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.CheckClassAdapter;
-import org.spongepowered.asm.mixin.InvalidMixinException;
+import org.spongepowered.asm.mixin.MixinApplyError;
import org.spongepowered.asm.mixin.MixinEnvironment;
-import org.spongepowered.asm.mixin.MixinTransformerError;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
@@ -270,7 +270,14 @@ public class MixinTransformer extends TreeTransformer {
try {
basicClass = this.applyMixins(transformedName, basicClass, mixins);
} catch (InvalidMixinException th) {
- this.logger.warn(String.format("Class mixin failed: %s %s", th.getClass().getName(), th.getMessage()), th);
+ MixinConfig config = th.getMixin().getParent();
+ this.logger.log(config.isRequired() ? Level.FATAL : Level.WARN, String.format("Mixin failed applying %s -> %s: %s %s",
+ th.getMixin(), transformedName, th.getClass().getName(), th.getMessage()), th);
+
+ if (config.isRequired()) {
+ throw new MixinApplyError("Mixin [" + th.getMixin() + "] FAILED for REQUIRED config [" + config + "]", th);
+ }
+
th.printStackTrace();
}
}
@@ -408,8 +415,10 @@ public class MixinTransformer extends TreeTransformer {
this.applyInitialisers(targetClass, mixin);
this.applyInjections(targetClass, mixin);
mixin.postApply(transformedName, targetClass);
+ } catch (InvalidMixinException ex) {
+ throw ex;
} catch (Exception ex) {
- throw new InvalidMixinException("Unexpecteded error whilst applying the mixin class", ex);
+ throw new InvalidMixinException(mixin, "Unexpecteded error whilst applying the mixin class", ex);
}
}
@@ -462,7 +471,7 @@ public class MixinTransformer extends TreeTransformer {
if (target == null) {
// If this field is a shadow field but is NOT found in the target class, that's bad, mmkay
if (shadow != null) {
- throw new InvalidMixinException(String.format("Shadow field %s was not located in the target class", field.name));
+ throw new InvalidMixinException(mixin, String.format("Shadow field %s was not located in the target class", field.name));
}
// This is just a local field, so add it
@@ -470,7 +479,7 @@ public class MixinTransformer extends TreeTransformer {
} else {
// Check that the shadow field has a matching descriptor
if (!target.desc.equals(field.desc)) {
- throw new InvalidMixinException(String.format("The field %s in the target class has a conflicting signature", field.name));
+ throw new InvalidMixinException(mixin, String.format("The field %s in the target class has a conflicting signature", field.name));
}
}
}
@@ -485,13 +494,15 @@ public class MixinTransformer extends TreeTransformer {
private void validateField(MixinTargetContext mixin, FieldNode field, AnnotationNode shadow) {
// Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition
if (MixinTransformer.hasFlag(field, Opcodes.ACC_STATIC) && !MixinTransformer.hasFlag(field, Opcodes.ACC_PRIVATE)) {
- throw new InvalidMixinException(String.format("Mixin classes cannot contain visible static methods or fields, found %s", field.name));
+ throw new InvalidMixinException(mixin, String.format("Mixin classes cannot contain visible static methods or fields, found %s",
+ field.name));
}
// Shadow fields can't have prefixes, it's meaningless for them anyway
String prefix = ASMHelper.getAnnotationValue(shadow, "prefix", Shadow.class);
if (field.name.startsWith(prefix)) {
- throw new InvalidMixinException(String.format("Shadow field %s in %s has a shadow prefix. This is not allowed.", field.name, mixin));
+ throw new InvalidMixinException(mixin, String.format("Shadow field %s in %s has a shadow prefix. This is not allowed.",
+ field.name, mixin));
}
}
@@ -514,14 +525,14 @@ public class MixinTransformer extends TreeTransformer {
// For shadow (and abstract, which can be used as a shorthand for Shadow) methods, we just check they're present
MethodNode target = this.findTargetMethod(targetClass, mixinMethod);
if (target == null) {
- throw new InvalidMixinException(String.format("Shadow method %s was not located in the target class", mixinMethod.name));
+ throw new InvalidMixinException(mixin, String.format("Shadow method %s was not located in the target class", mixinMethod.name));
}
} else if (!mixinMethod.name.startsWith("<")) {
if (MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_STATIC)
&& !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE)
&& !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_SYNTHETIC)
&& !isOverwrite) {
- throw new InvalidMixinException(
+ throw new InvalidMixinException(mixin,
String.format("Mixin classes cannot contain visible static methods or fields, found %s", mixinMethod.name));
}
@@ -565,7 +576,7 @@ public class MixinTransformer extends TreeTransformer {
targetClass.methods.remove(target);
} else if (isOverwrite) {
- throw new InvalidMixinException(String.format("Overwrite target %s was not located in the target class", method.name));
+ throw new InvalidMixinException(mixin, String.format("Overwrite target %s was not located in the target class", method.name));
}
targetClass.methods.add(method);
@@ -639,7 +650,7 @@ public class MixinTransformer extends TreeTransformer {
}
// Find the initialiser instructions in the candidate ctor
- InsnList initialiser = this.getInitialiser(ctor);
+ InsnList initialiser = this.getInitialiser(mixin, ctor);
if (initialiser == null || initialiser.size() == 0) {
return;
}
@@ -720,7 +731,7 @@ public class MixinTransformer extends TreeTransformer {
* @return initialiser bytecode extracted from the supplied constructor, or
* null if the constructor range could not be parsed
*/
- private InsnList getInitialiser(MethodNode ctor) {
+ private InsnList getInitialiser(MixinTargetContext mixin, MethodNode ctor) {
// Find the range of line numbers which corresponds to the constructor body
Range init = this.getConstructorRange(ctor);
if (!init.isValid()) {
@@ -763,7 +774,7 @@ public class MixinTransformer extends TreeTransformer {
if (opcode == ivalidOp) {
// At the moment I don't handle any transient locals because I haven't seen any in the wild, but let's avoid writing
// code which will likely break things and fix it if a real test case ever appears
- throw new InvalidMixinException("Cannot handle " + ASMHelper.getOpcodeName(opcode) + " opcode (0x"
+ throw new InvalidMixinException(mixin, "Cannot handle " + ASMHelper.getOpcodeName(opcode) + " opcode (0x"
+ Integer.toHexString(opcode).toUpperCase() + ") in class initialiser");
}
}
@@ -777,7 +788,8 @@ public class MixinTransformer extends TreeTransformer {
AbstractInsnNode last = initialiser.getLast();
if (last != null) {
if (last.getOpcode() != Opcodes.PUTFIELD) {
- throw new InvalidMixinException("Could not parse initialiser, expected 0xB5, found 0x" + Integer.toHexString(last.getOpcode()));
+ throw new InvalidMixinException(mixin, "Could not parse initialiser, expected 0xB5, found 0x"
+ + Integer.toHexString(last.getOpcode()));
}
}
diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java
similarity index 97%
rename from src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java
rename to src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java
index 80585b28..bc3ea3d4 100644
--- a/src/main/java/org/spongepowered/asm/mixin/MixinTransformerError.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java
@@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package org.spongepowered.asm.mixin;
+package org.spongepowered.asm.mixin.transformer;
/**
From 02aa220a36f4adc0c5ba44cd106b0d09ef335fc5 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sun, 1 Mar 2015 20:25:36 +0000
Subject: [PATCH 20/25] Improve handling of TypeInsns and INVOKEVIRTUAL in
mixins, closes #21
---
.../asm/mixin/transformer/ClassInfo.java | 25 ++++++++
.../mixin/transformer/MixinTargetContext.java | 57 +++++++++++++------
2 files changed, 65 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
index 9979c5c9..3f73578c 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java
@@ -664,6 +664,31 @@ class ClassInfo extends TreeInfo {
return false;
}
+
+ /**
+ * Find out whether this (non-mixin) class has a mixin targetting
+ * any of its superclasses. This method always returns false for
+ * mixin classes.
+ *
+ * @return true if and only if one or more classes in this class's hierarchy
+ * are targetted by a mixin
+ */
+ public boolean hasMixinTargetInHierarchy() {
+ if (this.isMixin) {
+ return false;
+ }
+
+ ClassInfo superClass = this.getSuperClass();
+
+ while (superClass != null && superClass != ClassInfo.OBJECT) {
+ if (superClass.mixins.size() > 0) {
+ return true;
+ }
+ superClass = superClass.getSuperClass();
+ }
+
+ return false;
+ }
/**
* Finds the specified private or protected method in this class's hierarchy
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index 15ff52cf..d030c5c2 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -89,6 +89,11 @@ public class MixinTargetContext implements IReferenceMapperContext {
* True if this mixin inherits from a mixin at any point in its hierarchy
*/
private final boolean inheritsFromMixin;
+
+ /**
+ * True if this mixin's superclass is detached from the target superclass
+ */
+ private final boolean detachedSuper;
/**
* ctor
@@ -102,7 +107,8 @@ public class MixinTargetContext implements IReferenceMapperContext {
this.classNode = mixin;
this.targetClass = target;
this.targetClassInfo = ClassInfo.forName(target.name);
- this.inheritsFromMixin = info.getClassInfo().hasMixinInHierarchy();
+ this.inheritsFromMixin = info.getClassInfo().hasMixinInHierarchy() || this.targetClassInfo.hasMixinTargetInHierarchy();
+ this.detachedSuper = !this.getClassNode().superName.equals(this.targetClass.superName);
}
/* (non-Javadoc)
@@ -231,9 +237,6 @@ public class MixinTargetContext implements IReferenceMapperContext {
this.transformDescriptor(method);
- String fromClass = this.getClassRef();
- boolean detached = !this.getClassNode().superName.equals(this.targetClass.superName);
-
Iterator iter = method.instructions.iterator();
while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();
@@ -241,10 +244,14 @@ public class MixinTargetContext implements IReferenceMapperContext {
if (insn instanceof MethodInsnNode) {
MethodInsnNode methodInsn = (MethodInsnNode)insn;
this.transformDescriptor(methodInsn);
- if (methodInsn.owner.equals(fromClass)) {
+ if (methodInsn.owner.equals(this.getClassRef())) {
methodInsn.owner = this.targetClass.name;
- } else if (detached && methodInsn.getOpcode() == Opcodes.INVOKESPECIAL) {
- this.updateStaticBindings(method, methodInsn);
+ } else if ((this.detachedSuper || this.inheritsFromMixin)) {
+ if (methodInsn.getOpcode() == Opcodes.INVOKESPECIAL) {
+ this.updateStaticBinding(method, methodInsn);
+ } else if (methodInsn.getOpcode() == Opcodes.INVOKEVIRTUAL && ClassInfo.forName(methodInsn.owner).isMixin()) {
+ this.updateDynamicBinding(method, methodInsn);
+ }
}
} else if (insn instanceof FieldInsnNode) {
FieldInsnNode fieldInsn = (FieldInsnNode)insn;
@@ -253,7 +260,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
iter.remove();
}
this.transformDescriptor(fieldInsn);
- if (fieldInsn.owner.equals(fromClass)) {
+ if (fieldInsn.owner.equals(this.getClassRef())) {
fieldInsn.owner = this.targetClass.name;
}
} else if (insn instanceof TypeInsnNode) {
@@ -301,7 +308,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
MethodInsnNode methodNode = (MethodInsnNode)insn;
if (methodNode.owner.equals(this.getClassRef()) && methodNode.name.equals(method.name) && methodNode.desc.equals(method.desc)) {
methodNode.setOpcode(Opcodes.INVOKESPECIAL);
- this.updateStaticBindings(method, methodNode);
+ this.updateStaticBinding(method, methodNode);
return;
}
}
@@ -314,26 +321,42 @@ public class MixinTargetContext implements IReferenceMapperContext {
* Update INVOKESPECIAL opcodes to target the topmost class in the hierarchy
* which contains the specified method.
*
- * @param method
- * @param insn
+ * @param method Method containing the instruction
+ * @param insn INVOKE instruction node
*/
- private void updateStaticBindings(MethodNode method, MethodInsnNode insn) {
+ private void updateStaticBinding(MethodNode method, MethodInsnNode insn) {
+ this.updateBinding(method, insn, Traversal.SUPER);
+ }
+
+ /**
+ * Update INVOKEVIRTUAL opcodes to target the topmost class in the hierarchy
+ * which contains the specified method.
+ *
+ * @param method Method containing the instruction
+ * @param insn INVOKE instruction node
+ */
+ private void updateDynamicBinding(MethodNode method, MethodInsnNode insn) {
+ this.updateBinding(method, insn, Traversal.ALL);
+ }
+
+ private void updateBinding(MethodNode method, MethodInsnNode insn, Traversal traversal) {
if (INIT.equals(method.name) || insn.owner.equals(this.targetClass.name) || this.targetClass.name.startsWith("<")) {
return;
}
- Method superMethod = this.targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, false, Traversal.SUPER);
+ Method superMethod = this.targetClassInfo.findMethodInHierarchy(insn.name, insn.desc, traversal == Traversal.ALL, traversal);
if (superMethod != null) {
if (superMethod.getOwner().isMixin()) {
- throw new InvalidMixinException(this, "Invalid INVOKESPECIAL in " + this + " resolved " + insn.owner + " -> " + superMethod.getOwner()
- + " for " + insn.name + insn.desc);
+ throw new InvalidMixinException(this, "Invalid " + ASMHelper.getOpcodeName(insn) + " in " + this + " resolved " + insn.owner
+ + " -> " + superMethod.getOwner() + " for " + insn.name + insn.desc);
}
insn.owner = superMethod.getOwner().getName();
} else if (ClassInfo.forName(insn.owner).isMixin()) {
- throw new MixinTransformerError("Error resolving INVOKESPECIAL target for " + insn.owner + "." + insn.name + " in " + this);
+ throw new MixinTransformerError("Error resolving " + ASMHelper.getOpcodeName(insn) + " target for " + insn.owner + "." + insn.name
+ + " in " + this);
}
}
-
+
/**
* Transforms a field descriptor in the context of this mixin target
*
From c4a9fd48239b3c00fd06fea75020a2a36299bd55 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Sun, 1 Mar 2015 21:31:55 +0000
Subject: [PATCH 21/25] Add short-circuit check for TypeInsn remapping,
actually closes #21
---
.../asm/mixin/transformer/MixinTargetContext.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
index d030c5c2..70bb9be1 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java
@@ -264,7 +264,11 @@ public class MixinTargetContext implements IReferenceMapperContext {
fieldInsn.owner = this.targetClass.name;
}
} else if (insn instanceof TypeInsnNode) {
- this.transformDescriptor((TypeInsnNode)insn);
+ TypeInsnNode typeInsn = (TypeInsnNode)insn;
+ if (typeInsn.desc.equals(this.getClassRef())) {
+ typeInsn.desc = this.targetClass.name;
+ }
+ this.transformDescriptor(typeInsn);
}
}
}
From 1f06361863c3a46d9387f4b3935b498be9f3b1e8 Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Mon, 2 Mar 2015 12:11:00 +0000
Subject: [PATCH 22/25] Re-add import which was accidentally removed, fix JDK8
javadoc warnings
---
.../spongepowered/asm/mixin/injection/struct/InjectionInfo.java | 2 ++
.../org/spongepowered/asm/mixin/transformer/InterfaceInfo.java | 1 +
2 files changed, 3 insertions(+)
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 b88cb062..bb58dddf 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
@@ -180,6 +180,8 @@ public abstract class InjectionInfo {
/**
* Get the mixin target context for this injection
+ *
+ * @return the target context
*/
public MixinTargetContext getContext() {
return this.mixin;
diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
index 72af7c2c..b78452ae 100644
--- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
+++ b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java
@@ -32,6 +32,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
+import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.util.ASMHelper;
From c6a83b49d8b8dddae7bffe50b64dda52446d366e Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Mon, 2 Mar 2015 15:49:06 +0000
Subject: [PATCH 23/25] Update version in build script to 0.2
---
build.gradle | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/build.gradle b/build.gradle
index 15d8393b..62bd65a5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,7 +24,7 @@ defaultTasks 'licenseFormat', 'check', 'build'
// Basic project information
group = 'org.spongepowered'
archivesBaseName = 'mixin'
-version = '0.1-SNAPSHOT'
+version = '0.2-SNAPSHOT'
// Extended project information
ext.projectName = 'Mixin'
@@ -160,11 +160,17 @@ shadowJar {
include(dependency('net.minecraftforge.srg2source:Srg2Source'))
include(dependency('net.sf.jopt-simple:jopt-simple'))
}
- // classifier = new Date().format('yyyyMMddHHmmss') // for dev
classifier = 'processor'
}
build.dependsOn(shadowJar)
+// Run this task instead of build to generate a timestamped shadow jar (for dev)
+task timestamp(type: Jar, dependsOn: build) {
+ if (gradle.startParameter.taskNames.contains(name)) {
+ shadowJar.classifier = new Date().format('yyyyMMddHHmmss')
+ }
+}
+
task sourceJar(type: Jar) {
from sourceSets.main.java
from sourceSets.main.resources
From f0b44fa63fc4f2606df1df24f9d2f1fcfa0f42ff Mon Sep 17 00:00:00 2001
From: Mumfrey
Date: Mon, 2 Mar 2015 15:49:55 +0000
Subject: [PATCH 24/25] Update README.MD and add logo
---
README.MD | 73 +++++++++++++++++++++++++++++++++++++++++++++++---
docs/logo.png | Bin 0 -> 16238 bytes
2 files changed, 70 insertions(+), 3 deletions(-)
create mode 100644 docs/logo.png
diff --git a/README.MD b/README.MD
index 89bf9693..13734c03 100644
--- a/README.MD
+++ b/README.MD
@@ -1,4 +1,71 @@
-Mixin
-=====
+
-Mixin is a trait/mixin framework for Java using ASM. The main documentation can be found in the [Wiki](https://github.com/SpongePowered/Mixin/wiki)
+**Mixin** is a trait/mixin framework for Java using [ASM](http://asm.ow2.org/)
+and hooking into the runtime class-loading process via Mojang's
+[LegacyLauncher](https://github.com/Mojang/LegacyLauncher) system. The main
+documentation for **Mixin** can be found in the [Wiki](wiki).
+
+### Building Mixin
+**Mixin** uses the [Gradle](http://gradle.org/) build automation system. To
+perform a build simply execute
+
+ gradle
+
+from within the project root directory.
+
+### Integration with Eclipse IDE
+
+The **Mixin** project can be integrated easily with Eclipse using the [Gradle
+Plugin](http://marketplace.eclipse.org/content/gradle-integration-eclipse-44).
+Simply choose `Import` -> `Gradle Project` and follow the prompts.
+
+When developing using **Mixin**, you can use the **Mixin Annotation Processor**
+within Eclipse to provide context-sensitive errors and warnings to help you more
+easily troubleshoot your mixins. To do so:
+
+1. Run the `gradle build` command to generate the mixin jar
+2. Open the properties of your eclipse project and navigate to `Java Compiler`
+ -> `Annotation Processing` -> `Factory Path`
+3. Check the `Enable project specific settings` checkbox
+4. Click the `Add External JARs` button and select the generated mixin jar
+5. Navigate up one level to `Java Compiler` -> `Annotation Processing`
+6. Check the `Enable project specific settings` checkbox
+7. Check the `Enable annotation processing` checkbox
+8. Click the `New...` button next to the `Processor options` box
+ * Set `Key` to **reobfSrgFile**
+ * Set `Value` to the fully-qualified path to the `mcp-srg.srg` file
+9. Click `OK` to apply the changes
+
+### Version History
+
+
+
+
+ | Version |
+ Features / Changes |
+ Date |
+
+
+
+
+ | 0.1 |
+
+
+ - Basic Mixin Support
+ - Basic Injector Support
+ - Annotation Processor
+
+ |
+ January 2015 |
+
+
+ | 0.2 |
+
+
+ - Added supermixin support (mixins inheriting from other mixins)
+
+ |
+ March 2015 |
+
+
+
diff --git a/docs/logo.png b/docs/logo.png
new file mode 100644
index 0000000000000000000000000000000000000000..dece9a8ba36b21638d1c6eb6b84ea2307b67062e
GIT binary patch
literal 16238
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