List of utility methods to do Reflection Annotation
A | getAnnotation(final Class> annotatedClass, final Class annotationClass) get Annotation return annotatedClass.getAnnotation(annotationClass);
|
T | getAnnotation(final Class> type, final Class get Annotation T res = null; if (!Modifier.isAbstract(type.getModifiers())) { Class<?> supertype = type; while (supertype != null && Object.class != supertype) { if (supertype.isAnnotationPresent(annotation)) { res = supertype.getAnnotation(annotation); break; supertype = supertype.getSuperclass(); return res; |
ANN | getAnnotation(final Class get Annotation final Annotation ann = obj.getAnnotation(reference); return ann == null ? null : (ANN) ann; |
ANNOTATION | getAnnotation(final Class Returns the first element which has an annotation of the given type declared. for (final AnnotatedElement element : elements) { final ANNOTATION annotation = element.getAnnotation(annotationClass); if (annotation != null) { return annotation; return null; |
A | getAnnotation(final Member member, final Class annotation) Returns the annotation instance if the member has the annotation .
if (member instanceof Field) { return ((Field) member).getAnnotation(annotation); if (member instanceof Method) { return ((Method) member).getAnnotation(annotation); throw new IllegalArgumentException("Member is neither field nor method: " + member); |
T | getAnnotation(final Method method, final Class get Annotation T annotation = method.getAnnotation(annotationClass); if (annotation != null) return annotation; final Class<?> declaringClass = method.getDeclaringClass(); Class<?> superClass = declaringClass.getSuperclass(); while (superClass != null) { try { final Method superClassMethod = superClass.getDeclaredMethod(method.getName(), ... |
T | getAnnotation(final Object obj, final Class get Annotation final Class<?> type = obj instanceof Class<?> ? (Class<?>) obj : obj.getClass(); return type.getAnnotation(annoType); |
A | getAnnotation(final Object object, final Class annotationClass) Get the first annotation of the declared type from this object. if (object == null) throw new IllegalArgumentException("object cannot be null in getAnnotation()"); if (annotationClass == null) throw new IllegalArgumentException("annotationClass cannot be null in getAnnotation()"); final Class<? extends Object> clazz = object.getClass(); A result = null; for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { result = c.getAnnotation(annotationClass); ... |
T | getAnnotation(Member m, Class get Annotation if (m == null || annotationClass == null) return null; if (m instanceof Constructor) return ((Constructor<?>) m).getAnnotation(annotationClass); else return ((Method) m).getAnnotation(annotationClass); |
Annotation | getAnnotation(Method m, Class annotationClass) get Annotation return m.getAnnotation(annotationClass);
|