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; } }
/** * 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; }
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 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()]); }