List of utility methods to do Reflection Annotation
Annotation | getAnnotation(Class> type, Class extends Annotation> annotationType) Returns the first annotation of the specified annotation type for the given type. If no annotation is found for the type, the hierarchical ancestors are examined. Annotation annotation = null; for (Class<?> t = type; annotation == null && t != null; t = t.getSuperclass()) annotation = t.getAnnotation(annotationType); return annotation; |
A | getAnnotation(Class> type, Class ann) get Annotation A a; do { a = type.getAnnotation(ann); Class<?>[] faces = type.getInterfaces(); for (int i = 0; a == null && i < faces.length; i++) { Class<?> face = faces[i]; a = face.getAnnotation(ann); } while (a == null && !Object.class.equals(type = type.getSuperclass())); return a; |
A | getAnnotation(Class> type, Class annotationType) get Annotation return getAnnotation(type, annotationType, true);
|
T | getAnnotation(Class> type, Class Return the provided Class' annotation for the specified type if such an annotation is present, else null. T t = type.getAnnotation(annotationClass); if (t != null) { return t; for (Class<?> i : type.getInterfaces()) { if ((t = getAnnotation(i, annotationClass)) != null) { return t; return null; |
A | getAnnotation(Class ac, AnnotatedElement m, Annotation... directAnnotations) get Annotation return getAnnotation(ac, false, m, directAnnotations);
|
A | getAnnotation(Class annotationType, Class> classType) get Annotation return classType.getAnnotation(annotationType);
|
E | getAnnotation(Class get Annotation try { return enu.getClass().getField(enu.name()).getAnnotation(at); } catch (Exception e) { return null; |
T | getAnnotation(Class get Annotation T annotation = null; Field field = null; try { field = realClass.getDeclaredField(pAttributeName); } catch (NoSuchFieldException e) { if (field != null) { annotation = field.getAnnotation(annotationClass); ... |
T | getAnnotation(Class Similar to Class#getAnnotation(Class) except also searches annotations on interfaces. if (c == null) return null; T t = getDeclaredAnnotation(a, c); if (t != null) return t; t = getAnnotation(a, c.getSuperclass()); if (t != null) return t; ... |
T | getAnnotation(Class Retrieves the annotation from the method, if it is not on the method, the parent is checked. if (method == null) { return null; if (method.isAnnotationPresent(annotation)) { return method.getAnnotation(annotation); } else { for (Class<?> aInterface : ownerClass.getInterfaces()) { Method inheritedMethod = getInheritedMethod(aInterface, method); ... |