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; } }
private boolean hasStyleAnnotations(final HasAnnotations member) { return member.isAnnotationPresent(Css.class) || member.isAnnotationPresent(Style.class); }
/** * 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(); }
/** * Overloaded version to check GWT's JClassType classes. * * @param type * @param hasAnnotations * * @return */ public boolean isElementType(final WiringElementType type, final com.google.gwt.core.ext.typeinfo.HasAnnotations hasAnnotations) { final Collection<Class<? extends Annotation>> annotationsForElementType = getAnnotationsForElementType(type); for (final Annotation a : hasAnnotations.getAnnotations()) { if (annotationsForElementType.contains(a.annotationType())) { return true; } } return false; }
@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; } }
final boolean keepClass = (annotationRetention | ReflectionStrategy.COMPILE) == annotationRetention; final boolean keepRuntime = (annotationRetention | ReflectionStrategy.RUNTIME) == annotationRetention; for (final Annotation anno : annoProvider.getDeclaredAnnotations()) { final Retention retention = anno.annotationType().getAnnotation(Retention.class); if (retention == null) {
public static Annotation[] extractAnnotations(int annotationRetention, HasAnnotations method) { ArrayList<Annotation> annos = new ArrayList<Annotation>(); boolean keepClass = (annotationRetention | ReflectionStrategy.COMPILE) == annotationRetention; boolean keepRuntime = (annotationRetention | ReflectionStrategy.RUNTIME) == annotationRetention; for (Annotation anno : method.getAnnotations()) { Retention retention = anno.annotationType().getAnnotation(Retention.class); if (retention == null) { if (keepClass) annos.add(anno); } else { switch (retention.value()) { case CLASS: if (keepClass) annos.add(anno); break; case RUNTIME: if (keepRuntime) annos.add(anno); default: } } } return annos.toArray(new Annotation[annos.size()]); }
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 true when one of the type has the specified annotation * * @param annotation the annotation * @param hasAnnotationsList the types * @return true if one the type has the annotation * @param <T> a T object. */ public static <T extends Annotation> boolean isAnnotationPresent( Class<T> annotation, List<? extends HasAnnotations> hasAnnotationsList ) { for ( HasAnnotations accessor : hasAnnotationsList ) { if ( accessor.isAnnotationPresent( annotation ) ) { return true; } } return false; }
public static boolean isHttpMethod(HasAnnotations hasAnnotations) { for (HttpVerb type : values()) { if (hasAnnotations.isAnnotationPresent(type.getAnnotationClass())) { return true; } } return false; }