Java Code Examples for java.lang.annotation.Repeatable#value()

The following examples show how to use java.lang.annotation.Repeatable#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static List<? extends Annotation> getAnnotation(Annotation a) {
    Class<?> annotated = a.annotationType();
    Method valueMethod = getValueMethod(annotated);
    if (valueMethod != null) {
        Class<?> returnType = valueMethod.getReturnType();
        if (returnType.isArray()) {
            Class<?> candidate = returnType.getComponentType();
            Repeatable r = candidate.getAnnotation(Repeatable.class);
            if (r != null) {
                Class<?> repeatClass = r.value();
                if (annotated == repeatClass) {
                    return getAnnotationValues(a, valueMethod);
                }
            }
        }
    }
    List<Annotation> annos = new ArrayList<>();
    annos.add(a);
    return annos;
}
 
Example 2
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static List<? extends Annotation> getAnnotation(Annotation a) {
    Class<?> annotated = a.annotationType();
    Method valueMethod = getValueMethod(annotated);
    if (valueMethod != null) {
        Class<?> returnType = valueMethod.getReturnType();
        if (returnType.isArray()) {
            Class<?> candidate = returnType.getComponentType();
            Repeatable r = candidate.getAnnotation(Repeatable.class);
            if (r != null) {
                Class<?> repeatClass = r.value();
                if (annotated == repeatClass) {
                    return getAnnotationValues(a, valueMethod);
                }
            }
        }
    }
    List<Annotation> annos = new ArrayList<>();
    annos.add(a);
    return annos;
}
 
Example 3
Source File: AuthCheckerHandlerInterceptor.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void scanCheckAnnos(AnnotatedElement annotatedElement, TagArrayList<Annotation> checkAnnos) {
    Annotation[] annotations = AnnotationUtils.getAnnotations(annotatedElement);
    if (CollectionUtil.isNotEmpty(annotations)) {
        for (Annotation annotation : annotations) {
            //在anno上查找,是否有anno标注为Check
            Check check = AnnotationUtils.getAnnotation(annotation, Check.class);
            if (check != null) {
                Repeatable repeatable = AnnotationUtils.getAnnotation(annotation, Repeatable.class);
                if (repeatable != null) {
                    Class<? extends Annotation> realCheckAnnoClazz = repeatable.value();
                    Set<? extends Annotation> realCheckAnnos = AnnotatedElementUtils.getMergedRepeatableAnnotations(annotatedElement,
                        realCheckAnnoClazz);
                    checkAnnos.addAll(realCheckAnnos);
                } else {
                    checkAnnos.add(annotation);
                }
            }
        }
    }
}
 
Example 4
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static List<? extends Annotation> getAnnotation(Annotation a) {
    Class<?> annotated = a.annotationType();
    Method valueMethod = getValueMethod(annotated);
    if (valueMethod != null) {
        Class<?> returnType = valueMethod.getReturnType();
        if (returnType.isArray()) {
            Class<?> candidate = returnType.getComponentType();
            Repeatable r = candidate.getAnnotation(Repeatable.class);
            if (r != null) {
                Class<?> repeatClass = r.value();
                if (annotated == repeatClass) {
                    return getAnnotationValues(a, valueMethod);
                }
            }
        }
    }
    List<Annotation> annos = new ArrayList<>();
    annos.add(a);
    return annos;
}
 
Example 5
Source File: AnnoConstruct.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        Repeatable repeatable = null;
        repeatable = annoType.getAnnotation(Repeatable.class);
        return (repeatable == null) ? null : repeatable.value();
    }
    return null;
}
 
Example 6
Source File: RepeatableContainers.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private Class<? extends Annotation> deduceContainer(Class<? extends Annotation> repeatable) {
	Repeatable annotation = repeatable.getAnnotation(Repeatable.class);
	Assert.notNull(annotation, () -> "Annotation type must be a repeatable annotation: " +
				"failed to resolve container type for " + repeatable.getName());
	return annotation.value();
}
 
Example 7
Source File: AnnotationUtils.java    From micronaut-test with Apache License 2.0 4 votes vote down vote up
/**
 * Find all <em>repeatable</em> {@linkplain Annotation annotations} of
 * {@code annotationType} that are either <em>present</em>, <em>indirectly
 * present</em>, or <em>meta-present</em> on the supplied {@link AnnotatedElement}.
 *
 * <p>This method extends the functionality of
 * {@link java.lang.reflect.AnnotatedElement#getAnnotationsByType(Class)}
 * with additional support for meta-annotations.
 *
 * <p>In addition, if the element is a class and the repeatable annotation
 * is {@link java.lang.annotation.Inherited @Inherited}, this method will
 * search on superclasses first in order to support top-down semantics.
 * The result is that this algorithm finds repeatable annotations that
 * would be <em>shadowed</em> and therefore not visible according to Java's
 * standard semantics for inherited, repeatable annotations.
 *
 * <p>If the element is a class and the repeatable annotation is not
 * discovered within the class hierarchy, this method will additionally
 * search on interfaces implemented by each class in the hierarchy.
 *
 * <p>If the supplied {@code element} is {@code null}, this method simply
 * returns an empty list.
 *
 * @param element        the element to search on, potentially {@code null}
 * @param annotationType the repeatable annotation type to search for; never {@code null}
 * @param <A>            the annotation instance
 * @return the list of all such annotations found; neither {@code null} nor mutable
 * @see java.lang.annotation.Repeatable
 * @see java.lang.annotation.Inherited
 */
public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element,
                                                                       Class<A> annotationType) {
    if (annotationType == null) {
        throw new IllegalArgumentException("annotationType must not be null");
    }
    Repeatable repeatable = annotationType.getAnnotation(Repeatable.class);
    if (repeatable == null) {
        throw new IllegalArgumentException(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));
}
 
Example 8
Source File: AnnoConstruct.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
    Repeatable repeatable = annoType.getAnnotation(Repeatable.class);
    return (repeatable == null) ? null : repeatable.value();
}
 
Example 9
Source File: AnnotatedElements.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Find the {@code \@Repeatable} container annotation class for an annotation class, or
 * {@code null}.
 *
 * <p>
 * Given:
 *
 * <code>
 *  @Repeatable(X.class)
 *  @interface SomeName {     <--- = annotationClass
 *  }...
 * </code>
 *
 * <p>
 * Returns {@code X.class}
 *
 * Otherwise if there was no {@code \@Repeatable} annotation, return {@code null}.
 * </p>
 */
private static <T extends Annotation> Class<? extends Annotation>
    getRepeatableAnnotationContainerClassFor(Class<T> annotationClass) {

  Repeatable repeatableAnnotation = annotationClass.getDeclaredAnnotation(Repeatable.class);
  return (repeatableAnnotation == null) ? null : repeatableAnnotation.value();
}
 
Example 10
Source File: AnnotationUtils.java    From beihu-boot with Apache License 2.0 2 votes vote down vote up
/**
 * Resolve the container type for the supplied repeatable {@code annotationType}.
 * <p>Automatically detects a <em>container annotation</em> declared via
 * {@link Repeatable}. If the supplied annotation type
 * is not annotated with {@code @Repeatable}, this method simply returns
 * {@code null}.
 *
 * @since 4.2
 */
static Class<? extends Annotation> resolveContainerAnnotationType(Class<? extends Annotation> annotationType) {
    Repeatable repeatable = getAnnotation(annotationType, Repeatable.class);
    return (repeatable != null ? repeatable.value() : null);
}
 
Example 11
Source File: AnnotationUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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);
}