20
20
import java .util .Arrays ;
21
21
import java .util .Collection ;
22
22
23
- import org .springframework .lang .Nullable ;
24
23
import org .springframework .util .Assert ;
25
24
26
25
/**
@@ -37,31 +36,27 @@ public interface AnnotationFilter {
37
36
* {@code java.lang.*} or in the
38
37
* {@code org.springframework.lang.*} package.
39
38
*/
40
- static final AnnotationFilter PLAIN = packages ("java.lang" ,
41
- "org.springframework.lang" );
39
+ AnnotationFilter PLAIN = packages ("java.lang" , "org.springframework.lang" );
42
40
43
41
/**
44
42
* {@link AnnotationFilter} that matches annotations in the
45
43
* {@code java.lang.*} package.
46
44
*/
47
- static final AnnotationFilter JAVA = packages ("java.lang" );
45
+ AnnotationFilter JAVA = packages ("java.lang" );
48
46
49
47
/**
50
48
* {@link AnnotationFilter} that never matches and can be used when no
51
49
* filtering is needed.
52
50
*/
53
- static final AnnotationFilter NONE = new AnnotationFilter () {
54
-
51
+ AnnotationFilter NONE = new AnnotationFilter () {
55
52
@ Override
56
- public boolean matches (@ Nullable String typeName ) {
53
+ public boolean matches (String typeName ) {
57
54
return false ;
58
55
}
59
-
60
56
@ Override
61
57
public String toString () {
62
58
return "No annotation filtering" ;
63
59
}
64
-
65
60
};
66
61
67
62
@@ -70,25 +65,26 @@ public String toString() {
70
65
* @param annotation the annotation to test
71
66
* @return {@code true} if the annotation matches
72
67
*/
73
- default boolean matches (@ Nullable Annotation annotation ) {
74
- return matches (annotation != null ? annotation .annotationType () : null );
68
+ default boolean matches (Annotation annotation ) {
69
+ return matches (annotation .annotationType ());
75
70
}
76
71
77
72
/**
78
73
* Test if the given type matches the filter.
79
74
* @param type the annotation type to test
80
75
* @return {@code true} if the annotation matches
81
76
*/
82
- default boolean matches (@ Nullable Class <?> type ) {
83
- return matches (type != null ? type .getName () : null );
77
+ default boolean matches (Class <?> type ) {
78
+ return matches (type .getName ());
84
79
}
85
80
86
81
/**
87
82
* Test if the given type name matches the filter.
88
83
* @param typeName the annotation type to test
89
84
* @return {@code true} if the annotation matches
90
85
*/
91
- boolean matches (@ Nullable String typeName );
86
+ boolean matches (String typeName );
87
+
92
88
93
89
/**
94
90
* Return a new {@link AnnotationFilter} that matches annotations in the
@@ -107,8 +103,8 @@ static AnnotationFilter packages(String... packages) {
107
103
* @param annotationType the annotation type to check
108
104
* @return the most appropriate annotation filter
109
105
*/
110
- static AnnotationFilter mostAppropriateFor (@ Nullable Class <?> annotationType ) {
111
- return PLAIN .matches (annotationType ) ? NONE : PLAIN ;
106
+ static AnnotationFilter mostAppropriateFor (Class <?> annotationType ) {
107
+ return ( PLAIN .matches (annotationType ) ? NONE : PLAIN ) ;
112
108
}
113
109
114
110
/**
@@ -119,30 +115,6 @@ static AnnotationFilter mostAppropriateFor(@Nullable Class<?> annotationType) {
119
115
* @return the most appropriate annotation filter
120
116
*/
121
117
static AnnotationFilter mostAppropriateFor (Class <?>... annotationTypes ) {
122
- Assert .notNull (annotationTypes , "AnnotationTypes must not be null" );
123
- return mostAppropriateFor (Arrays .asList (annotationTypes ));
124
- }
125
-
126
- /**
127
- * Return an {@link AnnotationFilter} that is the most appropriate for, and
128
- * will always match all the given annotation type. Whenever possible,
129
- * {@link AnnotationFilter#PLAIN} will be returned.
130
- * @param annotationType the annotation type to check
131
- * @return the most appropriate annotation filter
132
- */
133
- static AnnotationFilter mostAppropriateFor (@ Nullable String annotationType ) {
134
- return PLAIN .matches (annotationType ) ? NONE : PLAIN ;
135
- }
136
-
137
- /**
138
- * Return an {@link AnnotationFilter} that is the most appropriate for, and
139
- * will always match all the given annotation types. Whenever possible,
140
- * {@link AnnotationFilter#PLAIN} will be returned.
141
- * @param annotationTypes the annotation types to check
142
- * @return the most appropriate annotation filter
143
- */
144
- static AnnotationFilter mostAppropriateFor (String ... annotationTypes ) {
145
- Assert .notNull (annotationTypes , "AnnotationTypes must not be null" );
146
118
return mostAppropriateFor (Arrays .asList (annotationTypes ));
147
119
}
148
120
@@ -156,20 +128,16 @@ static AnnotationFilter mostAppropriateFor(String... annotationTypes) {
156
128
*/
157
129
@ SuppressWarnings ("unchecked" )
158
130
static AnnotationFilter mostAppropriateFor (Collection <?> annotationTypes ) {
159
- Assert .notNull (annotationTypes , "AnnotationTypes must not be null" );
160
131
for (Object annotationType : annotationTypes ) {
161
132
if (annotationType == null ) {
162
133
continue ;
163
134
}
164
- Assert .isTrue (
165
- annotationType instanceof Class || annotationType instanceof String ,
135
+ Assert .isTrue (annotationType instanceof Class || annotationType instanceof String ,
166
136
"AnnotationType must be a Class or String" );
167
- if (annotationType instanceof Class
168
- && PLAIN .matches ((Class <Annotation >) annotationType )) {
137
+ if (annotationType instanceof Class && PLAIN .matches ((Class <Annotation >) annotationType )) {
169
138
return NONE ;
170
139
}
171
- if (annotationType instanceof String
172
- && PLAIN .matches ((String ) annotationType )) {
140
+ if (annotationType instanceof String && PLAIN .matches ((String ) annotationType )) {
173
141
return NONE ;
174
142
}
175
143
}
0 commit comments