001    package net.sourceforge.retroweaver.runtime.java.lang.reflect;
002    
003    import static org.objectweb.asm.Opcodes.ACC_BRIDGE;
004    import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
005    import static org.objectweb.asm.Opcodes.ACC_VARARGS;
006    
007    import java.lang.reflect.Method;
008    
009    import net.sourceforge.retroweaver.runtime.java.lang.annotation.AIB;
010    import net.sourceforge.retroweaver.runtime.java.lang.annotation.Annotation;
011    
012    /**
013     * A mirror of java.lang.reflect.Method.
014     * 
015     * @author Toby Reyelts Date: Feb 20, 2005 Time: 11:10:46 PM
016     */
017    public class Method_ {
018    
019            private Method_() {
020                    // private constructor
021            }
022    
023            // Returns the default value for the annotation member represented by this
024            // <tt>Method</tt> instance.
025            public static Object getDefaultValue(final Method m) {
026                    final Class c = m.getDeclaringClass();
027    
028                    if (!c.isAnnotation()) {
029                            return null;
030                    }
031    
032                    return AIB.getAib(c).getDefaultValue(m.getName());
033            }
034    
035            // Returns this element's annotation for the specified type if such an
036            // annotation is present, else null.
037            public static <T extends Annotation> T getAnnotation(final Method m, final Class<T> annotationType) {
038                    final Class c = m.getDeclaringClass();
039                    return AIB.getAib(c).getMethodAnnotation(m.getName(), m.getParameterTypes(), m.getReturnType(), annotationType);
040            }
041    
042            // Returns all annotations present on this element.
043            public static Annotation[] getAnnotations(final Method m) {
044                    return getDeclaredAnnotations(m);
045            }
046    
047            // Returns all annotations that are directly present on this element.
048            public static Annotation[] getDeclaredAnnotations(final Method m) {
049                    final Class c = m.getDeclaringClass();
050                    return AIB.getAib(c).getMethodAnnotations(m.getName(), m.getParameterTypes(), m.getReturnType());
051            }
052    
053            // Returns true if an annotation for the specified type is present on this
054            // element, else false.
055            public static boolean isAnnotationPresent(final Method m, final Class<? extends Annotation> annotationType) {
056                    return getAnnotation(m, annotationType) != null;
057            }
058    
059            public static Annotation[][] getParameterAnnotations(final Method m) {
060                    final Class c = m.getDeclaringClass();
061                    return AIB.getAib(c).getMethodParameterAnnotations(m.getName(), m.getParameterTypes(), m.getReturnType());
062            }
063    
064            // Returns true if this method is a bridge method; returns false otherwise.
065            public static boolean isBridge(final Method m) {
066                    final Class c = m.getDeclaringClass();
067                    return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_BRIDGE);
068            }
069    
070            // Returns true if this method was declared to take a variable number of arguments; returns false otherwise.
071            public static boolean isVarArgs(final Method m) {
072                    final Class c = m.getDeclaringClass();
073                    return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_VARARGS);
074            }
075    
076            // Returns true if this method is a synthetic method; returns false otherwise.
077            public static boolean isSynthetic(final Method m) {
078                    final Class c = m.getDeclaringClass();
079                    return ReflectionDescriptor.getReflectionDescriptor(c).testMethodAccess(m, ACC_SYNTHETIC);
080            }
081    
082    }