List of utility methods to do Reflection Annotation Find
T | findAnnotation(Class> clazz, Class Look for the annotationType in the class or one of its ancestors. T a = clazz.getAnnotation(annotationType); if (a != null) { return a; Class<?> parentClass = clazz.getSuperclass(); if (parentClass != null && !parentClass.equals(Object.class)) { a = findAnnotation(parentClass, annotationType); if (a == null) { for (Class<?> i : clazz.getInterfaces()) { a = findAnnotation(i, annotationType); if (a != null) { return a; return a; |
T | findAnnotation(Class> klass, Class Returns the annotation on the given class or the package of the class. T ann = klass.getAnnotation(annotationClass); while (ann == null && klass != null) { ann = klass.getAnnotation(annotationClass); if (ann == null) ann = klass.getPackage().getAnnotation(annotationClass); if (ann == null) { klass = klass.getSuperclass(); if (klass != null) { ... |
A | findAnnotation(final Class> clazz, final Class type) Find a method annotation on the declaring class or in any of it's implemented interfaces final List<Class<?>> classes = allImplementedTypes(clazz); for (final Class<?> c : classes) { try { final A annotation = c.getAnnotation(type); if (annotation != null) { return annotation; } catch (final Exception e) { ... |
T | findAnnotation(final Class> clazz, final Class find Annotation checkNotNull(clazz, "clazz is null"); checkNotNull(annotation, "annotation is null"); Class<?> currentClazz = clazz; while (currentClazz != null) { T a = currentClazz.getAnnotation(annotation); if (a != null) { return a; Class<?> enclosingClass = currentClazz.getEnclosingClass(); while (enclosingClass != null) { a = findAnnotation(enclosingClass, annotation); if (a != null) { return a; enclosingClass = enclosingClass.getEnclosingClass(); final Class<?>[] interfaces = currentClazz.getInterfaces(); for (final Class<?> interfaceClass : interfaces) { a = findAnnotation(interfaceClass, annotation); if (a != null) { return a; currentClazz = currentClazz.getSuperclass(); return null; |
A | findAnnotation(final Class> type, final Class annotationType) Recursively search a type's inheritance hierarchy for an annotation. A annotation = type.getAnnotation(annotationType); if (annotation != null) { return annotation; for (final Class<?> subType : type.getInterfaces()) { annotation = findAnnotation(subType, annotationType); if (annotation != null) { return annotation; ... |
A | findAnnotation(final Class targetAnnotation, final Class> annotatedType) find Annotation A foundAnnotation = annotatedType.getAnnotation(targetAnnotation); if (foundAnnotation == null) { for (Annotation annotation : annotatedType.getAnnotations()) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(targetAnnotation)) { foundAnnotation = annotationType.getAnnotation(targetAnnotation); break; return foundAnnotation; |
T | findAnnotation(final Class find Annotation final T fieldAnnotation = field.getAnnotation(annotationClass); return fieldAnnotation == null ? beanClass.getAnnotation(annotationClass) : fieldAnnotation; |
Optional | findAnnotation(final Set find Annotation return annotations.stream().filter(annotation -> matches(annotation, annotationType)).findFirst()
.map(annotationType::cast);
|
T | findAnnotation(Method method, Class find Annotation T anno = method.getAnnotation(annotationType); if (anno != null) { return anno; return findAnnotation(method.getDeclaringClass(), method, annotationType); |
Optional | findAnnotation(Method method, Class find Annotation Class<?> clazz = method.getDeclaringClass(); T annotation = method.getAnnotation(type); while (annotation == null) { clazz = clazz.getSuperclass(); if (clazz == null || Object.class == clazz) { break; try { ... |