private static <T extends Annotation> T getAnnotationForInterface(Class<?> intf, Class<T> annotationType) { T annotation = intf.getAnnotation(annotationType); if (annotation != null) { return annotation; } for (Class<?> intf2 : intf.getInterfaces()) { return getAnnotationForInterface(intf2, annotationType); } return null; } }
private static <T extends Annotation> T getAnnotationForInterface(Class<?> intf, Class<T> annotationType) { T annotation = intf.getAnnotation(annotationType); if (annotation != null) { return annotation; } for (Class<?> intf2 : intf.getInterfaces()) { return getAnnotationForInterface(intf2, annotationType); } return null; } }
/** * Look for a specified annotation on a method. If there, return it. If not, search it's containing class. * Assume that the annotation is marked @Inherited. * * @param m method to examine * @param annotationType the annotation type to look for. */ public static <T extends Annotation> T getAnnotationForMethodOrContainingClass(Method m, Class<T> annotationType) { T annotation = m.getAnnotation(annotationType); if (annotation != null) { return annotation; } annotation = m.getDeclaringClass().getAnnotation(annotationType); if (annotation != null) { return annotation; } for (Class<?> intf : m.getDeclaringClass().getInterfaces()) { annotation = getAnnotationForInterface(intf, annotationType); if (annotation != null) { return annotation; } } return null; }
/** * Look for a specified annotation on a method. If there, return it. If not, search it's containing class. * Assume that the annotation is marked @Inherited. * * @param m method to examine * @param annotationType the annotation type to look for. */ public static <T extends Annotation> T getAnnotationForMethodOrContainingClass(Method m, Class<T> annotationType) { T annotation = m.getAnnotation(annotationType); if (annotation != null) { return annotation; } annotation = m.getDeclaringClass().getAnnotation(annotationType); if (annotation != null) { return annotation; } for (Class<?> intf : m.getDeclaringClass().getInterfaces()) { annotation = getAnnotationForInterface(intf, annotationType); if (annotation != null) { return annotation; } } return null; }