1 16 17 package org.springframework.core.annotation; 18 19 import java.lang.annotation.Annotation ; 20 import java.lang.reflect.Method ; 21 22 import org.springframework.core.BridgeMethodResolver; 23 24 44 public abstract class AnnotationUtils { 45 46 53 public static Annotation [] getAnnotations(Method method) { 54 return BridgeMethodResolver.findBridgedMethod(method).getAnnotations(); 55 } 56 57 66 public static <A extends Annotation > A getAnnotation(Method method, Class <A> annotationType) { 67 return BridgeMethodResolver.findBridgedMethod(method).getAnnotation(annotationType); 68 } 69 70 80 public static <A extends Annotation > A findAnnotation(Method method, Class <A> annotationType) { 81 if (!annotationType.isAnnotation()) { 82 throw new IllegalArgumentException (annotationType + " is not an annotation"); 83 } 84 A annotation = getAnnotation(method, annotationType); 85 Class cl = method.getDeclaringClass(); 86 while (annotation == null) { 87 cl = cl.getSuperclass(); 88 if (cl == null || cl.equals(Object .class)) { 89 break; 90 } 91 try { 92 method = cl.getDeclaredMethod(method.getName(), method.getParameterTypes()); 93 annotation = getAnnotation(method, annotationType); 94 } 95 catch (NoSuchMethodException ex) { 96 } 98 } 99 return annotation; 100 } 101 102 } 103 | Popular Tags |