1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
85
85
* </tr>
86
86
* </table>
87
87
*
88
- * <p>{@link MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement)
88
+ * <p>{@code MergedAnnotations} can be obtained {@linkplain #from(AnnotatedElement)
89
89
* from} any Java {@link AnnotatedElement}. They may also be used for sources that
90
90
* don't use reflection (such as those that directly parse bytecode).
91
91
*
94
94
* example, {@link SearchStrategy#TYPE_HIERARCHY} will search both superclasses and
95
95
* implemented interfaces.
96
96
*
97
- * <p>From a {@link MergedAnnotations} instance you can either
97
+ * <p>From a {@code MergedAnnotations} instance you can either
98
98
* {@linkplain #get(String) get} a single annotation, or {@linkplain #stream()
99
99
* stream all annotations} or just those that match {@linkplain #stream(String)
100
100
* a specific type}. You can also quickly tell if an annotation
138
138
public interface MergedAnnotations extends Iterable <MergedAnnotation <Annotation >> {
139
139
140
140
/**
141
- * Determine if the specified annotation is either directly present or
141
+ * Determine if the specified annotation type is either directly present or
142
142
* meta-present.
143
143
* <p>Equivalent to calling {@code get(annotationType).isPresent()}.
144
144
* @param annotationType the annotation type to check
@@ -147,7 +147,7 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
147
147
<A extends Annotation > boolean isPresent (Class <A > annotationType );
148
148
149
149
/**
150
- * Determine if the specified annotation is either directly present or
150
+ * Determine if the specified annotation type is either directly present or
151
151
* meta-present.
152
152
* <p>Equivalent to calling {@code get(annotationType).isPresent()}.
153
153
* @param annotationType the fully qualified class name of the annotation type
@@ -157,15 +157,15 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
157
157
boolean isPresent (String annotationType );
158
158
159
159
/**
160
- * Determine if the specified annotation is directly present.
160
+ * Determine if the specified annotation type is directly present.
161
161
* <p>Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
162
162
* @param annotationType the annotation type to check
163
163
* @return {@code true} if the annotation is directly present
164
164
*/
165
165
<A extends Annotation > boolean isDirectlyPresent (Class <A > annotationType );
166
166
167
167
/**
168
- * Determine if the specified annotation is directly present.
168
+ * Determine if the specified annotation type is directly present.
169
169
* <p>Equivalent to calling {@code get(annotationType).isDirectlyPresent()}.
170
170
* @param annotationType the fully qualified class name of the annotation type
171
171
* to check
@@ -256,17 +256,17 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
256
256
257
257
/**
258
258
* 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()}.
261
261
* @param annotationType the annotation type to match
262
262
* @return a stream of matching annotations
263
263
*/
264
264
<A extends Annotation > Stream <MergedAnnotation <A >> stream (Class <A > annotationType );
265
265
266
266
/**
267
267
* 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()}.
270
270
* @param annotationType the fully qualified class name of the annotation type
271
271
* to match
272
272
* @return a stream of matching annotations
@@ -275,7 +275,7 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
275
275
276
276
/**
277
277
* 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
279
279
* {@linkplain MergedAnnotation#getAggregateIndex() aggregate index} and then
280
280
* by the annotation distance (with the closest annotations first). This ordering
281
281
* means that, for most use-cases, the most suitable annotations appear
@@ -287,13 +287,13 @@ <A extends Annotation> MergedAnnotation<A> get(String annotationType,
287
287
288
288
/**
289
289
* 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
293
293
* {@link #from(AnnotatedElement, SearchStrategy)} with an appropriate
294
294
* {@link SearchStrategy}.
295
295
* @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
297
297
* annotations
298
298
*/
299
299
static MergedAnnotations from (AnnotatedElement element ) {
@@ -306,7 +306,7 @@ static MergedAnnotations from(AnnotatedElement element) {
306
306
* depending on the {@link SearchStrategy}, related inherited elements.
307
307
* @param element the source element
308
308
* @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
310
310
* element annotations
311
311
*/
312
312
static MergedAnnotations from (AnnotatedElement element , SearchStrategy searchStrategy ) {
@@ -321,7 +321,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
321
321
* @param searchStrategy the search strategy to use
322
322
* @param repeatableContainers the repeatable containers that may be used by
323
323
* 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
325
325
* element annotations
326
326
*/
327
327
static MergedAnnotations from (AnnotatedElement element , SearchStrategy searchStrategy ,
@@ -340,7 +340,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
340
340
* the element annotations or the meta-annotations
341
341
* @param annotationFilter an annotation filter used to restrict the
342
342
* annotations considered
343
- * @return a {@link MergedAnnotations} instance containing the merged
343
+ * @return a {@code MergedAnnotations} instance containing the merged
344
344
* annotations for the supplied element
345
345
*/
346
346
static MergedAnnotations from (AnnotatedElement element , SearchStrategy searchStrategy ,
@@ -355,7 +355,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
355
355
* Create a new {@link MergedAnnotations} instance from the specified
356
356
* annotations.
357
357
* @param annotations the annotations to include
358
- * @return a {@link MergedAnnotations} instance containing the annotations
358
+ * @return a {@code MergedAnnotations} instance containing the annotations
359
359
* @see #from(Object, Annotation...)
360
360
*/
361
361
static MergedAnnotations from (Annotation ... annotations ) {
@@ -369,7 +369,7 @@ static MergedAnnotations from(Annotation... annotations) {
369
369
* for information and logging. It does not need to <em>actually</em>
370
370
* contain the specified annotations, and it will not be searched.
371
371
* @param annotations the annotations to include
372
- * @return a {@link MergedAnnotations} instance containing the annotations
372
+ * @return a {@code MergedAnnotations} instance containing the annotations
373
373
* @see #from(Annotation...)
374
374
* @see #from(AnnotatedElement)
375
375
*/
@@ -386,7 +386,7 @@ static MergedAnnotations from(Object source, Annotation... annotations) {
386
386
* @param annotations the annotations to include
387
387
* @param repeatableContainers the repeatable containers that may be used by
388
388
* meta-annotations
389
- * @return a {@link MergedAnnotations} instance containing the annotations
389
+ * @return a {@code MergedAnnotations} instance containing the annotations
390
390
*/
391
391
static MergedAnnotations from (Object source , Annotation [] annotations , RepeatableContainers repeatableContainers ) {
392
392
return from (source , annotations , repeatableContainers , AnnotationFilter .PLAIN );
@@ -403,7 +403,7 @@ static MergedAnnotations from(Object source, Annotation[] annotations, Repeatabl
403
403
* meta-annotations
404
404
* @param annotationFilter an annotation filter used to restrict the
405
405
* annotations considered
406
- * @return a {@link MergedAnnotations} instance containing the annotations
406
+ * @return a {@code MergedAnnotations} instance containing the annotations
407
407
*/
408
408
static MergedAnnotations from (Object source , Annotation [] annotations ,
409
409
RepeatableContainers repeatableContainers , AnnotationFilter annotationFilter ) {
@@ -416,16 +416,16 @@ static MergedAnnotations from(Object source, Annotation[] annotations,
416
416
/**
417
417
* Create a new {@link MergedAnnotations} instance from the specified
418
418
* 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
420
420
* are not necessarily loaded using reflection. The provided annotations
421
421
* must all be {@link MergedAnnotation#isDirectlyPresent() directly present}
422
422
* and must have an {@link MergedAnnotation#getAggregateIndex() aggregate
423
423
* 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
426
426
* reflection.
427
427
* @param annotations the annotations to include
428
- * @return a {@link MergedAnnotations} instance containing the annotations
428
+ * @return a {@code MergedAnnotations} instance containing the annotations
429
429
* @see MergedAnnotation#of(ClassLoader, Object, Class, java.util.Map)
430
430
*/
431
431
static MergedAnnotations of (Collection <MergedAnnotation <?>> annotations ) {
@@ -435,7 +435,8 @@ static MergedAnnotations of(Collection<MergedAnnotation<?>> annotations) {
435
435
436
436
/**
437
437
* Search strategies supported by
438
- * {@link MergedAnnotations#from(AnnotatedElement, SearchStrategy)}.
438
+ * {@link MergedAnnotations#from(AnnotatedElement, SearchStrategy)} and
439
+ * variants of that method.
439
440
*
440
441
* <p>Each strategy creates a different set of aggregates that will be
441
442
* combined to create the final {@link MergedAnnotations}.
@@ -451,39 +452,49 @@ enum SearchStrategy {
451
452
452
453
/**
453
454
* 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.
459
460
*/
460
461
INHERITED_ANNOTATIONS ,
461
462
462
463
/**
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.
467
469
*/
468
470
SUPERCLASS ,
469
471
470
472
/**
471
473
* 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}.
474
477
*/
475
478
TYPE_HIERARCHY ,
476
479
477
480
/**
478
481
* 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.
485
495
*/
486
496
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
497
+
487
498
}
488
499
489
500
}
0 commit comments