/** * Resolve the container type for the supplied repeatable {@code annotationType}. * <p>Automatically detects a <em>container annotation</em> declared via * {@link java.lang.annotation.Repeatable}. If the supplied annotation type * is not annotated with {@code @Repeatable}, this method simply returns * {@code null}. * @since 4.2 */ @Nullable static Class<? extends Annotation> resolveContainerAnnotationType(Class<? extends Annotation> annotationType) { Repeatable repeatable = getAnnotation(annotationType, Repeatable.class); return (repeatable != null ? repeatable.value() : null); }
/** * Resolve the container type for the supplied repeatable {@code annotationType}. * <p>Automatically detects a <em>container annotation</em> declared via * {@link java.lang.annotation.Repeatable}. If the supplied annotation type * is not annotated with {@code @Repeatable}, this method simply returns * {@code null}. * @since 4.2 */ @Nullable static Class<? extends Annotation> resolveContainerAnnotationType(Class<? extends Annotation> annotationType) { Repeatable repeatable = getAnnotation(annotationType, Repeatable.class); return (repeatable != null ? repeatable.value() : null); }
/** * Checks whether this object has the given annotation on the object itself or inherited from a parent. * * @param annotation The annotation * @return True if the annotation is present */ default boolean hasAnnotation(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasAnnotation(repeatable.value()); } else { return hasAnnotation(annotation.getName()); } } return false; }
/** * Checks whether this object has the given annotation directly declared on the object. * * @param annotation The annotation * @return True if the annotation is present */ default boolean hasDeclaredAnnotation(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasDeclaredAnnotation(repeatable.value()); } else { return hasDeclaredAnnotation(annotation.getName()); } } return false; }
/** * Checks whether this object has the given stereotype directly declared on the object. * * @param stereotype The annotation * @return True if the annotation is present */ default boolean hasDeclaredStereotype(@Nullable Class<? extends Annotation> stereotype) { if (stereotype != null) { Repeatable repeatable = stereotype.getAnnotation(Repeatable.class); if (repeatable != null) { return hasDeclaredStereotype(repeatable.value()); } else { return hasDeclaredStereotype(stereotype.getName()); } } return false; }
/** * <p>Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent</p>. * <p> * <p>An annotation stereotype is a meta annotation potentially applied to another annotation</p> * * @param annotation The annotation * @return True if the annotation is present */ default boolean hasStereotype(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasStereotype(repeatable.value()); } else { return hasStereotype(annotation.getName()); } } return false; }
@Test public void findRepeatableAnnotationOnComposedAnnotation() { Repeatable repeatable = findAnnotation(MyRepeatableMeta1.class, Repeatable.class); assertNotNull(repeatable); assertEquals(MyRepeatableContainer.class, repeatable.value()); }
repeatableAnnotations.length > 0 ? repeatableAnnotations[0].value() : null;
public static <T extends Annotation> List<T> parseRepeatableAnnotation(Class<?> extensionType, Class<T> annotation, Function<Annotation, T[]> containerConsumer) { List<T> annotationDeclarations = ImmutableList.of(); Repeatable repeatableContainer = annotation.getAnnotation(Repeatable.class); if (repeatableContainer != null) { Annotation container = IntrospectionUtils.getAnnotation(extensionType, repeatableContainer.value()); if (container != null) { annotationDeclarations = ImmutableList.copyOf(containerConsumer.apply(container)); } } T singleDeclaration = IntrospectionUtils.getAnnotation(extensionType, annotation); if (singleDeclaration != null) { annotationDeclarations = ImmutableList.of(singleDeclaration); } return annotationDeclarations; }
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; }
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) { Repeatable repeatable = annoType.getAnnotation(Repeatable.class); return (repeatable == null) ? null : repeatable.value(); }
private Set<Class<?>> getAnnotatedByRepeatedAnnotation( AnnotatedElement annotationClass) { Repeatable repeatableAnnotation = annotationClass .getAnnotation(Repeatable.class); if (repeatableAnnotation != null) { return reflections .getTypesAnnotatedWith(repeatableAnnotation.value(), true); } return Collections.emptySet(); } }
/** * Resolve the container type for the supplied repeatable {@code annotationType}. * <p>Automatically detects a <em>container annotation</em> declared via * {@link java.lang.annotation.Repeatable}. If the supplied annotation type * is not annotated with {@code @Repeatable}, this method simply returns * {@code null}. * @since 4.2 */ @Nullable static Class<? extends Annotation> resolveContainerAnnotationType(Class<? extends Annotation> annotationType) { Repeatable repeatable = getAnnotation(annotationType, Repeatable.class); return (repeatable != null ? repeatable.value() : null); }
/** * Resolve the container type for the supplied repeatable {@code annotationType}. * <p>Automatically detects a <em>container annotation</em> declared via * {@link java.lang.annotation.Repeatable}. If the supplied annotation type * is not annotated with {@code @Repeatable}, this method simply returns * {@code null}. * @since 4.2 */ @Nullable static Class<? extends Annotation> resolveContainerAnnotationType(Class<? extends Annotation> annotationType) { Repeatable repeatable = getAnnotation(annotationType, Repeatable.class); return (repeatable != null ? repeatable.value() : null); }
@SuppressWarnings("unchecked") private <T extends Annotation> List<T> extractRepeatable(final Description result, final Class<T> clazz) { if (clazz != null && clazz.isAnnotationPresent(Repeatable.class)) { final Repeatable repeatable = clazz.getAnnotation(Repeatable.class); final Class<? extends Annotation> wrapper = repeatable.value(); final Annotation annotation = result.getAnnotation(wrapper); if (Objects.nonNull(annotation)) { try { final Method value = annotation.getClass().getMethod("value"); final Object annotations = value.invoke(annotation); return Arrays.asList((T[]) annotations); } catch (Exception e) { throw new IllegalStateException(e); } } } return Collections.emptyList(); }
public static <T extends Annotation> List<T> parseRepeatableAnnotation(Class<?> extensionType, Class<T> annotation, Function<Annotation, T[]> containerConsumer) { List<T> annotationDeclarations = ImmutableList.of(); Repeatable repeatableContainer = annotation.getAnnotation(Repeatable.class); if (repeatableContainer != null) { Annotation container = IntrospectionUtils.getAnnotation(extensionType, repeatableContainer.value()); if (container != null) { annotationDeclarations = ImmutableList.copyOf(containerConsumer.apply(container)); } } T singleDeclaration = IntrospectionUtils.getAnnotation(extensionType, annotation); if (singleDeclaration != null) { annotationDeclarations = ImmutableList.of(singleDeclaration); } return annotationDeclarations; }
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; }
private <T extends Annotation> List<io.micronaut.core.annotation.AnnotationValue<T>> resolveAnnotationValuesByType(Class<T> annotationType, Map<String, Map<CharSequence, Object>> sourceAnnotations, Map<String, Map<CharSequence, Object>> sourceStereotypes) { Repeatable repeatable = annotationType.getAnnotation(Repeatable.class); if (repeatable != null) { Class<? extends Annotation> repeatableType = repeatable.value(); if (hasStereotype(repeatableType)) { List<io.micronaut.core.annotation.AnnotationValue<T>> results = new ArrayList<>(); if (sourceAnnotations != null) { Map<CharSequence, Object> values = sourceAnnotations.get(repeatableType.getName()); addAnnotationValuesFromData(results, values); } if (sourceStereotypes != null) { Map<CharSequence, Object> values = sourceStereotypes.get(repeatableType.getName()); addAnnotationValuesFromData(results, values); } return results; } } return null; }
private <T extends Annotation> List<io.micronaut.core.annotation.AnnotationValue<T>> resolveAnnotationValuesByType(Class<T> annotationType, Map<String, Map<CharSequence, Object>> sourceAnnotations, Map<String, Map<CharSequence, Object>> sourceStereotypes) { Repeatable repeatable = annotationType.getAnnotation(Repeatable.class); if (repeatable != null) { Class<? extends Annotation> repeatableType = repeatable.value(); if (hasStereotype(repeatableType)) { List<io.micronaut.core.annotation.AnnotationValue<T>> results = new ArrayList<>(); if (sourceAnnotations != null) { Map<CharSequence, Object> values = sourceAnnotations.get(repeatableType.getName()); addAnnotationValuesFromData(results, values); } if (sourceStereotypes != null) { Map<CharSequence, Object> values = sourceStereotypes.get(repeatableType.getName()); addAnnotationValuesFromData(results, values); } return results; } } return null; }
/** * Get all the annotations of given <code>annotationType</code> present in given <code>element</code>, including any * meta-annotation and supporting repeatable annotations. * @param <A> Annotation type * @param element Annotated element to inspect (not null) * @param annotationType Annotation type to lookup (not null) * @return List of detected annotation of given <code>annotationType</code>, an empty List if none found */ public static <A extends Annotation> List<A> getAnnotations(AnnotatedElement element, Class<A> annotationType) { ObjectUtils.argumentNotNull(element, "AnnotatedElement must be not null"); ObjectUtils.argumentNotNull(annotationType, "Annotation type must be not null"); Class<? extends Annotation> repeatableContainerType = null; if (annotationType.isAnnotationPresent(Repeatable.class)) { repeatableContainerType = annotationType.getAnnotation(Repeatable.class).value(); } List<A> annotations = new LinkedList<>(); findAnnotations(annotations, element, annotationType, repeatableContainerType); return annotations; }