mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 05:42:15 +00:00
Properly handle enum reference for At.shift()
This commit is contained in:
1 parent
fc1742a54e
commit
2c93c43ddf
2 files changed
+25
-1
No files matched your search
@@ -273,7 +273,7 @@ public abstract class InjectionPoint {
|
||||
String at = ASMHelper.<String>getAnnotationValue(node, "value");
|
||||
List<String> args = ASMHelper.<List<String>>getAnnotationValue(node, "args");
|
||||
String target = ASMHelper.<String>getAnnotationValue(node, "target", "");
|
||||
At.Shift shift = ASMHelper.<At.Shift>getAnnotationValue(node, "shift", At.Shift.NONE);
|
||||
At.Shift shift = ASMHelper.<At.Shift>getAnnotationEnumConstantValue(node, "shift", At.Shift.class, At.Shift.NONE);
|
||||
int by = ASMHelper.<Integer>getAnnotationValue(node, "by", Integer.valueOf(0));
|
||||
int ordinal = ASMHelper.<Integer>getAnnotationValue(node, "ordinal", Integer.valueOf(-1));
|
||||
int opcode = ASMHelper.<Integer>getAnnotationValue(node, "opcode", Integer.valueOf(0));
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.objectweb.asm.util.CheckClassAdapter;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -483,6 +484,29 @@ public class ASMHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enum constant referenced by an annotation node
|
||||
*
|
||||
* @param annotationNode 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
|
||||
* @throws NoSuchFieldException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getAnnotationEnumConstantValue(AnnotationNode annotationNode, String key, Class<?> enumClass, T defaultValue) {
|
||||
String[] value = ASMHelper.getAnnotationValue(annotationNode, key);
|
||||
try {
|
||||
Field enumField = enumClass.getField(value[1]);
|
||||
if (enumField.isEnumConstant()) {
|
||||
return (T) enumField;
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static boolean methodIsStatic(MethodNode method) {
|
||||
return (method.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user