use of java.lang.annotation.Repeatable in project junit5 by junit-team.
the class AnnotationUtils method findRepeatableAnnotations.
/**
* @see org.junit.platform.commons.support.AnnotationSupport#findRepeatableAnnotations(AnnotatedElement, Class)
*/
public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) {
Preconditions.notNull(annotationType, "annotationType must not be null");
Repeatable repeatable = annotationType.getAnnotation(Repeatable.class);
Preconditions.notNull(repeatable, () -> annotationType.getName() + " must be @Repeatable");
Class<? extends Annotation> containerType = repeatable.value();
boolean inherited = containerType.isAnnotationPresent(Inherited.class);
// Short circuit the search algorithm.
if (element == null) {
return Collections.emptyList();
}
// We use a LinkedHashSet because the search algorithm may discover
// duplicates, but we need to maintain the original order.
Set<A> found = new LinkedHashSet<>(16);
findRepeatableAnnotations(element, annotationType, containerType, inherited, found, new HashSet<>(16));
// unmodifiable since returned from public, non-internal method(s)
return Collections.unmodifiableList(new ArrayList<>(found));
}
use of java.lang.annotation.Repeatable in project openj9 by eclipse.
the class Class method internalGetDeclaredAnnotationsByType.
private <A extends Annotation> ArrayList<A> internalGetDeclaredAnnotationsByType(Class<A> annotationClass) {
AnnotationCache currentAnnotationCache = getAnnotationCache();
ArrayList<A> annotationsList = new ArrayList<>();
LinkedHashMap<Class<? extends Annotation>, Annotation> map = currentAnnotationCache.directAnnotationMap;
if (map != null) {
Repeatable repeatable = annotationClass.getDeclaredAnnotation(Repeatable.class);
if (repeatable == null) {
A annotation = (A) map.get(annotationClass);
if (annotation != null) {
annotationsList.add(annotation);
}
} else {
Class<? extends Annotation> containerType = repeatable.value();
// if the annotation and its container are both present, the order must be maintained
for (Map.Entry<Class<? extends Annotation>, Annotation> entry : map.entrySet()) {
Class<? extends Annotation> annotationType = entry.getKey();
if (annotationType == annotationClass) {
annotationsList.add((A) entry.getValue());
} else if (annotationType == containerType) {
A[] containedAnnotations = (A[]) getAnnotationsArrayFromValue(entry.getValue(), containerType, annotationClass);
if (containedAnnotations != null) {
annotationsList.addAll(Arrays.asList(containedAnnotations));
}
}
}
}
}
return annotationsList;
}
use of java.lang.annotation.Repeatable in project graal by oracle.
the class AnnotationTypeFeature method duringAnalysis.
@Override
public void duringAnalysis(DuringAnalysisAccess access) {
DuringAnalysisAccessImpl accessImpl = (DuringAnalysisAccessImpl) access;
AnalysisUniverse universe = accessImpl.getUniverse();
/*
* JDK implementation of repeatable annotations always instantiates an array of a requested
* annotation. We need to mark arrays of all reachable annotations as in heap.
*/
universe.getTypes().stream().filter(AnalysisType::isAnnotation).filter(AnalysisType::isInTypeCheck).map(type -> universe.lookup(type.getWrapped()).getArrayClass()).filter(annotationArray -> !annotationArray.isInstantiated()).forEach(annotationArray -> {
accessImpl.registerAsInHeap(annotationArray);
access.requireAnalysisIteration();
});
Stream<AnnotatedElement> allElements = Stream.concat(Stream.concat(universe.getFields().stream(), universe.getMethods().stream()), universe.getTypes().stream());
Stream<AnnotatedElement> newElements = allElements.filter(visitedElements::add);
newElements.forEach(this::reportAnnotation);
}
use of java.lang.annotation.Repeatable in project strimzi by strimzi.
the class StrimziRunner method annotations.
/**
* Get the (possibly @Repeatable) annotations on the given element.
* @param element
* @param annotationType
* @param <A>
* @return
*/
<A extends Annotation> List<A> annotations(Annotatable element, Class<A> annotationType) {
final List<A> list;
A c = element.getAnnotation(annotationType);
if (c != null) {
list = singletonList(c);
} else {
Repeatable r = annotationType.getAnnotation(Repeatable.class);
if (r != null) {
Class<? extends Annotation> ra = r.value();
Annotation container = element.getAnnotation(ra);
if (container != null) {
try {
Method value = ra.getDeclaredMethod("value");
list = asList((A[]) value.invoke(container));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} else {
list = emptyList();
}
} else {
list = emptyList();
}
}
return list;
}
use of java.lang.annotation.Repeatable in project mule by mulesoft.
the class MuleExtensionAnnotationParser method parseRepeatableAnnotation.
public static <T extends Annotation> List<AnnotationValueFetcher<T>> parseRepeatableAnnotation(Type extensionType, Class<T> annotation, Function<Annotation, T[]> containerConsumer) {
List<AnnotationValueFetcher<T>> annotationDeclarations = ImmutableList.of();
Repeatable repeatableContainer = annotation.getAnnotation(Repeatable.class);
if (repeatableContainer != null) {
Optional<? extends AnnotationValueFetcher<? extends Annotation>> container = extensionType.getValueFromAnnotation(repeatableContainer.value());
if (container.isPresent()) {
annotationDeclarations = container.get().getInnerAnnotations((Function) containerConsumer);
}
}
Optional<AnnotationValueFetcher<T>> singleDeclaration = extensionType.getValueFromAnnotation(annotation);
if (singleDeclaration.isPresent()) {
annotationDeclarations = Collections.singletonList(singleDeclaration.get());
}
return annotationDeclarations;
}
Aggregations