Skip to content

Commit e5a292f

Browse files
committed
Deprecate AnnotationFilter.NONE and document MergedAnnotations design
Closes gh-24932
1 parent e36a415 commit e5a292f

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -21,8 +21,15 @@
2121
/**
2222
* Callback interface that can be used to filter specific annotation types.
2323
*
24+
* <p>Note that the {@link MergedAnnotations} model (which this interface has been
25+
* designed for) always ignores lang annotations according to the {@link #PLAIN}
26+
* filter (for efficiency reasons). Any additional filters and even custom filter
27+
* implementations apply within this boundary and may only narrow further from here.
28+
*
2429
* @author Phillip Webb
30+
* @author Juergen Hoeller
2531
* @since 5.2
32+
* @see MergedAnnotations
2633
*/
2734
@FunctionalInterface
2835
public interface AnnotationFilter {
@@ -31,6 +38,7 @@ public interface AnnotationFilter {
3138
* {@link AnnotationFilter} that matches annotations in the
3239
* {@code java.lang} and {@code org.springframework.lang} packages
3340
* and their subpackages.
41+
* <p>This is the default filter in the {@link MergedAnnotations} model.
3442
*/
3543
AnnotationFilter PLAIN = packages("java.lang", "org.springframework.lang");
3644

@@ -66,7 +74,12 @@ public String toString() {
6674
/**
6775
* {@link AnnotationFilter} that never matches and can be used when no
6876
* filtering is needed (allowing for any annotation types to be present).
77+
* @deprecated as of 5.2.6 since the {@link MergedAnnotations} model
78+
* always ignores lang annotations according to the {@link #PLAIN} filter
79+
* (for efficiency reasons)
80+
* @see #PLAIN
6981
*/
82+
@Deprecated
7083
AnnotationFilter NONE = new AnnotationFilter() {
7184
@Override
7285
public boolean matches(Annotation annotation) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -119,6 +119,13 @@
119119
* .forEach(System.out::println);
120120
* </pre>
121121
*
122+
* <p><b>NOTE: The {@code MergedAnnotations} API and its underlying model have
123+
* been designed for composable annotations in Spring's common component model,
124+
* with a focus on attribute aliasing and meta-annotation relationships.</b>
125+
* There is no support for retrieving plain Java annotations with this API;
126+
* please use standard Java reflection or Spring's {@link AnnotationUtils}
127+
* for simple annotation retrieval purposes.
128+
*
122129
* @author Phillip Webb
123130
* @author Sam Brannen
124131
* @since 5.2

spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -24,7 +24,6 @@
2424
import java.util.Set;
2525

2626
import org.springframework.core.annotation.AnnotatedElementUtils;
27-
import org.springframework.core.annotation.AnnotationFilter;
2827
import org.springframework.core.annotation.AnnotationUtils;
2928
import org.springframework.core.annotation.MergedAnnotation;
3029
import org.springframework.core.annotation.MergedAnnotations;
@@ -85,8 +84,7 @@ public StandardAnnotationMetadata(Class<?> introspectedClass) {
8584
public StandardAnnotationMetadata(Class<?> introspectedClass, boolean nestedAnnotationsAsMap) {
8685
super(introspectedClass);
8786
this.mergedAnnotations = MergedAnnotations.from(introspectedClass,
88-
SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none(),
89-
AnnotationFilter.NONE);
87+
SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none());
9088
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
9189
}
9290

0 commit comments

Comments
 (0)