Adding @ModifyArg and @Redirect annotations, example code to follow

This commit is contained in:
Mumfrey committed 2015-01-11 22:44:45 +00:00
1 parent 5e283e8039
commit adfeb07297
23 files changed
+1158 -257

No files matched your search

@@ -46,6 +46,7 @@ import org.objectweb.asm.util.CheckClassAdapter;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -388,6 +389,28 @@ public class ASMHelper {
return ASMHelper.getAnnotation(method.invisibleAnnotations, Type.getDescriptor(annotationClass));
}
/**
* Get a runtime-visible annotation of the specified class from the supplied method node
*
* @param method Source method
* @param annotationClasses Types of annotation to search for
* @return the annotation, or null if not present
*/
public static AnnotationNode getSingleVisibleAnnotation(MethodNode method, Class<? extends Annotation>... annotationClasses) {
return ASMHelper.getSingleAnnotation(method.visibleAnnotations, annotationClasses);
}
/**
* Get an invisible annotation of the specified class from the supplied method node
*
* @param method Source method
* @param annotationClasses Types of annotation to search for
* @return the annotation, or null if not present
*/
public static AnnotationNode getSingleInvisibleAnnotation(MethodNode method, Class<? extends Annotation>... annotationClasses) {
return ASMHelper.getSingleAnnotation(method.invisibleAnnotations, annotationClasses);
}
/**
* Get a runtime-visible annotation of the specified class from the supplied class node
*
@@ -432,6 +455,23 @@ public class ASMHelper {
return null;
}
private static AnnotationNode getSingleAnnotation(List<AnnotationNode> annotations, Class<? extends Annotation>... annotationClasses) {
List<AnnotationNode> nodes = new ArrayList<AnnotationNode>();
for (Class<? extends Annotation> annotationClass : annotationClasses) {
AnnotationNode annotation = ASMHelper.getAnnotation(annotations, Type.getDescriptor(annotationClass));
if (annotation != null) {
nodes.add(annotation);
}
}
int foundNodes = nodes.size();
if (foundNodes > 1) {
throw new IllegalArgumentException("Conflicting annotations found: " + annotationClasses);
}
return foundNodes == 0 ? null : nodes.get(0);
}
/**
* Duck type the "value" entry (if any) of the specified annotation node
*