List of utility methods to do Reflection Annotation
List | getAnnotationOuterIndecies(Class> annotationClass, Annotation[][] annotations) get Annotation Outer Indecies List<Integer> result = new ArrayList<Integer>(); for (int i = 0; i < annotations.length; i++) { for (int k = 0; k < annotations[i].length; k++) { if (annotationClass.isInstance(annotations[i][k])) result.add(i); return result; ... |
Object | getAnnotationPropertyValue(Annotation a, String annotationPropertyName) Given an Annotation and a property name, this method finds the property method, invokes it, and returns the result try { Method[] methods = a.annotationType().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(annotationPropertyName)) { return methods[i].invoke(a, new Object[] {}); } catch (Exception e) { ... |
T | getAnnotationRecursive(Class> cls, Class get Annotation Recursive T annotation = cls.getAnnotation(annotationClass); if (annotation != null) return annotation; if (Object.class.equals(cls)) return null; return getAnnotationRecursive(cls.getSuperclass(), annotationClass); |
Collection | getAnnotations(AnnotatedElement ae, Class get Annotations Collection<T> anns = new ArrayList<>(2); T ann = ae.getAnnotation(annotationType); if (ann != null) { anns.add(ann); for (Annotation metaAnn : ae.getAnnotations()) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { ... |
Annotation[] | getAnnotations(AnnotatedElement annotated) Returns all annotations present on this element. List<Annotation> results = new LinkedList<Annotation>(); results.addAll(Arrays.asList(annotated.getAnnotations())); if (annotated instanceof Class && !Object.class.equals(annotated)) { results.addAll(Arrays.asList(getAnnotations(((Class<?>) annotated).getSuperclass()))); for (Class<?> i : ((Class<?>) annotated).getInterfaces()) { results.addAll(Arrays.asList(getAnnotations(i))); } else if (annotated instanceof Method && !Object.class.equals(((Method) annotated).getDeclaringClass())) { ... |
List | getAnnotations(Annotation[][] annotations) get Annotations final List<Annotation> result = new LinkedList<>(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].length > 1) { throw new RuntimeException("you can only assign one annotation"); Annotation annotation = annotations[i][0]; result.add(annotation); return result; |
Set | getAnnotations(Class cls) get Annotations Set<Annotation> ret = new HashSet<Annotation>(); ret.addAll(Arrays.asList(cls.getAnnotations())); if (cls.getSuperclass() != null) { ret.addAll(getAnnotations(cls.getSuperclass())); for (Class intrface : cls.getInterfaces()) { ret.addAll(getAnnotations(intrface)); return ret; |
List | getAnnotations(Class extends Annotation> annotationClass, Annotation[] annotations) get Annotations List<Annotation> result = null; for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationClass) { if (result == null) { result = new ArrayList<Annotation>(); result.add(annotation); if (result == null) { return Collections.emptyList(); return result; |
List | getAnnotations(Class> c, Class Finds the annotation objects of annotated fields. Field[] fields = c.getDeclaredFields(); List<T> annotations = new LinkedList<>(); for (Field field : fields) { T annotation = field.getAnnotation(annotationClass); if (annotation != null) { annotations.add(annotation); return annotations; |
A[] | getAnnotations(Class annotation, Collection extends Annotation> annotations) get Annotations final Collection<A> found = new ArrayList<>(); for (Annotation a : annotations) { if (annotation.isAssignableFrom(annotation)) { found.add(annotation.cast(a)); return found.toArray((A[]) Array.newInstance(annotation, 0)); |