List of utility methods to do Reflection Annotation Find
Annotation | findAnnotation(Class> classy, Class extends Annotation> targetAnnotation) find Annotation Annotation[] annotations = classy.getAnnotations(); for (Annotation annotation : annotations) { if (targetAnnotation.isInstance(annotation)) { return annotation; return null; |
Annotation | findAnnotation(Class> clazz, Class extends Annotation> annotationClass, Set find Annotation if (clazz == null || set.contains(clazz) || clazz.equals(Object.class)) { return null; set.add(clazz); Annotation result = findAnnotation(clazz.getSuperclass(), annotationClass, set); if (result != null) { return result; Annotation findResult = Arrays.stream(clazz.getInterfaces()) .map((Class<?> interf) -> findAnnotation(interf, annotationClass, set)) .filter((Annotation annotation) -> annotation != null).findFirst().orElse(null); if (findResult != null) { return findResult; Annotation interfaceAnnotation = Arrays.stream(clazz.getDeclaredAnnotations()) .filter((Annotation annotation) -> annotation.annotationType().equals(annotationClass)).findFirst() .orElse(null); if (interfaceAnnotation != null) { return interfaceAnnotation; return Arrays.stream(clazz.getDeclaredAnnotations()) .map((Annotation annotation) -> findAnnotation(annotation.annotationType(), annotationClass, set)) .filter((Annotation annotation) -> annotation != null).findFirst().orElse(null); |
A | findAnnotation(Class> clazz, Class annotationClass) find Annotation A annotation = clazz.getAnnotation(annotationClass); if (null != annotation) { return annotation; for (Class<?> ifc : clazz.getInterfaces()) { annotation = ifc.getAnnotation(annotationClass); if (null != annotation) { return annotation; ... |
A | findAnnotation(Class> clazz, Class annotationType) Finds an annotation in a class type hierarchy. if (clazz == null) throw new IllegalArgumentException("Clazz parameter can't be null"); A annotation = clazz.getAnnotation(annotationType); if (annotation != null) return annotation; for (Class<?> ifc : clazz.getInterfaces()) { annotation = findAnnotation(ifc, annotationType); if (annotation != null) ... |
A | findAnnotation(Class> clazz, Class annotationType) Find a single Annotation of annotationType on the supplied Class , traversing its interfaces, annotations, and superclasses if the annotation is not present on the given class itself. return findAnnotation(clazz, annotationType, new HashSet<Annotation>()); |
A | findAnnotation(Class> clazz, Class annotationType) find Annotation A annotation = clazz.getAnnotation(annotationType); if (annotation != null) { return annotation; for (Class<?> ifc : clazz.getInterfaces()) { annotation = findAnnotation(ifc, annotationType); if (annotation != null) { return annotation; ... |
A | findAnnotation(Class> clazz, Class annotationType) find Annotation Preconditions.checkNotNull(clazz, "Class must not be null"); A annotation = clazz.getAnnotation(annotationType); if (annotation != null) { return annotation; for (Class<?> ifc : clazz.getInterfaces()) { annotation = findAnnotation(ifc, annotationType); if (annotation != null) { ... |
T | findAnnotation(Class> clazz, Class find Annotation T a = null; Class<?> c = findClassWithAnnotation(clazz, annotationClass); if (c != null) { a = c.getAnnotation(annotationClass); return a; |
T | findAnnotation(Class> clazz, Class find Annotation while (clazz != null) { T t = clazz.getAnnotation(annotationClass); if (t != null) { return t; for (Class<?> interfaceClass : clazz.getInterfaces()) { t = interfaceClass.getAnnotation(annotationClass); if (t != null) { ... |
T | findAnnotation(Class> clazz, Class Returns the annotation on the given class or the package of the class. T ann = clazz.getAnnotation(annotationClass); while (ann == null && clazz != null) { ann = clazz.getAnnotation(annotationClass); if (ann == null) { ann = clazz.getPackage().getAnnotation(annotationClass); if (ann == null) { clazz = clazz.getSuperclass(); ... |