mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 15:29:17 +00:00
WIP but mostly working Desc selector functionality
This commit is contained in:
1 parent
2ef2417de6
commit
21881482ae
27 files changed
+998
-42
No files matched your search
@@ -43,6 +43,7 @@ import org.spongepowered.asm.mixin.Debug;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.util.asm.IAnnotationHandle;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -53,6 +54,73 @@ import com.google.common.collect.Lists;
|
||||
*/
|
||||
public final class Annotations {
|
||||
|
||||
/**
|
||||
* Wrapper for AnnotationNode to support access via IAnnotationHandle
|
||||
*/
|
||||
public static class Handle implements IAnnotationHandle {
|
||||
|
||||
private final AnnotationNode annotation;
|
||||
|
||||
public Handle(AnnotationNode annotation) {
|
||||
Preconditions.checkNotNull(annotation, "annotation");
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return this.annotation.desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IAnnotationHandle> getAnnotationList(String key) {
|
||||
List<AnnotationNode> value = Annotations.<AnnotationNode>getValue(this.annotation, key, false);
|
||||
List<IAnnotationHandle> list = new ArrayList<IAnnotationHandle>();
|
||||
if (value != null) {
|
||||
for (AnnotationNode node : value) {
|
||||
list.add(new Handle(node));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Type> getTypeList(String key) {
|
||||
return this.<Type>getList(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAnnotationHandle getAnnotation(String key) {
|
||||
AnnotationNode value = Annotations.<AnnotationNode>getValue(this.annotation, key);
|
||||
return value != null ? new Handle(value) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(String key, T defaultValue) {
|
||||
return Annotations.<T>getValue(this.annotation, key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue() {
|
||||
return this.getValue("value", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(String key) {
|
||||
return this.getValue(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> getList(String key) {
|
||||
return Annotations.<T>getValue(this.annotation, key, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "@" + Bytecode.getSimpleName(this.annotation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations which are eligible for merge via {@link #mergeAnnotations}
|
||||
*/
|
||||
@@ -70,6 +138,24 @@ public final class Annotations {
|
||||
private Annotations() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supplied annotation object as an annotation handle
|
||||
*
|
||||
* @param annotation Annotation to return
|
||||
* @return Wrapped or cast annotation
|
||||
*/
|
||||
public static IAnnotationHandle handleOf(Object annotation) {
|
||||
if (annotation instanceof IAnnotationHandle) {
|
||||
return (IAnnotationHandle)annotation;
|
||||
} else if (annotation instanceof AnnotationNode) {
|
||||
return new Annotations.Handle((AnnotationNode)annotation);
|
||||
} else if (annotation == null) {
|
||||
return null;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported annotation type: " + annotation.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a runtime-visible annotation of the specified class on the supplied
|
||||
|
||||
Reference in new issue
Block a user