1 | package net.sourceforge.retroweaver.runtime.java.lang.reflect; |
2 | |
3 | import static org.objectweb.asm.Opcodes.ACC_BRIDGE; |
4 | import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC; |
5 | import static org.objectweb.asm.Opcodes.ACC_VARARGS; |
6 | |
7 | import java.lang.reflect.Method; |
8 | |
9 | import net.sourceforge.retroweaver.runtime.java.lang.annotation.AIB; |
10 | import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation; |
11 | |
12 | /** |
13 | * A mirror of java.lang.reflect.Method. |
14 | * |
15 | * @author Toby Reyelts Date: Feb 20, 2005 Time: 11:10:46 PM |
16 | */ |
17 | public class Method_ { |
18 | |
19 | private Method_() { |
20 | // private constructor |
21 | } |
22 | |
23 | // Returns the default value for the annotation member represented by this |
24 | // <tt>Method</tt> instance. |
25 | public static Object getDefaultValue(final Method m) { |
26 | final Class c = m.getDeclaringClass(); |
27 | |
28 | if (!c.isAnnotation()) { |
29 | return null; |
30 | } |
31 | |
32 | return AIB.getAib(c).getDefaultValue(m.getName()); |
33 | } |
34 | |
35 | // Returns this element's annotation for the specified type if such an |
36 | // annotation is present, else null. |
37 | public static <T extends Annotation> T getAnnotation(final Method m, final Class<T> annotationType) { |
38 | final Class c = m.getDeclaringClass(); |
39 | return AIB.getAib(c).getMethodAnnotation(m.getName(), m.getParameterTypes(), m.getReturnType(), annotationType); |
40 | } |
41 | |
42 | // Returns all annotations present on this element. |
43 | public static Annotation[] getAnnotations(final Method m) { |
44 | return getDeclaredAnnotations(m); |
45 | } |
46 | |
47 | // Returns all annotations that are directly present on this element. |
48 | public static Annotation[] getDeclaredAnnotations(final Method m) { |
49 | final Class c = m.getDeclaringClass(); |
50 | return AIB.getAib(c).getMethodAnnotations(m.getName(), m.getParameterTypes(), m.getReturnType()); |
51 | } |
52 | |
53 | // Returns true if an annotation for the specified type is present on this |
54 | // element, else false. |
55 | public static boolean isAnnotationPresent(final Method m, final Class<? extends Annotation> annotationType) { |
56 | return getAnnotation(m, annotationType) != null; |
57 | } |
58 | |
59 | public static Annotation[][] getParameterAnnotations(final Method m) { |
60 | final Class c = m.getDeclaringClass(); |
61 | return AIB.getAib(c).getMethodParameterAnnotations(m.getName(), m.getParameterTypes(), m.getReturnType()); |
62 | } |
63 | |
64 | // Returns true if this method is a bridge method; returns false otherwise. |
65 | public static boolean isBridge(final Method m) { |
66 | final Class c = m.getDeclaringClass(); |
67 | return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_BRIDGE); |
68 | } |
69 | |
70 | // Returns true if this method was declared to take a variable number of arguments; returns false otherwise. |
71 | public static boolean isVarArgs(final Method m) { |
72 | final Class c = m.getDeclaringClass(); |
73 | return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_VARARGS); |
74 | } |
75 | |
76 | // Returns true if this method is a synthetic method; returns false otherwise. |
77 | public static boolean isSynthetic(final Method m) { |
78 | final Class c = m.getDeclaringClass(); |
79 | return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_SYNTHETIC); |
80 | } |
81 | |
82 | } |