Housekeeping

This commit is contained in:
Mumfrey committed 2016-02-02 13:21:02 +00:00
1 parent 1e7f351115
commit 19272e1170
28 files changed
+123 -97

No files matched your search

@@ -24,7 +24,6 @@
*/
package org.spongepowered.asm.launch;
public class MixinInitialisationError extends Error {
private static final long serialVersionUID = 1L;
@@ -680,12 +680,12 @@ public class MixinEnvironment implements ITokenProvider {
// Sanity check
Object version = this.getVersion();
if (version == null || !MixinBootstrap.VERSION.equals(version)) {
throw new RuntimeException("Environment conflict, mismatched versions or you didn't call MixinBootstrap.init()");
throw new MixinException("Environment conflict, mismatched versions or you didn't call MixinBootstrap.init()");
}
// Also sanity check
if (this.getClass().getClassLoader() != Launch.class.getClassLoader()) {
throw new RuntimeException("Attempted to init the mixin environment in the wrong classloader");
throw new MixinException("Attempted to init the mixin environment in the wrong classloader");
}
this.options = new boolean[Option.values().length];
@@ -152,7 +152,7 @@ public abstract class InjectionPoint {
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
boolean found = false;
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
ArrayList<AbstractInsnNode>[] allNodes = new ArrayList[this.components.length];
for (int i = 0; i < this.components.length; i++) {
@@ -260,7 +260,7 @@ public class CallbackInjector extends Injector {
return false; // No @Coerce specified, types must match
}
boolean canCoerce = CallbackInjector.canCoerce(inTypes[arg], myTypes[arg]);
boolean canCoerce = Injector.canCoerce(inTypes[arg], myTypes[arg]);
if (!canCoerce) {
return false; // Can't coerce source type to local type, give up
}
@@ -313,14 +313,14 @@ public class CallbackInjector extends Injector {
super.sanityCheck(target, injectionPoints);
if (ASMHelper.methodIsStatic(target.method) != this.isStatic) {
throw new InvalidInjectionException(this.info, "'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);
}
if (Injector.CTOR.equals(target.method.name)) {
if (Constants.CTOR.equals(target.method.name)) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (!injectionPoint.getClass().equals(BeforeReturn.class)) {
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");
+ " targetting a ctor in " + this + ". Only RETURN allowed for a ctor target");
}
}
}
@@ -434,8 +434,8 @@ public class CallbackInjector extends Injector {
int position = callback.target.method.instructions.indexOf(callback.node);
List<String> expected = CallbackInjector.summariseLocals(this.methodNode.desc, callback.target.arguments.length + 1);
List<String> found = CallbackInjector.summariseLocals(callback.getDescriptorWithAllLocals(), callback.frameSize);
String message = String.format("LVT in %s::%s has incompatible changes at opcode %d in callback %s%s.\nExpected: %s\n Found: %s",
this.classNode.name, callback.target.method.name, position, this.methodNode.name, this.methodNode.desc, expected, found);
String message = String.format("LVT in %s has incompatible changes at opcode %d in callback %s.\nExpected: %s\n Found: %s",
callback.target, position, this, expected, found);
return message;
}
@@ -455,7 +455,7 @@ public class CallbackInjector extends Injector {
insns.add(new TypeInsnNode(Opcodes.NEW, errorClass));
insns.add(new InsnNode(Opcodes.DUP));
insns.add(new LdcInsnNode(message));
insns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, errorClass, Constants.INIT, "(Ljava/lang/String;)V", false));
insns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, errorClass, Constants.CTOR, "(Ljava/lang/String;)V", false));
insns.add(new InsnNode(Opcodes.ATHROW));
return method;
}
@@ -552,10 +552,10 @@ public class CallbackInjector extends Injector {
if (callback.isAtReturn) {
callback.add(new VarInsnNode(callback.target.returnType.getOpcode(Opcodes.ILOAD), callback.marshallVar), true, !store);
callback.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
callback.target.callbackInfoClass, Injector.CTOR, CallbackInfo.getConstructorDescriptor(callback.target.returnType), false));
callback.target.callbackInfoClass, Constants.CTOR, CallbackInfo.getConstructorDescriptor(callback.target.returnType), false));
} else {
callback.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
callback.target.callbackInfoClass, Injector.CTOR, CallbackInfo.getConstructorDescriptor(), false));
callback.target.callbackInfoClass, Constants.CTOR, CallbackInfo.getConstructorDescriptor(), false));
}
}
@@ -656,21 +656,5 @@ public class CallbackInjector extends Injector {
}
return list;
}
public static boolean canCoerce(Type from, Type to) {
return CallbackInjector.canCoerce(from.getDescriptor(), to.getDescriptor());
}
public static boolean canCoerce(String from, String to) {
if (from.length() > 1 || to.length() > 1) {
return false;
}
return CallbackInjector.canCoerce(from.charAt(0), to.charAt(0));
}
public static boolean canCoerce(char from, char to) {
return to == 'I' && "IBSCZ".indexOf(from) > -1;
}
}
@@ -38,6 +38,7 @@ import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.InvalidInjectionException;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.util.ASMHelper;
@@ -48,8 +49,6 @@ import com.google.common.base.Joiner;
* Base class for bytecode injectors
*/
public abstract class Injector {
protected static final String CTOR = "<init>";
/**
* Injection info
@@ -104,6 +103,11 @@ public abstract class Injector {
this.returnType = Type.getReturnType(this.methodNode.desc);
this.isStatic = ASMHelper.methodIsStatic(this.methodNode);
}
@Override
public String toString() {
return String.format("%s::%s", this.classNode.name, this.methodNode.name);
}
/**
* Inject into the specified method at the specified injection points
@@ -152,7 +156,9 @@ public abstract class Injector {
}
protected void sanityCheck(Target target, List<InjectionPoint> injectionPoints) {
// stub for subclasses
if (target.classNode != this.classNode) {
throw new InvalidInjectionException(this.info, "Target class does not match injector class in " + this);
}
}
protected abstract void inject(Target target, AbstractInsnNode node);
@@ -183,4 +189,21 @@ public abstract class Injector {
protected static String printArgs(Type[] args) {
return "(" + Joiner.on("").join(args) + ")";
}
public static boolean canCoerce(Type from, Type to) {
return Injector.canCoerce(from.getDescriptor(), to.getDescriptor());
}
public static boolean canCoerce(String from, String to) {
if (from.length() > 1 || to.length() > 1) {
return false;
}
return Injector.canCoerce(from.charAt(0), to.charAt(0));
}
public static boolean canCoerce(char from, char to) {
return to == 'I' && "IBSCZ".indexOf(from) > -1;
}
}
@@ -64,7 +64,7 @@ public abstract class InvokeInjector extends Injector {
super.sanityCheck(target, injectionPoints);
if (target.isStatic != this.isStatic) {
throw new InvalidInjectionException(this.info, "'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);
}
}
@@ -77,7 +77,7 @@ public abstract class InvokeInjector extends Injector {
protected void inject(Target target, AbstractInsnNode node) {
if (!(node instanceof MethodInsnNode)) {
throw new InvalidInjectionException(this.info, this.annotationType + " annotation on is targetting a non-method insn in " + target
+ " in " + this.classNode.name + "/" + this.methodNode.name);
+ " in " + this);
}
this.inject(target, (MethodInsnNode)node);
@@ -76,7 +76,7 @@ public class ModifyArgInjector extends InvokeInjector {
if (this.singleArgMode) {
if (!this.methodArgs[0].equals(this.returnType)) {
throw new InvalidInjectionException(this.info, "@ModifyArg return type on " + this.methodNode.name + " must match the parameter type."
throw new InvalidInjectionException(this.info, "@ModifyArg return type on " + this + " must match the parameter type."
+ " ARG=" + this.methodArgs[0] + " RETURN=" + this.returnType);
}
}
@@ -118,8 +118,8 @@ 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(this.info, "@ModifyArg method " + this.methodNode.name + " targets a method with an invalid"
+ " signature " + Injector.printArgs(args) + ", expected " + Injector.printArgs(this.methodArgs));
throw new InvalidInjectionException(this.info, "@ModifyArg method " + this + " targets a method with an invalid signature "
+ Injector.printArgs(args) + ", expected " + Injector.printArgs(this.methodArgs));
}
int[] argMap = this.storeArgs(target, args, insns, 0);
@@ -133,7 +133,7 @@ public class ModifyArgInjector extends InvokeInjector {
if (this.index > -1) {
if (this.index >= args.length || !args[this.index].equals(this.returnType)) {
throw new InvalidInjectionException(this.info, "Specified index " + this.index + " for @ModifyArg is invalid for args "
+ Injector.printArgs(args) + ", expected " + this.returnType + " on " + this.methodNode.name);
+ Injector.printArgs(args) + ", expected " + this.returnType + " on " + this);
}
return this.index;
}
@@ -147,8 +147,7 @@ public class ModifyArgInjector extends InvokeInjector {
if (argIndex != -1) {
throw new InvalidInjectionException(this.info, "Found duplicate args with index [" + argIndex + ", " + arg + "] matching type "
+ this.returnType + " for @ModifyArg target " + target + " in " + this.classNode.name + "/" + this.methodNode.name
+ ". Please specify index of desired arg.");
+ this.returnType + " for @ModifyArg target " + target + " in " + this + ". Please specify index of desired arg.");
}
argIndex = arg;
@@ -156,7 +155,7 @@ public class ModifyArgInjector extends InvokeInjector {
if (argIndex == -1) {
throw new InvalidInjectionException(this.info, "Could not find arg matching type " + this.returnType + " for @ModifyArg target "
+ target + " in " + this.classNode.name + "/" + this.methodNode.name);
+ target + " in " + this);
}
return argIndex;
@@ -193,14 +193,14 @@ public class BeforeLoadLocal extends ContextualInjectionPoint {
while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();
if (state.isPendingCheck()) {
int local = this.discriminator.findLocal(this.mixin, this.returnType, this.discriminator.isArgsOnly(), target, insn);
int local = this.discriminator.findLocal(this.returnType, this.discriminator.isArgsOnly(), target, insn);
state.check(nodes, insn, local);
} else if (insn instanceof VarInsnNode && insn.getOpcode() == this.opcode && (this.ordinal == -1 || !state.success())) {
state.register((VarInsnNode)insn);
if (this.opcodeAfter) {
state.setPendingCheck();
} else {
int local = this.discriminator.findLocal(this.mixin, this.returnType, this.discriminator.isArgsOnly(), target, insn);
int local = this.discriminator.findLocal(this.returnType, this.discriminator.isArgsOnly(), target, insn);
state.check(nodes, insn, local);
}
}
@@ -24,7 +24,9 @@
*/
package org.spongepowered.asm.mixin.injection.modify;
public class InvalidImplicitDiscriminatorException extends RuntimeException {
import org.spongepowered.asm.mixin.MixinException;
public class InvalidImplicitDiscriminatorException extends MixinException {
private static final long serialVersionUID = 1L;
@@ -34,11 +34,9 @@ import java.util.Set;
import org.spongepowered.asm.lib.Type;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.AnnotationNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.LocalVariableNode;
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator.Context.Local;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.ASMHelper;
import org.spongepowered.asm.util.Locals;
import org.spongepowered.asm.util.PrettyPrinter;
@@ -122,23 +120,19 @@ public class LocalVariableDiscriminator {
*/
private final boolean isStatic;
public Context(MixinTargetContext mixin, Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
this(mixin.getTargetClass(), returnType, argsOnly, target, node);
}
public Context(ClassNode targetClass, Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
public Context(Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
this.isStatic = ASMHelper.methodIsStatic(target.method);
this.returnType = returnType;
this.target = target;
this.node = node;
this.baseArgIndex = this.isStatic ? 0 : 1;
this.locals = this.initLocals(targetClass, target, argsOnly, node);
this.locals = this.initLocals(target, argsOnly, node);
this.initOrdinals();
}
private Local[] initLocals(ClassNode targetClass, Target target, boolean argsOnly, AbstractInsnNode node) {
private Local[] initLocals(Target target, boolean argsOnly, AbstractInsnNode node) {
if (!argsOnly) {
LocalVariableNode[] locals = Locals.getLocalsAt(targetClass, target.method, node);
LocalVariableNode[] locals = Locals.getLocalsAt(target.classNode, target.method, node);
if (locals != null) {
Local[] lvt = new Local[locals.length];
for (int l = 0; l < locals.length; l++) {
@@ -152,7 +146,7 @@ public class LocalVariableDiscriminator {
Local[] lvt = new Local[this.baseArgIndex + target.arguments.length];
if (!this.isStatic) {
lvt[0] = new Local("this", Type.getType(targetClass.name));
lvt[0] = new Local("this", Type.getType(target.classNode.name));
}
for (int local = this.baseArgIndex; local < lvt.length; local++) {
Type arg = target.arguments[local - this.baseArgIndex];
@@ -277,9 +271,9 @@ public class LocalVariableDiscriminator {
return this.ordinal < 0 && this.index < context.baseArgIndex && this.names.isEmpty();
}
public int findLocal(MixinTargetContext mixin, Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
public int findLocal(Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
try {
return this.findLocal(new Context(mixin, returnType, argsOnly, target, node));
return this.findLocal(new Context(returnType, argsOnly, target, node));
} catch (InvalidImplicitDiscriminatorException ex) {
return -1;
}
@@ -30,7 +30,6 @@ import java.util.List;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.Type;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.lib.tree.VarInsnNode;
@@ -62,8 +61,8 @@ public class ModifyVariableInjector extends Injector {
*/
final InsnList insns = new InsnList();
public Context(ClassNode targetClass, Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
super(targetClass, returnType, argsOnly, target, node);
public Context(Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
super(returnType, argsOnly, target, node);
}
}
@@ -126,16 +125,16 @@ public class ModifyVariableInjector extends Injector {
super.sanityCheck(target, injectionPoints);
if (target.isStatic != this.isStatic) {
throw new InvalidInjectionException(this.info, "'static' of variable modifier method does not match target in " + this.methodNode.name);
throw new InvalidInjectionException(this.info, "'static' of variable modifier method does not match target in " + this);
}
int ordinal = this.discriminator.getOrdinal();
if (ordinal < -1) {
throw new InvalidInjectionException(this.info, "Invalid ordinal " + ordinal + " specified in " + this.methodNode.name);
throw new InvalidInjectionException(this.info, "Invalid ordinal " + ordinal + " specified in " + this);
}
if (this.discriminator.getIndex() == 0 && !this.isStatic) {
throw new InvalidInjectionException(this.info, "Invalid index 0 specified in non-static variable modifier " + this.methodNode.name);
throw new InvalidInjectionException(this.info, "Invalid index 0 specified in non-static variable modifier " + this);
}
}
@@ -144,7 +143,7 @@ public class ModifyVariableInjector extends Injector {
*/
@Override
protected void inject(Target target, AbstractInsnNode node) {
Context context = new Context(this.classNode, this.returnType, this.discriminator.isArgsOnly(), target, node);
Context context = new Context(this.returnType, this.discriminator.isArgsOnly(), target, node);
if (this.print) {
this.printLocals(context);
@@ -156,7 +155,7 @@ public class ModifyVariableInjector extends Injector {
this.inject(context, local);
}
} catch (InvalidImplicitDiscriminatorException ex) {
throw new InvalidInjectionException(this.info, "Implicit variable modifier injection failed in " + this.methodNode.name, ex);
throw new InvalidInjectionException(this.info, "Implicit variable modifier injection failed in " + this, ex);
}
target.insns.insertBefore(node, context.insns);
@@ -24,7 +24,9 @@
*/
package org.spongepowered.asm.mixin.injection.struct;
public class InvalidMemberDescriptorException extends RuntimeException {
import org.spongepowered.asm.mixin.MixinException;
public class InvalidMemberDescriptorException extends MixinException {
private static final long serialVersionUID = 1L;
@@ -28,6 +28,7 @@ import org.spongepowered.asm.lib.Type;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.mixin.MixinException;
import org.spongepowered.asm.mixin.transformer.IReferenceMapperContext;
import org.spongepowered.asm.obfuscation.SrgMethod;
import org.spongepowered.asm.util.SignaturePrinter;
@@ -219,7 +220,7 @@ public class MemberInfo {
*/
public String toSrg() {
if (!this.isFullyQualified()) {
throw new RuntimeException("Cannot convert unqualified reference to SRG mapping");
throw new MixinException("Cannot convert unqualified reference to SRG mapping");
}
if (this.desc.startsWith("(")) {
@@ -239,11 +240,11 @@ public class MemberInfo {
public SrgMethod asSrgMethod() {
if (!this.isFullyQualified()) {
throw new RuntimeException("Cannot convert unqualified reference to SrgMethod");
throw new MixinException("Cannot convert unqualified reference to SrgMethod");
}
if (this.isField()) {
throw new RuntimeException("Cannot convert a non-method reference to SrgMethod");
throw new MixinException("Cannot convert a non-method reference to SrgMethod");
}
return new SrgMethod(this.owner + "/" + this.name, this.desc);
@@ -25,6 +25,7 @@
package org.spongepowered.asm.mixin.injection.struct;
import org.spongepowered.asm.lib.Type;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -36,6 +37,8 @@ import org.spongepowered.asm.util.ASMHelper;
*/
public class Target {
public final ClassNode classNode;
/**
* Target method
*/
@@ -91,7 +94,8 @@ public class Target {
*
* @param method target method
*/
public Target(MethodNode method) {
public Target(ClassNode classNode, MethodNode method) {
this.classNode = classNode;
this.method = method;
this.insns = method.instructions;
this.isStatic = ASMHelper.methodIsStatic(method);
@@ -266,6 +270,6 @@ public class Target {
@Override
public String toString() {
return this.method.name + this.method.desc;
return String.format("%s::%s%s", this.classNode.name, this.method.name, this.method.desc);
}
}
@@ -24,7 +24,9 @@
*/
package org.spongepowered.asm.mixin.transformer;
public class InvalidMixinException extends RuntimeException {
import org.spongepowered.asm.mixin.MixinException;
public class InvalidMixinException extends MixinException {
private static final long serialVersionUID = 1L;
@@ -520,7 +520,7 @@ public class MixinApplicator {
// Patch the initialiser into the target class ctors
for (MethodNode method : this.targetClass.methods) {
if (Constants.INIT.equals(method.name)) {
if (Constants.CTOR.equals(method.name)) {
method.maxStack = Math.max(method.maxStack, ctor.maxStack);
this.injectInitialiser(mixin, method, initialiser);
}
@@ -537,7 +537,7 @@ public class MixinApplicator {
MethodNode ctor = null;
for (MethodNode mixinMethod : mixin.getMethods()) {
if (Constants.INIT.equals(mixinMethod.name) && MixinApplicator.hasLineNumbers(mixinMethod)) {
if (Constants.CTOR.equals(mixinMethod.name) && MixinApplicator.hasLineNumbers(mixinMethod)) {
if (ctor == null) {
ctor = mixinMethod;
} else {
@@ -569,7 +569,7 @@ public class MixinApplicator {
line = ((LineNumberNode)insn).line;
lineNumberIsValid = true;
} else if (insn instanceof MethodInsnNode) {
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && Constants.INIT.equals(((MethodInsnNode)insn).name) && superIndex == -1) {
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && Constants.CTOR.equals(((MethodInsnNode)insn).name) && superIndex == -1) {
superIndex = ctor.instructions.indexOf(insn);
start = line;
}
@@ -681,7 +681,7 @@ public class MixinApplicator {
for (Iterator<AbstractInsnNode> iter = ctor.instructions.iterator(0); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && Constants.INIT.equals(((MethodInsnNode)insn).name)) {
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && Constants.CTOR.equals(((MethodInsnNode)insn).name)) {
for (AbstractInsnNode node : initialiser) {
if (node instanceof LabelNode) {
continue;
@@ -48,6 +48,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.MixinException;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
@@ -358,7 +359,7 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
private void checkTarget(String targetClassName, ClassInfo targetInfo, boolean checkPublic) throws InvalidMixinException {
if (targetInfo == null) {
throw new RuntimeException("@Mixin target " + targetClassName + " was not found " + this);
throw new MixinException("@Mixin target " + targetClassName + " was not found " + this);
}
boolean targetIsInterface = targetInfo.isInterface();
if (targetIsInterface != this.isInterfaceMixin) {
@@ -225,7 +225,7 @@ class MixinPreProcessor {
method.renameTo(target.name);
}
if (Constants.INIT.equals(target.name)) {
if (Constants.CTOR.equals(target.name)) {
throw new InvalidMixinException(this.mixin, "Nice try! Cannot alias a constructor!");
}
@@ -24,11 +24,13 @@
*/
package org.spongepowered.asm.mixin.transformer;
import org.spongepowered.asm.mixin.MixinException;
/**
* An exception that occurs when a mixin reloads and does something it is
* normally allowed to do but isn't due to reloading restrictions.
*/
public class MixinReloadException extends RuntimeException {
public class MixinReloadException extends MixinException {
private static final long serialVersionUID = 1L;
private final MixinInfo mixinInfo;
@@ -524,7 +524,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
*/
private void processImaginarySuper(MethodNode method, FieldInsnNode fieldInsn) {
if (fieldInsn.getOpcode() != Opcodes.GETFIELD) {
if (Constants.INIT.equals(method.name)) {
if (Constants.CTOR.equals(method.name)) {
throw new InvalidMixinException(this, "Illegal imaginary super declaration: field " + fieldInsn.name
+ " must not specify an initialiser");
}
@@ -581,7 +581,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
}
private void updateBinding(MethodNode method, MemberRef methodRef, Traversal traversal) {
if (Constants.INIT.equals(method.name) || methodRef.getOwner().equals(this.targetClass.name) || this.targetClass.name.startsWith("<")) {
if (Constants.CTOR.equals(method.name) || methodRef.getOwner().equals(this.targetClass.name) || this.targetClass.name.startsWith("<")) {
return;
}
@@ -713,7 +713,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
String targetName = method.name + method.desc;
Target target = this.targetMethods.get(targetName);
if (target == null) {
target = new Target(method);
target = new Target(this.targetClass, method);
this.targetMethods.put(targetName, target);
}
return target;
@@ -49,6 +49,7 @@ import org.spongepowered.asm.mixin.MixinApplyError;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.MixinException;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler;
import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler.ErrorAction;
@@ -293,7 +294,7 @@ public class MixinTransformer extends TreeTransformer {
Object globalMixinTransformer = environment.getActiveTransformer();
if (globalMixinTransformer instanceof IClassTransformer) {
throw new RuntimeException("Terminating MixinTransformer instance " + this);
throw new MixinException("Terminating MixinTransformer instance " + this);
}
// I am a leaf on the wind
@@ -391,7 +392,7 @@ public class MixinTransformer extends TreeTransformer {
this.init(environment);
} catch (Exception ex) {
this.lock.pop();
throw new RuntimeException(ex);
throw new MixinException(ex);
}
}
@@ -425,7 +426,7 @@ public class MixinTransformer extends TreeTransformer {
if (mixins != null) {
// Re-entrance is "safe" as long as we don't need to apply any mixins, if there are mixins then we need to panic now
if (locked) {
this.logger.warn("Re-entrance detected, this will cause serious problems.", new RuntimeException());
this.logger.warn("Re-entrance detected, this will cause serious problems.", new MixinException());
throw new MixinApplyError("Re-entrance error.");
}
@@ -26,6 +26,7 @@ package org.spongepowered.asm.mixin.transformer;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.util.CheckClassAdapter;
import org.spongepowered.asm.mixin.MixinException;
/**
* Mixin transformer module which runs CheckClassAdapter on the post-mixin
@@ -33,7 +34,7 @@ import org.spongepowered.asm.lib.util.CheckClassAdapter;
*/
public class MixinTransformerModuleCheckClass implements IMixinTransformerModule {
public static class ValidationFailedException extends RuntimeException {
public static class ValidationFailedException extends MixinException {
private static final long serialVersionUID = 1L;
@@ -28,6 +28,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.spongepowered.asm.mixin.MixinException;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.io.Files;
@@ -64,7 +66,7 @@ public class SrgContainer {
} else if (type.equals("MD")) {
this.methodMap.forcePut(new SrgMethod(args[0], args[1]), new SrgMethod(args[2], args[3]));
} else {
throw new RuntimeException("Invalid SRG file: " + srg);
throw new MixinException("Invalid SRG file: " + srg);
}
}
}
@@ -31,7 +31,7 @@ import org.spongepowered.asm.mixin.Mixin;
*/
public abstract class Constants {
public static final String INIT = "<init>";
public static final String CTOR = "<init>";
public static final String CLINIT = "<clinit>";
public static final String IMAGINARY_SUPER = "super$";
public static final String DEBUG_OUTPUT_PATH = ".mixin.out";
@@ -47,6 +47,7 @@ import org.spongepowered.asm.lib.tree.analysis.BasicValue;
import org.spongepowered.asm.lib.tree.analysis.Frame;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo.FrameData;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.MixinVerifier;
/**
@@ -125,7 +126,15 @@ public class Locals {
node = Locals.nextNode(method.instructions, node);
}
List<FrameData> frames = ClassInfo.forName(classNode.name).findMethod(method).getFrames();
ClassInfo classInfo = ClassInfo.forName(classNode.name);
if (classInfo == null) {
throw new LVTGeneratorException("Could not load class metadata for " + classNode.name + " generating LVT for " + method.name);
}
Method methodInfo = classInfo.findMethod(method);
if (methodInfo == null) {
throw new LVTGeneratorException("Could not locate method metadata for " + method.name + " generating LVT in " + classNode.name);
}
List<FrameData> frames = methodInfo.getFrames();
LocalVariableNode[] frame = new LocalVariableNode[method.maxLocals];
int local = 0, index = 0;
@@ -176,7 +185,7 @@ public class Locals {
frame[framePos] = null; // TOP
}
} else {
throw new RuntimeException("Unrecognised locals opcode " + localType + " in locals array at position " + localPos
throw new LVTGeneratorException("Unrecognised locals opcode " + localType + " in locals array at position " + localPos
+ " in " + classNode.name + "." + method.name + method.desc);
}
} else if (localType == null) {
@@ -184,7 +193,7 @@ public class Locals {
frame[framePos] = null;
}
} else {
throw new RuntimeException("Invalid value " + localType + " in locals array at position " + localPos
throw new LVTGeneratorException("Invalid value " + localType + " in locals array at position " + localPos
+ " in " + classNode.name + "." + method.name + method.desc);
}
}