List of utility methods to do Reflection Annotation
T | getAnnotation(Class Recursively searches for an annotation Search order
null is returned.
T annotation = cls.getAnnotation(annotationClass); if (annotation == null) { for (final Class<?> interfaceCls : cls.getInterfaces()) { annotation = getAnnotation(annotationClass, interfaceCls); if (annotation != null) break; if (annotation == null && cls.getSuperclass() != null && cls.getSuperclass() != Object.class) annotation = getAnnotation(annotationClass, cls.getSuperclass()); return annotation; |
T | getAnnotation(Class Utility method to read out repeatable annotations. for (AnnotatedElement obj : objects) { T annot = obj.getAnnotation(annotationType); if (annot != null) { return annot; return null; |
T | getAnnotation(Class Looks for the annotation specified on the given object. return getAnnotation(cl, o.getClass());
|
T | getAnnotation(Class get Annotation for (Annotation annotation : method.getParameterAnnotations()[parameterIndex]) { if (annotation.annotationType() == clazz) { return (T) annotation; return null; |
T | getAnnotation(Class get Annotation if (annotations == null) { return null; for (Annotation annotation : annotations) { if (cls.isAssignableFrom(annotation.getClass())) { return (T) annotation; return null; |
T | getAnnotation(Class get Annotation T annotation = null; for (Method method : methods) { if (method != null && (annotation = method.getAnnotation(cls)) != null) { return annotation; return null; |
T | getAnnotation(Class Method searchs annotation in annotations array and return it. if (annotations != null) { for (int i = 0; i < annotations.length; ++i) { if (lookingFor.isInstance(annotations[i])) { return (T) annotations[i]; return null; ... |
A | getAnnotation(Enum> enumConstant, Class annotationClass) get Annotation try { Field field = enumConstant.getClass().getDeclaredField(enumConstant.name()); return getAnnotation(field, annotationClass); } catch (Exception e) { throw new IllegalStateException(e); |
A | getAnnotation(final AnnotatedElement annotatedElement, final Class annotationClass) Returns the annotation or null if the element is not annotated with that type. final Optional<Annotation> annotation = Stream.of(annotatedElement.getAnnotations()) .filter(a -> a.annotationType().getName().equals(annotationClass.getName())).findAny(); return (A) annotation.orElse(null); |
T | getAnnotation(final Class c, final Class get Annotation final List<T> found = getAnnotations(c, annClass); if (found != null && !found.isEmpty()) { return found.get(0); } else { return null; |