1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2020 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.
20
20
import java .util .ArrayDeque ;
21
21
import java .util .ArrayList ;
22
22
import java .util .Deque ;
23
- import java .util .HashSet ;
24
23
import java .util .List ;
25
24
import java .util .Map ;
26
- import java .util .Set ;
27
25
28
26
import org .springframework .lang .Nullable ;
29
27
import org .springframework .util .ConcurrentReferenceHashMap ;
42
40
* be searched once, regardless of how many times they are actually used.
43
41
*
44
42
* @author Phillip Webb
45
- * @author Sam Brannen
46
43
* @since 5.2
47
44
* @see AnnotationTypeMapping
48
45
*/
@@ -63,22 +60,19 @@ final class AnnotationTypeMappings {
63
60
64
61
65
62
private AnnotationTypeMappings (RepeatableContainers repeatableContainers ,
66
- AnnotationFilter filter , Class <? extends Annotation > annotationType ,
67
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
63
+ AnnotationFilter filter , Class <? extends Annotation > annotationType ) {
68
64
69
65
this .repeatableContainers = repeatableContainers ;
70
66
this .filter = filter ;
71
67
this .mappings = new ArrayList <>();
72
- addAllMappings (annotationType , visitedAnnotationTypes );
68
+ addAllMappings (annotationType );
73
69
this .mappings .forEach (AnnotationTypeMapping ::afterAllMappingsSet );
74
70
}
75
71
76
72
77
- private void addAllMappings (Class <? extends Annotation > annotationType ,
78
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
79
-
73
+ private void addAllMappings (Class <? extends Annotation > annotationType ) {
80
74
Deque <AnnotationTypeMapping > queue = new ArrayDeque <>();
81
- addIfPossible (queue , null , annotationType , null , visitedAnnotationTypes );
75
+ addIfPossible (queue , null , annotationType , null );
82
76
while (!queue .isEmpty ()) {
83
77
AnnotationTypeMapping mapping = queue .removeFirst ();
84
78
this .mappings .add (mapping );
@@ -108,15 +102,14 @@ private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, Annot
108
102
}
109
103
110
104
private void addIfPossible (Deque <AnnotationTypeMapping > queue , AnnotationTypeMapping source , Annotation ann ) {
111
- addIfPossible (queue , source , ann .annotationType (), ann , new HashSet <>() );
105
+ addIfPossible (queue , source , ann .annotationType (), ann );
112
106
}
113
107
114
108
private void addIfPossible (Deque <AnnotationTypeMapping > queue , @ Nullable AnnotationTypeMapping source ,
115
- Class <? extends Annotation > annotationType , @ Nullable Annotation ann ,
116
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
109
+ Class <? extends Annotation > annotationType , @ Nullable Annotation ann ) {
117
110
118
111
try {
119
- queue .addLast (new AnnotationTypeMapping (source , annotationType , ann , visitedAnnotationTypes ));
112
+ queue .addLast (new AnnotationTypeMapping (source , annotationType , ann ));
120
113
}
121
114
catch (Exception ex ) {
122
115
AnnotationUtils .rethrowAnnotationConfigurationException (ex );
@@ -173,37 +166,20 @@ AnnotationTypeMapping get(int index) {
173
166
* @return type mappings for the annotation type
174
167
*/
175
168
static AnnotationTypeMappings forAnnotationType (Class <? extends Annotation > annotationType ) {
176
- return forAnnotationType (annotationType , new HashSet <>());
177
- }
178
-
179
- /**
180
- * Create {@link AnnotationTypeMappings} for the specified annotation type.
181
- * @param annotationType the source annotation type
182
- * @param visitedAnnotationTypes the set of annotations that we have already
183
- * visited; used to avoid infinite recursion for recursive annotations which
184
- * some JVM languages support (such as Kotlin)
185
- * @return type mappings for the annotation type
186
- */
187
- static AnnotationTypeMappings forAnnotationType (Class <? extends Annotation > annotationType ,
188
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
189
-
190
- return forAnnotationType (annotationType , RepeatableContainers .standardRepeatables (),
191
- AnnotationFilter .PLAIN , visitedAnnotationTypes );
169
+ return forAnnotationType (annotationType , AnnotationFilter .PLAIN );
192
170
}
193
171
194
172
/**
195
173
* Create {@link AnnotationTypeMappings} for the specified annotation type.
196
174
* @param annotationType the source annotation type
197
- * @param repeatableContainers the repeatable containers that may be used by
198
- * the meta-annotations
199
175
* @param annotationFilter the annotation filter used to limit which
200
176
* annotations are considered
201
177
* @return type mappings for the annotation type
202
178
*/
203
- static AnnotationTypeMappings forAnnotationType (Class <? extends Annotation > annotationType ,
204
- RepeatableContainers repeatableContainers , AnnotationFilter annotationFilter ) {
179
+ static AnnotationTypeMappings forAnnotationType (
180
+ Class <? extends Annotation > annotationType , AnnotationFilter annotationFilter ) {
205
181
206
- return forAnnotationType (annotationType , repeatableContainers , annotationFilter , new HashSet <>() );
182
+ return forAnnotationType (annotationType , RepeatableContainers . standardRepeatables () , annotationFilter );
207
183
}
208
184
209
185
/**
@@ -213,24 +189,20 @@ static AnnotationTypeMappings forAnnotationType(Class<? extends Annotation> anno
213
189
* the meta-annotations
214
190
* @param annotationFilter the annotation filter used to limit which
215
191
* annotations are considered
216
- * @param visitedAnnotationTypes the set of annotations that we have already
217
- * visited; used to avoid infinite recursion for recursive annotations which
218
- * some JVM languages support (such as Kotlin)
219
192
* @return type mappings for the annotation type
220
193
*/
221
- private static AnnotationTypeMappings forAnnotationType (Class <? extends Annotation > annotationType ,
222
- RepeatableContainers repeatableContainers , AnnotationFilter annotationFilter ,
223
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
194
+ static AnnotationTypeMappings forAnnotationType (Class <? extends Annotation > annotationType ,
195
+ RepeatableContainers repeatableContainers , AnnotationFilter annotationFilter ) {
224
196
225
197
if (repeatableContainers == RepeatableContainers .standardRepeatables ()) {
226
198
return standardRepeatablesCache .computeIfAbsent (annotationFilter ,
227
- key -> new Cache (repeatableContainers , key )).get (annotationType , visitedAnnotationTypes );
199
+ key -> new Cache (repeatableContainers , key )).get (annotationType );
228
200
}
229
201
if (repeatableContainers == RepeatableContainers .none ()) {
230
202
return noRepeatablesCache .computeIfAbsent (annotationFilter ,
231
- key -> new Cache (repeatableContainers , key )).get (annotationType , visitedAnnotationTypes );
203
+ key -> new Cache (repeatableContainers , key )).get (annotationType );
232
204
}
233
- return new AnnotationTypeMappings (repeatableContainers , annotationFilter , annotationType , visitedAnnotationTypes );
205
+ return new AnnotationTypeMappings (repeatableContainers , annotationFilter , annotationType );
234
206
}
235
207
236
208
static void clearCache () {
@@ -263,21 +235,14 @@ private static class Cache {
263
235
/**
264
236
* Get or create {@link AnnotationTypeMappings} for the specified annotation type.
265
237
* @param annotationType the annotation type
266
- * @param visitedAnnotationTypes the set of annotations that we have already
267
- * visited; used to avoid infinite recursion for recursive annotations which
268
- * some JVM languages support (such as Kotlin)
269
238
* @return a new or existing {@link AnnotationTypeMappings} instance
270
239
*/
271
- AnnotationTypeMappings get (Class <? extends Annotation > annotationType ,
272
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
273
-
274
- return this .mappings .computeIfAbsent (annotationType , key -> createMappings (key , visitedAnnotationTypes ));
240
+ AnnotationTypeMappings get (Class <? extends Annotation > annotationType ) {
241
+ return this .mappings .computeIfAbsent (annotationType , this ::createMappings );
275
242
}
276
243
277
- private AnnotationTypeMappings createMappings (Class <? extends Annotation > annotationType ,
278
- Set <Class <? extends Annotation >> visitedAnnotationTypes ) {
279
-
280
- return new AnnotationTypeMappings (this .repeatableContainers , this .filter , annotationType , visitedAnnotationTypes );
244
+ AnnotationTypeMappings createMappings (Class <? extends Annotation > annotationType ) {
245
+ return new AnnotationTypeMappings (this .repeatableContainers , this .filter , annotationType );
281
246
}
282
247
}
283
248
0 commit comments