protected void addViewMetaData(Annotation currentAnnotation, List<Annotation> metaDataList) { Class<? extends Annotation> annotationClass = currentAnnotation.annotationType(); if (annotationClass.isAnnotationPresent(ViewMetaData.class)) { metaDataList.add(currentAnnotation); } if (annotationClass.isAnnotationPresent(Stereotype.class)) { for (Annotation inheritedViaStereotype : annotationClass.getAnnotations()) { if (inheritedViaStereotype.annotationType().isAnnotationPresent(ViewMetaData.class)) { metaDataList.add(inheritedViaStereotype); } } } }
static Set<Annotation> findQualifiers(Set<Annotation> annotations) { Set<Annotation> results = new LinkedHashSet<>(); for(Annotation annotation : annotations) { Class<? extends Annotation> annotationClass = annotation.getClass(); if(annotation instanceof Default) { continue; } else if(annotationClass.getAnnotation(Qualifier.class) != null) { results.add(annotation); } else if(annotationClass.getAnnotation(Stereotype.class) != null) { Set<Annotation> parentAnnotations = new LinkedHashSet<>(asList(annotationClass.getAnnotations())); results.addAll(findQualifiers(parentAnnotations)); } } return results; }
@Override public Set<Class<? extends Annotation>> getStereotypes() { Set<Class<? extends Annotation>> stereotypes = new HashSet<>(); Arrays.stream(javaType.getAnnotations()) .map(a -> a.getClass()) .filter(a -> a.getAnnotation(Stereotype.class) != null) .forEach(stereotypes::add); return stereotypes; }
public static boolean isStereotype(Class<? extends Annotation> candidate) { for (Annotation annotation : candidate.getAnnotations()) { if (annotation.annotationType().equals(Stereotype.class)) { return true; } } return false; }
private static <T extends Annotation> T hasAnnotationInStereotypes(Annotation[] declaredAnnotations, Class<T> expectedAnnotationType) { for (Annotation declaredAnnotation : declaredAnnotations) { Class<? extends Annotation> declaredAnnotationType = declaredAnnotation.annotationType(); if (declaredAnnotationType == expectedAnnotationType) { return expectedAnnotationType.cast(declaredAnnotation); } else if (declaredAnnotationType.isAnnotationPresent(Stereotype.class)) { T ann = hasAnnotationInStereotypes(declaredAnnotationType.getAnnotations(), expectedAnnotationType); if (ann != null) { return expectedAnnotationType.cast(ann); } } } return null; }
@Override public Set<Class<? extends Annotation>> getStereotypes() { Set<Class<? extends Annotation>> stereotypes = new HashSet<>(); for (Annotation annotation : getQualifiers()) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(Stereotype.class)) { stereotypes.add(annotationType); } } return stereotypes; }
public static Annotation resolveSecurityBindingType(Annotation annotation) { List<Annotation> result = getAllAnnotations(annotation.annotationType().getAnnotations(), new HashSet<Integer>()); for (Annotation foundAnnotation : result) { if (foundAnnotation.annotationType().isAnnotationPresent(SecurityBindingType.class)) { return foundAnnotation; } } throw new IllegalStateException(annotation.annotationType().getName() + " is a " + Stereotype.class.getName() + " but it isn't annotated with " + SecurityBindingType.class.getName()); }
private List<Annotation> mergeMetaData(Set<Annotation> metaData, List<Annotation> inheritedMetaData) { //TODO add qualifier support List<Annotation> nodeViewMetaData = new ArrayList<Annotation>(); List<Annotation> viewMetaDataFromStereotype = new ArrayList<Annotation>(); for (Annotation annotation : metaData) { if (annotation.annotationType().isAnnotationPresent(ViewMetaData.class)) { nodeViewMetaData.add(annotation); } //TODO move to stereotype-util, improve it and merge it with DefaultViewConfigInheritanceStrategy if (annotation.annotationType().isAnnotationPresent(Stereotype.class)) { for (Annotation metaAnnotation : annotation.annotationType().getAnnotations()) { if (metaAnnotation.annotationType().isAnnotationPresent(ViewMetaData.class)) { viewMetaDataFromStereotype.add(metaAnnotation); } } } } //merge meta-data of same level List<Annotation> result = mergeAnnotationInstances(viewMetaDataFromStereotype, nodeViewMetaData); if (inheritedMetaData != null && !inheritedMetaData.isEmpty()) { //merge meta-data with levels above result = mergeAnnotationInstances(inheritedMetaData, result); } return result; }
public Set<Class<? extends Annotation>> getStereotypes() { return Stream.of(repositoryType.getAnnotations()) .map(a -> a.annotationType()) .filter(a -> a.isAnnotationPresent(Stereotype.class)) .collect(Collectors.toSet()); }