微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.lang.annotation.Repeatable的实例源码

项目:allure-java    文件AllureJunit4.java   
private <T extends Annotation> Stream<Label> getLabels(final Description result,final Class<T> labelAnnotation,final Function<T,Label> extractor) {

    final List<Label> labels = getAnnotationsOnMethod(result,labelAnnotation).stream()
            .map(extractor)
            .collect(Collectors.toList());

    if (labelAnnotation.isAnnotationPresent(Repeatable.class) || labels.isEmpty()) {
        final Stream<Label> onClassLabels = getAnnotationsOnClass(result,labelAnnotation).stream()
                .map(extractor);
        labels.addAll(onClassLabels.collect(Collectors.toList()));
    }

    return labels.stream();
}
项目:holon-core    文件AnnotationUtils.java   
/**
 * 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
 * @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;
}
项目:holon-core    文件AnnotationUtils.java   
/**
 * Get all the annotations of given <code>annotationType</code> present in given annotations list,including any
 * Meta-annotation and supporting repeatable annotations.
 * @param <A> Annotation type
 * @param annotations Annotation list element to inspect
 * @param annotationType Annotation type to lookup
 * @return List of detected annotation of given <code>annotationType</code>,an empty List if none found
 */
@SuppressWarnings("unchecked")
public static <A extends Annotation> List<A> getAnnotations(List<Annotation> annotations,Class<A> annotationType) {
    ObjectUtils.argumentNotNull(annotationType,"Annotation type must be not null");

    if (annotations == null || annotations.isEmpty()) {
        return Collections.emptyList();
    }

    Class<? extends Annotation> repeatableContainerType = null;
    if (annotationType.isAnnotationPresent(Repeatable.class)) {
        repeatableContainerType = annotationType.getAnnotation(Repeatable.class).value();
    }

    List<A> ans = new LinkedList<>();
    for (Annotation annotation : annotations) {
        if (annotationType.equals(annotation.annotationType())) {
            ans.add((A) annotation);
        }
        if (!isInJavaLangAnnotationPackage(annotation) && !annotation.annotationType().equals(annotationType)
                && (repeatableContainerType == null
                        || !annotation.annotationType().equals(repeatableContainerType))) {
            findAnnotations(ans,annotation.annotationType(),repeatableContainerType);
        }
    }
    return ans;
}
项目:rise    文件AsmUtil.java   
/**
 * Return the annotations present by type. Repeated annotations are taken
 * into account
 */
public static List<AnnotationNode> getAnnotationsByType(List<AnnotationNode> annotations,Class<? extends Annotation> annotation) {
    Repeatable repeatable = annotation.getAnnotation(Repeatable.class);
    return getAnnotationsByType(annotations,Type.getInternalName(annotation),repeatable != null ? Type.getInternalName(repeatable.value()) : null);
}
项目:super-csv-annotation    文件AnnotationExpander.java   
/**
 * 繰り返されたアノテーションかどうか判定する。
 * <p>属性「value」に、繰り返しのアノテーション{@link Repeatable}が付与されている
 *    アノテーションの配列を保持しているかどうかで判定する。</p>
 * @param targetAnno
 * @return
 */
private boolean isRepeated(final Annotation targetAnno) {

    try {
        final Method method = targetAnno.getClass().getmethod("value");

        // 値のクラスタイプがアノテーションの配列かどうかのチェック
        final Class<?> returnType = method.getReturnType();
        if(!(returnType.isArray() && Annotation.class.isAssignableFrom(returnType.getComponentType()))) {
            return false;
        }

        final Annotation[] annos = (Annotation[]) method.invoke(targetAnno);
        if(annos.length == 0) {
            return false;
        }

        // @Repetableアノテーションが付与されているかどうか
        if(annos[0].annotationType().getAnnotation(Repeatable.class) != null) {
            return true;
        }

    } catch (Exception e) {

    }

    return false;

}
项目:openjdk-jdk10    文件AnnoConstruct.java   
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
    Repeatable repeatable = annoType.getAnnotation(Repeatable.class);
    return (repeatable == null) ? null : repeatable.value();
}
项目:openjdk9    文件AnnoConstruct.java   
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
    Repeatable repeatable = annoType.getAnnotation(Repeatable.class);
    return (repeatable == null) ? null : repeatable.value();
}
项目:spring4-understanding    文件AnnotationUtilsTests.java   
@Test
public void findRepeatableAnnotationOnComposedAnnotation() {
    Repeatable repeatable = findAnnotation(MyRepeatableMeta1.class,Repeatable.class);
    assertNotNull(repeatable);
    assertEquals(MyRepeatableContainer.class,repeatable.value());
}
项目:dataz-core    文件AnnotationTraverserBuilder.java   
private boolean isRepeatableAnnotation() {
    return annotationClass.isAnnotationPresent(Repeatable.class);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。