Skip to content

Commit fd34533

Browse files
committed
Merge branch '5.3.x'
2 parents 84568e8 + 29d9828 commit fd34533

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@
8585
* </tr>
8686
* </table>
8787
*
88-
* <p>{@link MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement)
88+
* <p>{@code MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement)
8989
* from} any Java {@link AnnotatedElement}. They may also be used for sources that
9090
* don't use reflection (such as those that directly parse bytecode).
9191
*
@@ -94,7 +94,7 @@
9494
* example, {@link SearchStrategy#TYPE_HIERARCHY} will search both superclasses and
9595
* implemented interfaces.
9696
*
97-
* <p>From a {@link MergedAnnotations} instance you can either
97+
* <p>From a {@code MergedAnnotations} instance you can either
9898
* {@linkplain #get(String) get} a single annotation, or {@linkplain #stream()
9999
* stream all annotations} or just those that match {@linkplain #stream(String)
100100
* a specific type}. You can also quickly tell if an annotation
@@ -138,7 +138,7 @@
138138
public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>> {
139139

140140
/**
141-
* Determine if the specified annotation is either directly present or
141+
* Determine if the specified annotation type is either directly present or
142142
* meta-present.
143143
* <p>Equivalent to calling {@code get(annotationType).isPresent()}.
144144
* @param annotationType the annotation type to check
@@ -147,7 +147,7 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
147147
<A extends Annotation> boolean isPresent(Class<A> annotationType);
148148

149149
/**
150-
* Determine if the specified annotation is either directly present or
150+
* Determine if the specified annotation type is either directly present or
151151
* meta-present.
152152
* <p>Equivalent to calling {@code get(annotationType).isPresent()}.
153153
* @param annotationType the fully qualified class name of the annotation type
@@ -157,15 +157,15 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
157157
boolean isPresent(String annotationType);
158158

159159
/**
160-
* Determine if the specified annotation is directly present.
160+
* Determine if the specified annotation type is directly present.
161161
* <p>Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
162162
* @param annotationType the annotation type to check
163163
* @return {@code true} if the annotation is directly present
164164
*/
165165
<A extends Annotation> boolean isDirectlyPresent(Class<A> annotationType);
166166

167167
/**
168-
* Determine if the specified annotation is directly present.
168+
* Determine if the specified annotation type is directly present.
169169
* <p>Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
170170
* @param annotationType the fully qualified class name of the annotation type
171171
* to check
@@ -256,17 +256,17 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
256256

257257
/**
258258
* Stream all annotations and meta-annotations that match the specified
259-
* type. The resulting stream follows the same ordering rules as
260-
* {@link #stream()}.
259+
* type.
260+
* <p>The resulting stream follows the same ordering rules as {@link #stream()}.
261261
* @param annotationType the annotation type to match
262262
* @return a stream of matching annotations
263263
*/
264264
<A extends Annotation> Stream<MergedAnnotation<A>> stream(Class<A> annotationType);
265265

266266
/**
267267
* Stream all annotations and meta-annotations that match the specified
268-
* type. The resulting stream follows the same ordering rules as
269-
* {@link #stream()}.
268+
* type.
269+
* <p>The resulting stream follows the same ordering rules as {@link #stream()}.
270270
* @param annotationType the fully qualified class name of the annotation type
271271
* to match
272272
* @return a stream of matching annotations
@@ -275,7 +275,7 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
275275

276276
/**
277277
* Stream all annotations and meta-annotations contained in this collection.
278-
* The resulting stream is ordered first by the
278+
* <p>The resulting stream is ordered first by the
279279
* {@linkplain MergedAnnotation#getAggregateIndex() aggregate index} and then
280280
* by the annotation distance (with the closest annotations first). This ordering
281281
* means that, for most use-cases, the most suitable annotations appear
@@ -287,13 +287,13 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
287287

288288
/**
289289
* Create a new {@link MergedAnnotations} instance containing all
290-
* annotations and meta-annotations from the specified element. The
291-
* resulting instance will not include any inherited annotations. If you
292-
* want to include those as well you should use
290+
* annotations and meta-annotations from the specified element.
291+
* <p>The resulting instance will not include any inherited annotations. If
292+
* you want to include those as well you should use
293293
* {@link #from(AnnotatedElement, SearchStrategy)} with an appropriate
294294
* {@link SearchStrategy}.
295295
* @param element the source element
296-
* @return a {@link MergedAnnotations} instance containing the element's
296+
* @return a {@code MergedAnnotations} instance containing the element's
297297
* annotations
298298
*/
299299
static MergedAnnotations from(AnnotatedElement element) {
@@ -306,7 +306,7 @@ static MergedAnnotations from(AnnotatedElement element) {
306306
* depending on the {@link SearchStrategy}, related inherited elements.
307307
* @param element the source element
308308
* @param searchStrategy the search strategy to use
309-
* @return a {@link MergedAnnotations} instance containing the merged
309+
* @return a {@code MergedAnnotations} instance containing the merged
310310
* element annotations
311311
*/
312312
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy) {
@@ -321,7 +321,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
321321
* @param searchStrategy the search strategy to use
322322
* @param repeatableContainers the repeatable containers that may be used by
323323
* the element annotations or the meta-annotations
324-
* @return a {@link MergedAnnotations} instance containing the merged
324+
* @return a {@code MergedAnnotations} instance containing the merged
325325
* element annotations
326326
*/
327327
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
@@ -340,7 +340,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
340340
* the element annotations or the meta-annotations
341341
* @param annotationFilter an annotation filter used to restrict the
342342
* annotations considered
343-
* @return a {@link MergedAnnotations} instance containing the merged
343+
* @return a {@code MergedAnnotations} instance containing the merged
344344
* annotations for the supplied element
345345
*/
346346
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
@@ -355,7 +355,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
355355
* Create a new {@link MergedAnnotations} instance from the specified
356356
* annotations.
357357
* @param annotations the annotations to include
358-
* @return a {@link MergedAnnotations} instance containing the annotations
358+
* @return a {@code MergedAnnotations} instance containing the annotations
359359
* @see #from(Object, Annotation...)
360360
*/
361361
static MergedAnnotations from(Annotation... annotations) {
@@ -369,7 +369,7 @@ static MergedAnnotations from(Annotation... annotations) {
369369
* for information and logging. It does not need to <em>actually</em>
370370
* contain the specified annotations, and it will not be searched.
371371
* @param annotations the annotations to include
372-
* @return a {@link MergedAnnotations} instance containing the annotations
372+
* @return a {@code MergedAnnotations} instance containing the annotations
373373
* @see #from(Annotation...)
374374
* @see #from(AnnotatedElement)
375375
*/
@@ -386,7 +386,7 @@ static MergedAnnotations from(Object source, Annotation... annotations) {
386386
* @param annotations the annotations to include
387387
* @param repeatableContainers the repeatable containers that may be used by
388388
* meta-annotations
389-
* @return a {@link MergedAnnotations} instance containing the annotations
389+
* @return a {@code MergedAnnotations} instance containing the annotations
390390
*/
391391
static MergedAnnotations from(Object source, Annotation[] annotations, RepeatableContainers repeatableContainers) {
392392
return from(source, annotations, repeatableContainers, AnnotationFilter.PLAIN);
@@ -403,7 +403,7 @@ static MergedAnnotations from(Object source, Annotation[] annotations, Repeatabl
403403
* meta-annotations
404404
* @param annotationFilter an annotation filter used to restrict the
405405
* annotations considered
406-
* @return a {@link MergedAnnotations} instance containing the annotations
406+
* @return a {@code MergedAnnotations} instance containing the annotations
407407
*/
408408
static MergedAnnotations from(Object source, Annotation[] annotations,
409409
RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
@@ -416,16 +416,16 @@ static MergedAnnotations from(Object source, Annotation[] annotations,
416416
/**
417417
* Create a new {@link MergedAnnotations} instance from the specified
418418
* collection of directly present annotations. This method allows a
419-
* {@link MergedAnnotations} instance to be created from annotations that
419+
* {@code MergedAnnotations} instance to be created from annotations that
420420
* are not necessarily loaded using reflection. The provided annotations
421421
* must all be {@link MergedAnnotation#isDirectlyPresent() directly present}
422422
* and must have an {@link MergedAnnotation#getAggregateIndex() aggregate
423423
* index} of {@code 0}.
424-
* <p>The resulting {@link MergedAnnotations} instance will contain both the
425-
* specified annotations, and any meta-annotations that can be read using
424+
* <p>The resulting {@code MergedAnnotations} instance will contain both the
425+
* specified annotations and any meta-annotations that can be read using
426426
* reflection.
427427
* @param annotations the annotations to include
428-
* @return a {@link MergedAnnotations} instance containing the annotations
428+
* @return a {@code MergedAnnotations} instance containing the annotations
429429
* @see MergedAnnotation#of(ClassLoader, Object, Class, java.util.Map)
430430
*/
431431
static MergedAnnotations of(Collection<MergedAnnotation<?>> annotations) {
@@ -435,7 +435,8 @@ static MergedAnnotations of(Collection<MergedAnnotation<?>> annotations) {
435435

436436
/**
437437
* Search strategies supported by
438-
* {@link MergedAnnotations#from(AnnotatedElement, SearchStrategy)}.
438+
* {@link MergedAnnotations#from(AnnotatedElement, SearchStrategy)} and
439+
* variants of that method.
439440
*
440441
* <p>Each strategy creates a different set of aggregates that will be
441442
* combined to create the final {@link MergedAnnotations}.
@@ -451,39 +452,49 @@ enum SearchStrategy {
451452

452453
/**
453454
* Find all directly declared annotations as well as any
454-
* {@link Inherited @Inherited} superclass annotations. This strategy
455-
* is only really useful when used with {@link Class} types since the
456-
* {@link Inherited @Inherited} annotation is ignored for all other
457-
* {@linkplain AnnotatedElement annotated elements}. This strategy does
458-
* not search implemented interfaces.
455+
* {@link Inherited @Inherited} superclass annotations.
456+
* <p>This strategy is only really useful when used with {@link Class}
457+
* types since the {@link Inherited @Inherited} annotation is ignored for
458+
* all other {@linkplain AnnotatedElement annotated elements}.
459+
* <p>This strategy does not search implemented interfaces.
459460
*/
460461
INHERITED_ANNOTATIONS,
461462

462463
/**
463-
* Find all directly declared and superclass annotations. This strategy
464-
* is similar to {@link #INHERITED_ANNOTATIONS} except the annotations
465-
* do not need to be meta-annotated with {@link Inherited @Inherited}.
466-
* This strategy does not search implemented interfaces.
464+
* Find all directly declared and superclass annotations.
465+
* <p>This strategy is similar to {@link #INHERITED_ANNOTATIONS} except
466+
* the annotations do not need to be meta-annotated with
467+
* {@link Inherited @Inherited}.
468+
* <p>This strategy does not search implemented interfaces.
467469
*/
468470
SUPERCLASS,
469471

470472
/**
471473
* Perform a full search of the entire type hierarchy, including
472-
* superclasses and implemented interfaces. Superclass annotations do
473-
* not need to be meta-annotated with {@link Inherited @Inherited}.
474+
* superclasses and implemented interfaces.
475+
* <p>Superclass annotations do not need to be meta-annotated with
476+
* {@link Inherited @Inherited}.
474477
*/
475478
TYPE_HIERARCHY,
476479

477480
/**
478481
* Perform a full search of the entire type hierarchy on the source
479-
* <em>and</em> any enclosing classes. This strategy is similar to
480-
* {@link #TYPE_HIERARCHY} except that {@linkplain Class#getEnclosingClass()
481-
* enclosing classes} are also searched. Superclass annotations do not
482-
* need to be meta-annotated with {@link Inherited @Inherited}. When
483-
* searching a {@link Method} source, this strategy is identical to
484-
* {@link #TYPE_HIERARCHY}.
482+
* <em>and</em> any enclosing classes.
483+
* <p>This strategy is similar to {@link #TYPE_HIERARCHY} except that
484+
* {@linkplain Class#getEnclosingClass() enclosing classes} are also
485+
* searched.
486+
* <p>Superclass and enclosing class annotations do not need to be
487+
* meta-annotated with {@link Inherited @Inherited}.
488+
* <p>When searching a {@link Method} source, this strategy is identical
489+
* to {@link #TYPE_HIERARCHY}.
490+
* <p><strong>WARNING:</strong> This strategy searches recursively for
491+
* annotations on the enclosing class for any source type, regardless
492+
* whether the source type is an <em>inner class</em>, a {@code static}
493+
* nested class, or a nested interface. Thus, it may find more annotations
494+
* than you would expect.
485495
*/
486496
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
497+
487498
}
488499

489500
}

0 commit comments

Comments
 (0)