List of utility methods to do Reflection Annotation
T | getAnnotation(final AnnotatedElement anElement, final Class get Annotation return anElement != null ? (T) anElement.getAnnotation(annotationClass) : null;
|
T | getAnnotation(final Method method, final Class get Annotation final T annotation = method.getAnnotation(annotationClass); if (annotation != null) { return annotation; final Class<?> declaringClass = method.getDeclaringClass(); Class<?> currentSuperClass = declaringClass.getSuperclass(); while (currentSuperClass != null) { try { ... |
T | getAnnotation(@Nonnull Annotation[] annotations, @Nonnull Class Retrieve the annotation of given type from array of annotations if (annotations == null || annotations.length == 0) { return null; for (Annotation a : annotations) { if (annotation.isAssignableFrom(a.getClass())) { return (T) a; return null; |
A | getAnnotation(@Nonnull Class> cls, @Nonnull Class annotation) get Annotation return annotation.cast(cls.getAnnotation(annotation));
|
T | getAnnotation(AnnotatedElement ae, Class Get a single Annotation of annotationType from the supplied Method, Constructor or Field. T ann = ae.getAnnotation(annotationType); if (ann == null) { for (Annotation metaAnn : ae.getAnnotations()) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { break; return ann; |
Object | getAnnotation(AnnotatedElement aobj, Class aClass) Get annotation of an object via reflection for (Object a : aobj.getAnnotations()) { if (isAnnotationInstance(aClass, a)) return a; return null; |
Annotation | getAnnotation(AnnotatedElement element, Class extends Annotation> annotation) get Annotation return element.getAnnotation(annotation);
|
Annotation | getAnnotation(AnnotatedElement element, String annotationTypeName) get Annotation Class<?> annotationType = null; try { annotationType = Class.forName(annotationTypeName); } catch (Exception ex) { throw new IllegalArgumentException(ex); return element.getAnnotation(annotationType.asSubclass(Annotation.class)); |
Annotation | getAnnotation(AnnotatedElement target, String annotationType) get Annotation for (Annotation annotation : target.getAnnotations()) { if (annotationType.equals(annotation.annotationType().getName())) { return annotation; return null; |
T | getAnnotation(Annotation ann, Class get Annotation if (annotationType.isInstance(ann)) { return (T) ann; return ann.annotationType().getAnnotation(annotationType); |