26
26
import org .springframework .util .LinkedMultiValueMap ;
27
27
import org .springframework .util .MultiValueMap ;
28
28
29
- import static org .springframework .core .annotation .AnnotationUtils .*;
30
-
31
29
/**
32
30
* Utility class used to collect all annotation values including those declared on
33
31
* meta-annotations.
@@ -41,14 +39,16 @@ public class AnnotatedElementUtils {
41
39
42
40
public static Set <String > getMetaAnnotationTypes (AnnotatedElement element , String annotationType ) {
43
41
final Set <String > types = new LinkedHashSet <String >();
44
- process (element , annotationType , true , new Processor <Object >() {
42
+ process (element , annotationType , false , new Processor <Object >() {
43
+
45
44
@ Override
46
45
public Object process (Annotation annotation , int metaDepth ) {
47
46
if (metaDepth > 0 ) {
48
47
types .add (annotation .annotationType ().getName ());
49
48
}
50
49
return null ;
51
50
}
51
+
52
52
@ Override
53
53
public void postProcess (Annotation annotation , Object result ) {
54
54
}
@@ -57,26 +57,30 @@ public void postProcess(Annotation annotation, Object result) {
57
57
}
58
58
59
59
public static boolean hasMetaAnnotationTypes (AnnotatedElement element , String annotationType ) {
60
- return Boolean .TRUE .equals (process (element , annotationType , true , new Processor <Boolean >() {
60
+ return Boolean .TRUE .equals (process (element , annotationType , false , new Processor <Boolean >() {
61
+
61
62
@ Override
62
63
public Boolean process (Annotation annotation , int metaDepth ) {
63
64
if (metaDepth > 0 ) {
64
65
return Boolean .TRUE ;
65
66
}
66
67
return null ;
67
68
}
69
+
68
70
@ Override
69
71
public void postProcess (Annotation annotation , Boolean result ) {
70
72
}
71
73
}));
72
74
}
73
75
74
76
public static boolean isAnnotated (AnnotatedElement element , String annotationType ) {
75
- return Boolean .TRUE .equals (process (element , annotationType , true , new Processor <Boolean >() {
77
+ return Boolean .TRUE .equals (process (element , annotationType , false , new Processor <Boolean >() {
78
+
76
79
@ Override
77
80
public Boolean process (Annotation annotation , int metaDepth ) {
78
81
return Boolean .TRUE ;
79
82
}
83
+
80
84
@ Override
81
85
public void postProcess (Annotation annotation , Boolean result ) {
82
86
}
@@ -90,16 +94,18 @@ public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement elem
90
94
public static AnnotationAttributes getAnnotationAttributes (AnnotatedElement element , String annotationType ,
91
95
final boolean classValuesAsString , final boolean nestedAnnotationsAsMap ) {
92
96
93
- return process (element , annotationType , true , new Processor <AnnotationAttributes >() {
97
+ return process (element , annotationType , false , new Processor <AnnotationAttributes >() {
98
+
94
99
@ Override
95
100
public AnnotationAttributes process (Annotation annotation , int metaDepth ) {
96
101
return AnnotationUtils .getAnnotationAttributes (annotation , classValuesAsString , nestedAnnotationsAsMap );
97
102
}
103
+
98
104
@ Override
99
105
public void postProcess (Annotation annotation , AnnotationAttributes result ) {
100
106
for (String key : result .keySet ()) {
101
- if (!VALUE .equals (key )) {
102
- Object value = getValue (annotation , key );
107
+ if (!AnnotationUtils . VALUE .equals (key )) {
108
+ Object value = AnnotationUtils . getValue (annotation , key );
103
109
if (value != null ) {
104
110
result .put (key , value );
105
111
}
@@ -109,7 +115,8 @@ public void postProcess(Annotation annotation, AnnotationAttributes result) {
109
115
});
110
116
}
111
117
112
- public static MultiValueMap <String , Object > getAllAnnotationAttributes (AnnotatedElement element , String annotationType ) {
118
+ public static MultiValueMap <String , Object > getAllAnnotationAttributes (AnnotatedElement element ,
119
+ String annotationType ) {
113
120
return getAllAnnotationAttributes (element , annotationType , false , false );
114
121
}
115
122
@@ -118,6 +125,7 @@ public static MultiValueMap<String, Object> getAllAnnotationAttributes(Annotated
118
125
119
126
final MultiValueMap <String , Object > attributes = new LinkedMultiValueMap <String , Object >();
120
127
process (element , annotationType , false , new Processor <Void >() {
128
+
121
129
@ Override
122
130
public Void process (Annotation annotation , int metaDepth ) {
123
131
if (annotation .annotationType ().getName ().equals (annotationType )) {
@@ -128,11 +136,12 @@ public Void process(Annotation annotation, int metaDepth) {
128
136
}
129
137
return null ;
130
138
}
139
+
131
140
@ Override
132
141
public void postProcess (Annotation annotation , Void result ) {
133
142
for (String key : attributes .keySet ()) {
134
- if (!VALUE .equals (key )) {
135
- Object value = getValue (annotation , key );
143
+ if (!AnnotationUtils . VALUE .equals (key )) {
144
+ Object value = AnnotationUtils . getValue (annotation , key );
136
145
if (value != null ) {
137
146
attributes .add (key , value );
138
147
}
@@ -161,7 +170,8 @@ private static <T> T process(AnnotatedElement element, String annotationType, bo
161
170
Processor <T > processor ) {
162
171
163
172
try {
164
- return doProcess (element , annotationType , traverseClassHierarchy , processor , new HashSet <AnnotatedElement >(), 0 );
173
+ return doProcess (element , annotationType , traverseClassHierarchy , processor ,
174
+ new HashSet <AnnotatedElement >(), 0 );
165
175
}
166
176
catch (Throwable ex ) {
167
177
throw new IllegalStateException ("Failed to introspect annotations: " + element , ex );
@@ -189,8 +199,8 @@ private static <T> T doProcess(AnnotatedElement element, String annotationType,
189
199
Processor <T > processor , Set <AnnotatedElement > visited , int metaDepth ) {
190
200
191
201
if (visited .add (element )) {
192
- Annotation [] annotations =
193
- ( traverseClassHierarchy ? element . getDeclaredAnnotations () : element .getAnnotations ());
202
+ Annotation [] annotations = ( traverseClassHierarchy ? element . getDeclaredAnnotations ()
203
+ : element .getAnnotations ());
194
204
for (Annotation annotation : annotations ) {
195
205
if (annotation .annotationType ().getName ().equals (annotationType ) || metaDepth > 0 ) {
196
206
T result = processor .process (annotation , metaDepth );
@@ -206,7 +216,7 @@ private static <T> T doProcess(AnnotatedElement element, String annotationType,
206
216
}
207
217
}
208
218
for (Annotation annotation : annotations ) {
209
- if (!isInJavaLangAnnotationPackage (annotation )) {
219
+ if (!AnnotationUtils . isInJavaLangAnnotationPackage (annotation )) {
210
220
T result = doProcess (annotation .annotationType (), annotationType , traverseClassHierarchy ,
211
221
processor , visited , metaDepth );
212
222
if (result != null ) {
0 commit comments