@Override public synchronized ReflectionManifest get(Object key) { ReflectionManifest value = super.get(key); if (value == null) { value = new ReflectionManifest(); @SuppressWarnings("unchecked") // private class K type = (K)key; value.cls = type.getAnnotation(KeepClass.class); value.method = type.getAnnotation(KeepMethod.class); value.field = type.getAnnotation(KeepField.class); value.constructor = type.getAnnotation(KeepConstructor.class); value.anno = type.getAnnotation(KeepAnnotation.class); put(type, value); } return value; } }
public static <T extends Annotation> T getAnnotation(HasAnnotations classType, Class<T> annotationType) { try { T ann = classType.getAnnotation(annotationType); if (ann == null) { for (Annotation metaAnn : classType.getAnnotations()) { // only return a custom annotation if it contains the JacksonAnnotationsInside annotation if (metaAnn.annotationType().getAnnotation(JacksonAnnotationsInside.class) != null) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { break; } } } } return ann; } catch (Exception ex) { return null; } }
public static <T extends Annotation> T getAnnotation(HasAnnotations classType, Class<T> annotationType) { try { T ann = classType.getAnnotation(annotationType); if (ann == null) { for (Annotation metaAnn : classType.getAnnotations()) { // only return a custom annotation if it contains the JacksonAnnotationsInside annotation if (metaAnn.annotationType().getAnnotation(JacksonAnnotationsInside.class) != null) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { break; } } } } return ann; } catch (Exception ex) { return null; } }
/** * Returns the first occurence of the annotation found on the types * * @param annotation the annotation * @param hasAnnotationsList the types * @return the first occurence of the annotation found on the types * @param <T> a T object. */ public static <T extends Annotation> Optional<T> getAnnotation( Class<T> annotation, List<? extends HasAnnotations> hasAnnotationsList ) { for ( HasAnnotations accessor : hasAnnotationsList ) { if ( accessor.isAnnotationPresent( annotation ) ) { return Optional.of( accessor.getAnnotation( annotation ) ); } } return Optional.absent(); }