List of utility methods to do Reflection Annotation
T | getAnnotations(Class Returns the parameter annotation requested. T res = null; Annotation[][] anns = m.getParameterAnnotations(); for (int i = 0; i < anns[param].length && res == null; i++) if (anns[param][i].annotationType().equals(ann)) res = (T) anns[param][i]; if (res == null) { Class<?> cl = o.getClass().getSuperclass(); while (cl != null && res == null) { ... |
List | getAnnotations(Enum> targetEnum, Class extends Annotation> targetAnnotationClass) get Annotations Annotation[] allAnnotations; try { allAnnotations = targetEnum.getClass().getField(targetEnum.name()).getAnnotations(); } catch (Exception e) { throw new IllegalStateException("It failed to get annotations. targetEnum = [" + targetEnum + "]", e); List<Annotation> annotations = new ArrayList<Annotation>(); for (Annotation annotation : allAnnotations) { ... |
Annotation[] | getAnnotations(Field field) get Annotations return field.getAnnotations();
|
List | getAnnotations(final Class c, final Class Returns the (first) instance of the annotation, on the class (or any superclass, or interfaces implemented). final List<T> found = new ArrayList<T>(); if (c.isAnnotationPresent(annClass)) { found.add((T) c.getAnnotation(annClass)); Class parent = c.getSuperclass(); while ((parent != null) && (parent != Object.class)) { if (parent.isAnnotationPresent(annClass)) { found.add((T) parent.getAnnotation(annClass)); ... |
Set | getAnnotations(final Class> clazz, final Class get Annotations Set<T> annotations = new HashSet<>(); Class<?> queryClass = clazz; while (null != queryClass) { addAnnotation(queryClass, annotations, annotation); for (Class<?> interfaceClass : queryClass.getInterfaces()) { addAnnotation(interfaceClass, annotations, annotation); queryClass = queryClass.getSuperclass(); ... |
Annotation[] | getAnnotations(final Class> clazz, final String fieldName) get Annotations try { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field.getAnnotations(); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); |
List | getAnnotations(Method method) Returns all of the Annotation s defined on the given Method . if (methodAnnotationCache.containsKey(method)) { return methodAnnotationCache.get(method); List<Annotation> annotations = new ArrayList<Annotation>(); for (Annotation a : method.getAnnotations()) { annotations.add(a); annotations = Collections.unmodifiableList(annotations); ... |
A[] | getAnnotations(Method method) get Annotations return (A[]) method.getAnnotations();
|
Annotation[] | getAnnotations(Method method) get Annotations return method.getDeclaredAnnotations();
|
List | getAnnotations(Method method) get Annotations if (methodAnnotationCache.containsKey(method)) { return methodAnnotationCache.get(method); List<Annotation> annotations = Collections.unmodifiableList(Arrays.asList(method.getAnnotations())); methodAnnotationCache.put(method, annotations); return annotations; |