List of usage examples for java.lang Class getDeclaredAnnotationsByType
@Override public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass)
From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java
/** * Finds the first class from a given class' hierarchy that is not annotated * with the specified annotation.//from www . j ava2 s. com * * @author paouelle * * @param <T> the type of the class t start searching from * * @param clazz the class from which to search * @param annotationClass the annotation to search for * @return the non-<code>null</code> first class in <code>clazz</code>'s * hierarchy not annotated with the specified annotation * @throws NullPointerException if <code>clazz</code> or * <code>annotationClass</code> is <code>null</code> */ public static <T> Class<? super T> findFirstClassNotAnnotatedWith(Class<T> clazz, Class<? extends Annotation> annotationClass) { org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class"); org.apache.commons.lang3.Validate.notNull(annotationClass, "invalid null annotation class"); Class<? super T> c = clazz; while (c.getDeclaredAnnotationsByType(annotationClass).length > 0) { c = c.getSuperclass(); } return c; }
From source file:com.github.helenusdriver.commons.lang3.reflect.ReflectionUtils.java
/** * Finds the first class from a given class' hierarchy that is annotated * with the specified annotation./* ww w. ja v a2 s . co m*/ * * @author paouelle * * @param <T> the type of the class to start searching from * * @param clazz the class from which to search * @param annotationClass the annotation to search for * @return the first class in <code>clazz</code>'s hierarchy annotated with * the specified annotation or <code>null</code> if none is found * @throws NullPointerException if <code>clazz</code> or * <code>annotationClass</code> is <code>null</code> */ public static <T> Class<? super T> findFirstClassAnnotatedWith(Class<T> clazz, Class<? extends Annotation> annotationClass) { org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class"); org.apache.commons.lang3.Validate.notNull(annotationClass, "invalid null annotation class"); Class<? super T> c = clazz; do { if (c.getDeclaredAnnotationsByType(annotationClass).length > 0) { return c; } c = c.getSuperclass(); } while (c != null); return null; }