diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java index 55dff9086f7..81822f690ff 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ import org.springframework.util.Assert; * * * - *
{@link MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement) + *
{@code MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement) * from} any Java {@link AnnotatedElement}. They may also be used for sources that * don't use reflection (such as those that directly parse bytecode). * @@ -94,7 +94,7 @@ import org.springframework.util.Assert; * example, {@link SearchStrategy#TYPE_HIERARCHY} will search both superclasses and * implemented interfaces. * - *
From a {@link MergedAnnotations} instance you can either + *
From a {@code MergedAnnotations} instance you can either
* {@linkplain #get(String) get} a single annotation, or {@linkplain #stream()
* stream all annotations} or just those that match {@linkplain #stream(String)
* a specific type}. You can also quickly tell if an annotation
@@ -138,7 +138,7 @@ import org.springframework.util.Assert;
public interface MergedAnnotations extends Iterable Equivalent to calling {@code get(annotationType).isPresent()}.
* @param annotationType the annotation type to check
@@ -147,7 +147,7 @@ public interface MergedAnnotations extends Iterable Equivalent to calling {@code get(annotationType).isPresent()}.
* @param annotationType the fully qualified class name of the annotation type
@@ -157,7 +157,7 @@ public interface MergedAnnotations extends Iterable Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
* @param annotationType the annotation type to check
* @return {@code true} if the annotation is directly present
@@ -165,7 +165,7 @@ public interface MergedAnnotations extends Iterable Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
* @param annotationType the fully qualified class name of the annotation type
* to check
@@ -256,8 +256,8 @@ public interface MergedAnnotations extends Iterable The resulting stream follows the same ordering rules as {@link #stream()}.
* @param annotationType the annotation type to match
* @return a stream of matching annotations
*/
@@ -265,8 +265,8 @@ public interface MergedAnnotations extends Iterable The resulting stream follows the same ordering rules as {@link #stream()}.
* @param annotationType the fully qualified class name of the annotation type
* to match
* @return a stream of matching annotations
@@ -275,7 +275,7 @@ public interface MergedAnnotations extends Iterable The resulting stream is ordered first by the
* {@linkplain MergedAnnotation#getAggregateIndex() aggregate index} and then
* by the annotation distance (with the closest annotations first). This ordering
* means that, for most use-cases, the most suitable annotations appear
@@ -287,13 +287,13 @@ public interface MergedAnnotations extends Iterable The resulting instance will not include any inherited annotations. If
+ * you want to include those as well you should use
* {@link #from(AnnotatedElement, SearchStrategy)} with an appropriate
* {@link SearchStrategy}.
* @param element the source element
- * @return a {@link MergedAnnotations} instance containing the element's
+ * @return a {@code MergedAnnotations} instance containing the element's
* annotations
*/
static MergedAnnotations from(AnnotatedElement element) {
@@ -306,7 +306,7 @@ public interface MergedAnnotations extends Iterable The resulting {@link MergedAnnotations} instance will contain both the
- * specified annotations, and any meta-annotations that can be read using
+ * The resulting {@code MergedAnnotations} instance will contain both the
+ * specified annotations and any meta-annotations that can be read using
* reflection.
* @param annotations the annotations to include
- * @return a {@link MergedAnnotations} instance containing the annotations
+ * @return a {@code MergedAnnotations} instance containing the annotations
* @see MergedAnnotation#of(ClassLoader, Object, Class, java.util.Map)
*/
static MergedAnnotations of(Collection Each strategy creates a different set of aggregates that will be
* combined to create the final {@link MergedAnnotations}.
@@ -451,39 +452,49 @@ public interface MergedAnnotations extends Iterable This strategy is only really useful when used with {@link Class}
+ * types since the {@link Inherited @Inherited} annotation is ignored for
+ * all other {@linkplain AnnotatedElement annotated elements}.
+ * This strategy does not search implemented interfaces.
*/
INHERITED_ANNOTATIONS,
/**
- * Find all directly declared and superclass annotations. This strategy
- * is similar to {@link #INHERITED_ANNOTATIONS} except the annotations
- * do not need to be meta-annotated with {@link Inherited @Inherited}.
- * This strategy does not search implemented interfaces.
+ * Find all directly declared and superclass annotations.
+ * This strategy is similar to {@link #INHERITED_ANNOTATIONS} except
+ * the annotations do not need to be meta-annotated with
+ * {@link Inherited @Inherited}.
+ * This strategy does not search implemented interfaces.
*/
SUPERCLASS,
/**
* Perform a full search of the entire type hierarchy, including
- * superclasses and implemented interfaces. Superclass annotations do
- * not need to be meta-annotated with {@link Inherited @Inherited}.
+ * superclasses and implemented interfaces.
+ * Superclass annotations do not need to be meta-annotated with
+ * {@link Inherited @Inherited}.
*/
TYPE_HIERARCHY,
/**
* Perform a full search of the entire type hierarchy on the source
- * and any enclosing classes. This strategy is similar to
- * {@link #TYPE_HIERARCHY} except that {@linkplain Class#getEnclosingClass()
- * enclosing classes} are also searched. Superclass annotations do not
- * need to be meta-annotated with {@link Inherited @Inherited}. When
- * searching a {@link Method} source, this strategy is identical to
- * {@link #TYPE_HIERARCHY}.
+ * and any enclosing classes.
+ * This strategy is similar to {@link #TYPE_HIERARCHY} except that
+ * {@linkplain Class#getEnclosingClass() enclosing classes} are also
+ * searched.
+ * Superclass and enclosing class annotations do not need to be
+ * meta-annotated with {@link Inherited @Inherited}.
+ * When searching a {@link Method} source, this strategy is identical
+ * to {@link #TYPE_HIERARCHY}.
+ * WARNING: This strategy searches recursively for
+ * annotations on the enclosing class for any source type, regardless
+ * whether the source type is an inner class, a {@code static}
+ * nested class, or a nested interface. Thus, it may find more annotations
+ * than you would expect.
*/
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
+
}
}