Search in sources :

Example 6 with Repeatable

use of java.lang.annotation.Repeatable in project mule by mulesoft.

the class MuleExtensionAnnotationParser method parseRepeatableAnnotation.

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;
}
Also used : Repeatable(java.lang.annotation.Repeatable) Annotation(java.lang.annotation.Annotation)

Example 7 with Repeatable

use of java.lang.annotation.Repeatable in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findRepeatableAnnotationOnComposedAnnotation.

@Test
public void findRepeatableAnnotationOnComposedAnnotation() {
    Repeatable repeatable = findAnnotation(MyRepeatableMeta1.class, Repeatable.class);
    assertNotNull(repeatable);
    assertEquals(MyRepeatableContainer.class, repeatable.value());
}
Also used : Repeatable(java.lang.annotation.Repeatable) Test(org.junit.Test)

Example 8 with Repeatable

use of java.lang.annotation.Repeatable in project graal by oracle.

the class AnnotationTypeFeature method afterRegistration.

@Override
public void afterRegistration(AfterRegistrationAccess access) {
    ImageSingletons.add(AnnotationTypeSupport.class, new AnnotationTypeSupport());
    ((AfterRegistrationAccessImpl) access).getImageClassLoader().allAnnotations().stream().map(a -> a.getAnnotation(Repeatable.class)).filter(Objects::nonNull).map(Repeatable::value).forEach(repeatableAnnotationClasses::add);
}
Also used : ImageSingletons(org.graalvm.nativeimage.ImageSingletons) Feature(org.graalvm.nativeimage.Feature) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) EconomicSet(org.graalvm.collections.EconomicSet) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) AnnotationTypeSupport(com.oracle.svm.core.hub.AnnotationTypeSupport) Objects(java.util.Objects) Stream(java.util.stream.Stream) Repeatable(java.lang.annotation.Repeatable) AfterRegistrationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl) Annotation(java.lang.annotation.Annotation) AnnotatedElement(java.lang.reflect.AnnotatedElement) AfterRegistrationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl) AnnotationTypeSupport(com.oracle.svm.core.hub.AnnotationTypeSupport) Objects(java.util.Objects)

Example 9 with Repeatable

use of java.lang.annotation.Repeatable in project core by weld.

the class Annotations method getRepeatableAnnotationAccessor.

/**
 * Returns the value {@link Method} of a repeatable annotation container or null if the given annotation is not a repeatable
 * annotation container.
 * @param annotation the given annotation
 * @return the value {@link Method} of a repeatable annotation container or null if the given annotation is not a repeatable
 * annotation container
 */
public static Method getRepeatableAnnotationAccessor(Class<? extends Annotation> annotation) {
    Method value;
    if (System.getSecurityManager() == null) {
        value = Reflections.findDeclaredMethodByName(annotation, VALUE_MEMBER_NAME);
    } else {
        value = doPrivileged(action(() -> Reflections.findDeclaredMethodByName(annotation, VALUE_MEMBER_NAME)));
    }
    if (value == null) {
        return null;
    }
    if (!value.getReturnType().isArray()) {
        return null;
    }
    Repeatable repeatable = value.getReturnType().getComponentType().getAnnotation(Repeatable.class);
    if (repeatable == null) {
        return null;
    }
    if (!repeatable.value().equals(annotation)) {
        return null;
    }
    return value;
}
Also used : Repeatable(java.lang.annotation.Repeatable) Method(java.lang.reflect.Method)

Aggregations

Repeatable (java.lang.annotation.Repeatable)9 Annotation (java.lang.annotation.Annotation)4 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)2 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)2 AutomaticFeature (com.oracle.svm.core.annotate.AutomaticFeature)2 AnnotationTypeSupport (com.oracle.svm.core.hub.AnnotationTypeSupport)2 AfterRegistrationAccessImpl (com.oracle.svm.hosted.FeatureImpl.AfterRegistrationAccessImpl)2 DuringAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 Method (java.lang.reflect.Method)2 Objects (java.util.Objects)2 Stream (java.util.stream.Stream)2 EconomicSet (org.graalvm.collections.EconomicSet)2 Feature (org.graalvm.nativeimage.Feature)2 ImageSingletons (org.graalvm.nativeimage.ImageSingletons)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1