List of utility methods to do Reflection Annotation Find
A | findAnnotationInAnyParameter(Method method, Class annotationClass) Tries to extract the first occurrence an annotation of a certain class inside a method's parameters. for (Parameter parameter : method.getParameters()) { if (parameter.isAnnotationPresent(annotationClass)) { return parameter.getAnnotation(annotationClass); return null; |
A | findAnnotationInMethodOrInItsAnnotations(Method method, Class annotationClass) Tries to extract an annotation of a certain class directly annotated on to the method or any of its annotations. if (method.isAnnotationPresent(annotationClass)) { return method.getAnnotation(annotationClass); for (Annotation annotation : method.getAnnotations()) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(annotationClass)) { return annotationType.getAnnotation(annotationClass); return null; |
Set | findAnnotationMethods(String fullClassName, Class extends Annotation> anno) find Annotation Methods Set<Method> methodSet = new HashSet<Method>(); Class<?> clz = Class.forName(fullClassName); Method[] methods = clz.getDeclaredMethods(); for (Method method : methods) { if (method.getModifiers() != Modifier.PUBLIC) { continue; Annotation annotation = method.getAnnotation(anno); ... |
LinkedHashMap | findAnnotationsMap(Class Same as #findAnnotations(Class,Class) except returns the annotations as a map with the keys being the class on which the annotation was found. LinkedHashMap<Class<?>, T> m = new LinkedHashMap<Class<?>, T>(); findAnnotationsMap(a, c, m); return m; |
Annotation | findAnnotationSuperClasses(Class> annotationClass, Class c) find Annotation Super Classes while (c != null) { Annotation result = c.getAnnotation(annotationClass); if (result != null) return result; else c = c.getSuperclass(); return null; ... |
Annotation | findAnnotationWithMetaAnnotation(Class> clazz, Class extends Annotation> metaAnnotationType) find Annotation With Meta Annotation Annotation annotation = getAnnotationWithMetaAnnotation(clazz, metaAnnotationType); if (annotation != null) { return annotation; for (Class<?> ifc : clazz.getInterfaces()) { annotation = findAnnotationWithMetaAnnotation(ifc, metaAnnotationType); if (annotation != null) { return annotation; ... |