mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-25 00:34:21 +00:00
Bump ver to 0.6.8. Add implicit-zero modification support. Closes #165
This commit is contained in:
1 parent
719079e292
commit
20d0468b44
12 files changed
+321
-85
No files matched your search
@@ -62,7 +62,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.6.7";
|
||||
public static final String VERSION = "0.6.8";
|
||||
|
||||
// Consts
|
||||
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
|
||||
|
||||
@@ -27,6 +27,8 @@ package org.spongepowered.asm.mixin.injection;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
|
||||
/**
|
||||
* Annotation for specifying the injection point for an {@link ModifyConstant}
|
||||
* injector. Leaving all values unset causes the injection point to match all
|
||||
@@ -41,14 +43,94 @@ import java.lang.annotation.RetentionPolicy;
|
||||
public @interface Constant {
|
||||
|
||||
/**
|
||||
* Causes this injector to match ACONST_NULL (null object) literals
|
||||
* Available options for the {@link Constant#expandZeroConditions} setting.
|
||||
* Each option matches the inverse instructions as well because in the
|
||||
* compiled code it is not unusual for <tt>if (x > 0)</tt> to be compiled
|
||||
* as <tt>if (!(x <= 0))</tt>
|
||||
*
|
||||
* <p>Note that all of these options assume that <tt>x</tt> is on the <b>
|
||||
* left-hand side</b> of the expression in question. For expressions where
|
||||
* zero is on the <b>right-hand side</b> you should choose the inverse.</p>
|
||||
*/
|
||||
public enum Condition {
|
||||
|
||||
/**
|
||||
* Match < operators and >= instructions:
|
||||
*
|
||||
* <code>x < 0</code>
|
||||
*/
|
||||
LESS_THAN_ZERO(Opcodes.IFLT, Opcodes.IFGE),
|
||||
|
||||
/**
|
||||
* Match <= operators and > instructions
|
||||
*
|
||||
* <code>x <= 0</code>
|
||||
*/
|
||||
LESS_THAN_OR_EQUAL_TO_ZERO(Opcodes.IFLE, Opcodes.IFGT),
|
||||
|
||||
/**
|
||||
* Match >= operators and < instructions, equivalent to
|
||||
* {@link #LESS_THAN_ZERO}
|
||||
*
|
||||
* <code>x >= 0</code>
|
||||
*/
|
||||
GREATER_THAN_OR_EQUAL_TO_ZERO(Condition.LESS_THAN_ZERO),
|
||||
|
||||
/**
|
||||
* Match > operators and <= instructions, equivalent to
|
||||
* {@link #LESS_THAN_OR_EQUAL_TO_ZERO}
|
||||
*
|
||||
* <code>x > 0</code>
|
||||
*/
|
||||
GREATER_THAN_ZERO(Condition.LESS_THAN_OR_EQUAL_TO_ZERO);
|
||||
|
||||
private final int[] opcodes;
|
||||
|
||||
private final Condition equivalence;
|
||||
|
||||
private Condition(int... opcodes) {
|
||||
this(null, opcodes);
|
||||
}
|
||||
|
||||
private Condition(Condition equivalence) {
|
||||
this(equivalence, equivalence.opcodes);
|
||||
}
|
||||
|
||||
private Condition(Condition equivalence, int... opcodes) {
|
||||
this.equivalence = equivalence != null ? equivalence : this;
|
||||
this.opcodes = opcodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the condition which is equivalent to this condition
|
||||
*/
|
||||
public Condition getEquivalentCondition() {
|
||||
return this.equivalence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the opcodes for this condition
|
||||
*/
|
||||
public int[] getOpcodes() {
|
||||
return this.opcodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Causes this injector to match <tt>ACONST_NULL</tt> (null object) literals
|
||||
*
|
||||
* @return true to match <tt>null</tt>
|
||||
*/
|
||||
public boolean nullValue() default false;
|
||||
|
||||
/**
|
||||
* Specify an integer constant to match, includes byte and short values
|
||||
* Specify an integer constant to match, includes byte and short values.
|
||||
*
|
||||
* <p><b>Special note for referencing <tt>0</tt> (zero) which forms part of
|
||||
* a comparison expression:</b> See the {@link #expandZeroConditions} option
|
||||
* below.</p>
|
||||
*
|
||||
* @return integer value to match
|
||||
*/
|
||||
@@ -102,10 +184,53 @@ public @interface Constant {
|
||||
*/
|
||||
public int ordinal() default -1;
|
||||
|
||||
/**
|
||||
* Whilst most constants can be located in the compiled method with relative
|
||||
* ease, there exists a special case when a <tt>zero</tt> is used in a
|
||||
* conditional expression. For example:
|
||||
*
|
||||
* <blockquote><code>if (x >= 0)</code></blockquote>
|
||||
*
|
||||
* <p>This special case occurs because java includes explicit instructions
|
||||
* for this type of comparison, and thus the compiled code might look more
|
||||
* like this:</p>
|
||||
*
|
||||
* <blockquote><code>if (x.isGreaterThanOrEqualToZero())</code></blockquote>
|
||||
*
|
||||
* <p>Of course if we know that the constant we are searching for is part of
|
||||
* a comparison, then we can explicitly search for the
|
||||
* <tt>isGreaterThanOrEqualToZero</tt> and convert it back to the original
|
||||
* form in order to redirect it just like any other constant access.</p>
|
||||
*
|
||||
* <p>To enable this behaviour, you may specify one or more values for this
|
||||
* argument based on the type of expression you wish to expand. Since the
|
||||
* Java compiler is wont to compile certain expressions as the <i>inverse
|
||||
* </i> of their source-level counterparts (eg. compiling a <em>do this if
|
||||
* greater than</em> structure to a <em>ignore this if less than or equal
|
||||
* </em> structure); specifying a particular expression type implicitly
|
||||
* includes the inverse expression as well.</p>
|
||||
*
|
||||
* <p>It is worth noting that the effect on ordinals may be hard to predict,
|
||||
* and thus care should be taken to ensure that the selected injection
|
||||
* points match the expected locations.</p>
|
||||
*
|
||||
* <p>Specifying this option has the following effects:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>Matching conditional opcodes in the target method are identified
|
||||
* for injection candidacy.</li>
|
||||
* <li>An <tt>intValue</tt> of <tt>0</tt> is implied and does not need to
|
||||
* be explicitly defined.</li>
|
||||
* <li>However, explicitly specifying an <tt>intValue</tt> of <tt>0</tt>
|
||||
* will cause this selector to also match explicit <tt>0</tt> constants
|
||||
* in the method body as well.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public Condition[] expandZeroConditions() default {};
|
||||
|
||||
/**
|
||||
* @return true to enable verbose debug logging for this injection point
|
||||
*/
|
||||
public boolean log() default false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,10 @@ import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
*
|
||||
* <p>The callback receives the original value of the constant, and should
|
||||
* return the new value.</p>
|
||||
*
|
||||
* <p>Like other <em>Redirect</em> injectors, the callback signature can
|
||||
* optionally include the target method arguments by simply appending them to
|
||||
* the handler method signature.</p>
|
||||
*/
|
||||
|
||||
@Target({ ElementType.METHOD })
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.code;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
@@ -98,21 +96,12 @@ public final class MethodSlices {
|
||||
* @param info owning injector
|
||||
* @return parsed slice collection
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MethodSlices parse(InjectionInfo info) {
|
||||
MethodSlices slices = new MethodSlices(info);
|
||||
|
||||
AnnotationNode annotation = info.getAnnotation();
|
||||
if (annotation != null) {
|
||||
List<AnnotationNode> sliceNodes = new ArrayList<AnnotationNode>();
|
||||
Object sliceValue = ASMHelper.getAnnotationValue(annotation, "slice");
|
||||
if (sliceValue instanceof List) {
|
||||
sliceNodes.addAll((List<AnnotationNode>)sliceValue);
|
||||
} else if (sliceValue instanceof AnnotationNode) {
|
||||
sliceNodes.add((AnnotationNode)sliceValue);
|
||||
}
|
||||
|
||||
for (AnnotationNode node : sliceNodes) {
|
||||
for (AnnotationNode node : ASMHelper.<AnnotationNode>getAnnotationValue(annotation, "slice", true)) {
|
||||
MethodSlice slice = MethodSlice.parse(info, node);
|
||||
slices.add(slice);
|
||||
}
|
||||
|
||||
+42
-8
@@ -28,6 +28,8 @@ 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.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.JumpInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
@@ -39,6 +41,12 @@ import org.spongepowered.asm.util.ASMHelper;
|
||||
* A bytecode injector which allows a specific
|
||||
*/
|
||||
public class ModifyConstantInjector extends RedirectInjector {
|
||||
|
||||
/**
|
||||
* Offset between "implicit zero" opcodes and "explicit int comparison"
|
||||
* opcodes
|
||||
*/
|
||||
private static final int OPCODE_OFFSET = Opcodes.IF_ICMPLT - Opcodes.IFLT;
|
||||
|
||||
/**
|
||||
* @param info Injection info
|
||||
@@ -57,30 +65,56 @@ public class ModifyConstantInjector extends RedirectInjector {
|
||||
throw new UnsupportedOperationException("Target failure for " + this.info);
|
||||
}
|
||||
|
||||
if (ASMHelper.isConstant(node.getCurrentTarget())) {
|
||||
this.injectConstantModifier(target, node);
|
||||
AbstractInsnNode targetNode = node.getCurrentTarget();
|
||||
if (targetNode instanceof JumpInsnNode) {
|
||||
this.injectExpandedConstantModifier(target, (JumpInsnNode)targetNode);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidInjectionException(this.info, this.annotationType + " annotation on is targetting an invalid insn in "
|
||||
if (ASMHelper.isConstant(targetNode)) {
|
||||
this.injectConstantModifier(target, targetNode);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidInjectionException(this.info, this.annotationType + " annotation is targetting an invalid insn in "
|
||||
+ target + " in " + this);
|
||||
}
|
||||
|
||||
private void injectConstantModifier(Target target, InjectionNode node) {
|
||||
final AbstractInsnNode constNode = node.getCurrentTarget();
|
||||
/**
|
||||
* Injects a constant modifier at an implied-zero
|
||||
*
|
||||
* @param target target method
|
||||
* @param jumpNode jump instruction (must be IFLT, IFGE, IFGT or IFLE)
|
||||
*/
|
||||
private void injectExpandedConstantModifier(Target target, JumpInsnNode jumpNode) {
|
||||
int opcode = jumpNode.getOpcode();
|
||||
if (opcode < Opcodes.IFLT || opcode > Opcodes.IFLE) {
|
||||
throw new InvalidInjectionException(this.info, this.annotationType + " annotation selected an invalid opcode "
|
||||
+ ASMHelper.getOpcodeName(opcode) + " in " + target + " in " + this);
|
||||
}
|
||||
|
||||
final InsnList insns = new InsnList();
|
||||
insns.add(new InsnNode(Opcodes.ICONST_0));
|
||||
AbstractInsnNode invoke = this.invokeConstantHandler(Type.getType("I"), target, insns, insns);
|
||||
insns.add(new JumpInsnNode(opcode + ModifyConstantInjector.OPCODE_OFFSET, jumpNode.label));
|
||||
target.replaceNode(jumpNode, invoke, insns);
|
||||
target.addToStack(1);
|
||||
}
|
||||
|
||||
private void injectConstantModifier(Target target, AbstractInsnNode constNode) {
|
||||
final Type constantType = ASMHelper.getConstantType(constNode);
|
||||
final InsnList before = new InsnList();
|
||||
final InsnList after = new InsnList();
|
||||
AbstractInsnNode invoke = this.invokeConstantHandler(constNode, constantType, target, before, after);
|
||||
AbstractInsnNode invoke = this.invokeConstantHandler(constantType, target, before, after);
|
||||
target.wrapNode(constNode, invoke, before, after);
|
||||
}
|
||||
|
||||
private AbstractInsnNode invokeConstantHandler(AbstractInsnNode targetNode, Type constantType, Target target, InsnList before, InsnList after) {
|
||||
private AbstractInsnNode invokeConstantHandler(Type constantType, Target target, InsnList before, InsnList after) {
|
||||
final String handlerDesc = ASMHelper.generateDescriptor(constantType, constantType);
|
||||
final boolean withArgs = this.checkDescriptor(handlerDesc, target, "getter");
|
||||
|
||||
if (!this.isStatic) {
|
||||
before.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
before.insert(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
target.addToStack(1);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class CallbackInjectionInfo extends InjectionInfo {
|
||||
|
||||
@Override
|
||||
protected Injector parseInjector(AnnotationNode injectAnnotation) {
|
||||
boolean cancellable = ASMHelper.<Boolean>getAnnotationValue(injectAnnotation, "cancellable", false);
|
||||
boolean cancellable = ASMHelper.<Boolean>getAnnotationValue(injectAnnotation, "cancellable", Boolean.FALSE);
|
||||
LocalCapture locals = ASMHelper.<LocalCapture>getAnnotationValue(injectAnnotation, "locals", LocalCapture.class, LocalCapture.NO_CAPTURE);
|
||||
String identifier = ASMHelper.<String>getAnnotationValue(injectAnnotation, "id", "");
|
||||
|
||||
|
||||
@@ -173,17 +173,12 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<AnnotationNode> readInjectionPoints(String type) {
|
||||
Object atValue = ASMHelper.getAnnotationValue(this.annotation, "at");
|
||||
if (atValue instanceof List) {
|
||||
return (List<AnnotationNode>)atValue;
|
||||
} else if (atValue instanceof AnnotationNode) {
|
||||
List<AnnotationNode> ats = new ArrayList<AnnotationNode>();
|
||||
ats.add((AnnotationNode)atValue);
|
||||
return ats;
|
||||
List<AnnotationNode> ats = ASMHelper.<AnnotationNode>getAnnotationValue(this.annotation, "at", false);
|
||||
if (ats == null) {
|
||||
throw new InvalidInjectionException(this, 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)");
|
||||
return ats;
|
||||
}
|
||||
|
||||
protected void parseInjectionPoints(List<AnnotationNode> ats) {
|
||||
|
||||
+69
-43
@@ -26,8 +26,10 @@ package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -37,6 +39,7 @@ import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.Constant.Condition;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.ModifyConstantInjector;
|
||||
@@ -45,6 +48,8 @@ import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* Information about a constant modifier injector
|
||||
*/
|
||||
@@ -71,55 +76,67 @@ public class ModifyConstantInjectionInfo extends InjectionInfo {
|
||||
private final String stringValue;
|
||||
private final Type typeValue;
|
||||
|
||||
private final int[] expandOpcodes;
|
||||
private final boolean expand;
|
||||
|
||||
private final String matchByType;
|
||||
|
||||
private final boolean log;
|
||||
|
||||
public BeforeConstant(InjectionInfo info, AnnotationNode node, String returnType) {
|
||||
Boolean empty = ASMHelper.<Boolean>getAnnotationValue(node, "nullValue", (Boolean)null);
|
||||
this.ordinal = ASMHelper.<Integer>getAnnotationValue(node, "ordinal", Integer.valueOf(-1));
|
||||
this.nullValue = empty != null ? empty.booleanValue() : false;;
|
||||
this.intValue = ASMHelper.<Integer>getAnnotationValue(node, "intValue", (Integer)null);
|
||||
this.floatValue = ASMHelper.<Float>getAnnotationValue(node, "floatValue", (Float)null);
|
||||
this.longValue = ASMHelper.<Long>getAnnotationValue(node, "longValue", (Long)null);
|
||||
this.ordinal = ASMHelper.<Integer>getAnnotationValue(node, "ordinal", Integer.valueOf(-1));
|
||||
this.nullValue = empty != null ? empty.booleanValue() : false;
|
||||
this.intValue = ASMHelper.<Integer>getAnnotationValue(node, "intValue", (Integer)null);
|
||||
this.floatValue = ASMHelper.<Float>getAnnotationValue(node, "floatValue", (Float)null);
|
||||
this.longValue = ASMHelper.<Long>getAnnotationValue(node, "longValue", (Long)null);
|
||||
this.doubleValue = ASMHelper.<Double>getAnnotationValue(node, "doubleValue", (Double)null);
|
||||
this.stringValue = ASMHelper.<String>getAnnotationValue(node, "stringValue", (String)null);
|
||||
this.typeValue = ASMHelper.<Type>getAnnotationValue(node, "classValue", (Type)null);
|
||||
this.typeValue = ASMHelper.<Type>getAnnotationValue(node, "classValue", (Type)null);
|
||||
|
||||
this.matchByType = this.validateDiscriminator(info, returnType, empty);
|
||||
this.expandOpcodes = this.parseExpandOpcodes(node);
|
||||
this.expand = this.expandOpcodes.length > 0;
|
||||
|
||||
this.log = ASMHelper.<Boolean>getAnnotationValue(node, "log", Boolean.FALSE).booleanValue();
|
||||
}
|
||||
|
||||
private String validateDiscriminator(InjectionInfo info, String returnType, Boolean empty) {
|
||||
int c = BeforeConstant.count(empty, this.intValue, this.floatValue, this.longValue, this.doubleValue, this.stringValue, this.typeValue);
|
||||
if (c == 1) {
|
||||
returnType = null;
|
||||
} else if (c > 1) {
|
||||
throw new InvalidInjectionException(info, "Conflicting constant discriminators specified on @Constant annotation for " + info);
|
||||
}
|
||||
|
||||
this.matchByType = returnType;
|
||||
|
||||
this.log = ASMHelper.<Boolean>getAnnotationValue(node, "log", Boolean.FALSE).booleanValue();
|
||||
return returnType;
|
||||
}
|
||||
|
||||
private int[] parseExpandOpcodes(AnnotationNode node) {
|
||||
Set<Integer> opcodes = new HashSet<Integer>();
|
||||
for (Condition condition : ASMHelper.<Condition>getAnnotationValue(node, "expandZeroConditions", true, Condition.class)) {
|
||||
Condition actual = condition.getEquivalentCondition();
|
||||
for (int opcode : actual.getOpcodes()) {
|
||||
opcodes.add(Integer.valueOf(opcode));
|
||||
}
|
||||
}
|
||||
return Ints.toArray(opcodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
boolean found = false;
|
||||
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info("BeforeConstant is searching for an constants in method with descriptor {}", desc);
|
||||
}
|
||||
this.log("BeforeConstant is searching for constants in method with descriptor {}", desc);
|
||||
|
||||
ListIterator<AbstractInsnNode> iter = insns.iterator();
|
||||
for (int ordinal = 0; iter.hasNext();) {
|
||||
AbstractInsnNode insn = iter.next();
|
||||
|
||||
boolean matchesInsn = this.matchesInsn(insn);
|
||||
boolean matchesInsn = this.expand ? this.matchesConditionalInsn(insn) : this.matchesConstantInsn(insn);
|
||||
if (matchesInsn) {
|
||||
if (this.log) {
|
||||
String byType = this.matchByType != null ? " TYPE" : " value";
|
||||
BeforeConstant.logger.info(" BeforeConstant found a matching constant{} at ordinal {}", byType, ordinal);
|
||||
}
|
||||
this.log(" BeforeConstant found a matching constant{} at ordinal {}", this.matchByType != null ? " TYPE" : " value", ordinal);
|
||||
if (this.ordinal == -1 || this.ordinal == ordinal) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found {}", ASMHelper.describeNode(insn).trim());
|
||||
}
|
||||
this.log(" BeforeConstant found {}", ASMHelper.describeNode(insn).trim());
|
||||
nodes.add(insn);
|
||||
found = true;
|
||||
}
|
||||
@@ -130,52 +147,61 @@ public class ModifyConstantInjectionInfo extends InjectionInfo {
|
||||
return found;
|
||||
}
|
||||
|
||||
private boolean matchesInsn(AbstractInsnNode insn) {
|
||||
private boolean matchesConditionalInsn(AbstractInsnNode insn) {
|
||||
for (int conditionalOpcode : this.expandOpcodes) {
|
||||
if (insn.getOpcode() == conditionalOpcode) {
|
||||
this.log(" BeforeConstant found %s instruction", ASMHelper.getOpcodeName(conditionalOpcode));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.intValue != null && this.intValue.intValue() == 0 && ASMHelper.isConstant(insn)) {
|
||||
Object value = ASMHelper.getConstant(insn);
|
||||
this.log(" BeforeConstant found INTEGER constant: value = {}", value);
|
||||
return value instanceof Integer && ((Integer)value).intValue() == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matchesConstantInsn(AbstractInsnNode insn) {
|
||||
if (!ASMHelper.isConstant(insn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object value = ASMHelper.getConstant(insn);
|
||||
if (value == null) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found NULL constant: nullValue = {}", this.nullValue);
|
||||
}
|
||||
this.log(" BeforeConstant found NULL constant: nullValue = {}", this.nullValue);
|
||||
return this.nullValue || Constants.OBJECT.equals(this.matchByType);
|
||||
} else if (value instanceof Integer) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found INTEGER constant: value = {}, intValue = {}", value, this.intValue);
|
||||
}
|
||||
this.log(" BeforeConstant found INTEGER constant: value = {}, intValue = {}", value, this.intValue);
|
||||
return value.equals(this.intValue) || "I".equals(this.matchByType);
|
||||
} else if (value instanceof Float) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found FLOAT constant: value = {}, floatValue = {}", value, this.floatValue);
|
||||
}
|
||||
this.log(" BeforeConstant found FLOAT constant: value = {}, floatValue = {}", value, this.floatValue);
|
||||
return value.equals(this.floatValue) || "F".equals(this.matchByType);
|
||||
} else if (value instanceof Long) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found LONG constant: value = {}, longValue = {}", value, this.longValue);
|
||||
}
|
||||
this.log(" BeforeConstant found LONG constant: value = {}, longValue = {}", value, this.longValue);
|
||||
return value.equals(this.longValue) || "J".equals(this.matchByType);
|
||||
} else if (value instanceof Double) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found DOUBLE constant: value = {}, doubleValue = {}", value, this.doubleValue);
|
||||
}
|
||||
this.log(" BeforeConstant found DOUBLE constant: value = {}, doubleValue = {}", value, this.doubleValue);
|
||||
return value.equals(this.doubleValue) || "D".equals(this.matchByType);
|
||||
} else if (value instanceof String) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found STRING constant: value = {}, stringValue = {}", value, this.stringValue);
|
||||
}
|
||||
this.log(" BeforeConstant found STRING constant: value = {}, stringValue = {}", value, this.stringValue);
|
||||
return value.equals(this.stringValue) || Constants.STRING.equals(this.matchByType);
|
||||
} else if (value instanceof Type) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(" BeforeConstant found CLASS constant: value = {}, typeValue = {}", value, this.typeValue);
|
||||
}
|
||||
this.log(" BeforeConstant found CLASS constant: value = {}, typeValue = {}", value, this.typeValue);
|
||||
return value.equals(this.typeValue) || Constants.CLASS.equals(this.matchByType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void log(String message, Object... params) {
|
||||
if (this.log) {
|
||||
BeforeConstant.logger.info(message, params);
|
||||
}
|
||||
}
|
||||
|
||||
private static int count(Object... values) {
|
||||
int counter = 0;
|
||||
for (Object value : values) {
|
||||
|
||||
@@ -533,12 +533,12 @@ class MixinApplicatorStandard {
|
||||
}
|
||||
|
||||
AnnotationNode renamed = ASMHelper.getVisibleAnnotation(method, MixinRenamed.class);
|
||||
if (renamed == null || !ASMHelper.getAnnotationValue(renamed, "isInterfaceMember", false)) {
|
||||
if (renamed == null || !ASMHelper.getAnnotationValue(renamed, "isInterfaceMember", Boolean.FALSE)) {
|
||||
throw new InvalidMixinException(mixin, "@Intrinsic method must be prefixed interface method, no rename encountered on "
|
||||
+ methodName + " in " + mixin);
|
||||
}
|
||||
|
||||
if (!ASMHelper.getAnnotationValue(intrinsic, "displace", false)) {
|
||||
if (!ASMHelper.getAnnotationValue(intrinsic, "displace", Boolean.FALSE)) {
|
||||
this.logger.log(mixin.getLoggingLevel(), "Skipping Intrinsic mixin method {} for {}", methodName, mixin.getTargetClassRef());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,11 @@ import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.ClassReader;
|
||||
@@ -657,23 +659,75 @@ public final class ASMHelper {
|
||||
* defaultValue if the annotation value is not set
|
||||
*
|
||||
* @param <T> duck type
|
||||
* @param annotationNode Annotation node to query
|
||||
* @param annotation Annotation node to query
|
||||
* @param key Key to search for
|
||||
* @param enumClass Class of enum containing the enum constant to search for
|
||||
* @param defaultValue Value to return if the specified key isn't found
|
||||
* @return duck-typed annotation value or defaultValue if missing
|
||||
*/
|
||||
public static <T extends Enum<T>> T getAnnotationValue(AnnotationNode annotationNode, String key, Class<T> enumClass, T defaultValue) {
|
||||
String[] value = ASMHelper.<String[]>getAnnotationValue(annotationNode, key);
|
||||
public static <T extends Enum<T>> T getAnnotationValue(AnnotationNode annotation, String key, Class<T> enumClass, T defaultValue) {
|
||||
String[] value = ASMHelper.<String[]>getAnnotationValue(annotation, key);
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return ASMHelper.toEnumValue(enumClass, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified annotation node value as a list of nodes
|
||||
*
|
||||
* @param <T> list element type
|
||||
* @param annotation Annotation node to query
|
||||
* @param key Key to search for
|
||||
* @param notNull if true, return an empty list instead of null if the
|
||||
* annotation value is absent
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getAnnotationValue(AnnotationNode annotation, String key, boolean notNull) {
|
||||
Object value = ASMHelper.<Object>getAnnotationValue(annotation, key);
|
||||
if (value instanceof List) {
|
||||
return (List<T>)value;
|
||||
} else if (value != null) {
|
||||
List<T> list = new ArrayList<T>();
|
||||
list.add((T)value);
|
||||
return list;
|
||||
}
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified annotation node value as a list of enums
|
||||
*
|
||||
* @param <T> list element type
|
||||
* @param annotation Annotation node to query
|
||||
* @param key Key to search for
|
||||
* @param notNull if true, return an empty list instead of null if the
|
||||
* annotation value is absent
|
||||
* @param enumClass Class of enum containing the enum constant to use
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Enum<T>> List<T> getAnnotationValue(AnnotationNode annotation, String key, boolean notNull, Class<T> enumClass) {
|
||||
Object value = ASMHelper.<Object>getAnnotationValue(annotation, key);
|
||||
if (value instanceof List) {
|
||||
for (ListIterator<Object> iter = ((List<Object>)value).listIterator(); iter.hasNext();) {
|
||||
iter.set(ASMHelper.toEnumValue(enumClass, (String[])iter.next()));
|
||||
}
|
||||
return (List<T>)value;
|
||||
} else if (value instanceof String[]) {
|
||||
List<T> list = new ArrayList<T>();
|
||||
list.add(ASMHelper.toEnumValue(enumClass, (String[])value));
|
||||
return list;
|
||||
}
|
||||
return Collections.<T>emptyList();
|
||||
}
|
||||
|
||||
private static <T extends Enum<T>> T toEnumValue(Class<T> enumClass, String[] value) {
|
||||
if (!enumClass.getName().equals(Type.getType(value[0]).getClassName())) {
|
||||
throw new IllegalArgumentException("The supplied enum class does not match the stored enum value");
|
||||
}
|
||||
return Enum.valueOf(enumClass, value[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the supplied method node is static
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user