Skip to content

Commit b841e85

Browse files
committed
Polish MergedAnnotation API internals
1 parent 2b3fdfa commit b841e85

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Provides {@link AnnotationTypeMapping} information for a single source
3131
* annotation type. Performs a recursive breadth first crawl of all
3232
* meta-annotations to ultimately provide a quick way to map the attributes of
33-
* root {@link Annotation}.
33+
* a root {@link Annotation}.
3434
*
3535
* <p>Supports convention based merging of meta-annotations as well as implicit
3636
* and explicit {@link AliasFor @AliasFor} aliases. Also provides information
@@ -81,14 +81,12 @@ private void addAllMappings(Class<? extends Annotation> annotationType) {
8181
}
8282

8383
private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, AnnotationTypeMapping source) {
84-
Annotation[] metaAnnotations =
85-
AnnotationsScanner.getDeclaredAnnotations(source.getAnnotationType(), false);
84+
Annotation[] metaAnnotations = AnnotationsScanner.getDeclaredAnnotations(source.getAnnotationType(), false);
8685
for (Annotation metaAnnotation : metaAnnotations) {
8786
if (!isMappable(source, metaAnnotation)) {
8887
continue;
8988
}
90-
Annotation[] repeatedAnnotations = this.repeatableContainers
91-
.findRepeatedAnnotations(metaAnnotation);
89+
Annotation[] repeatedAnnotations = this.repeatableContainers.findRepeatedAnnotations(metaAnnotation);
9290
if (repeatedAnnotations != null) {
9391
for (Annotation repeatedAnnotation : repeatedAnnotations) {
9492
if (!isMappable(source, metaAnnotation)) {
@@ -103,9 +101,7 @@ private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, Annot
103101
}
104102
}
105103

106-
private void addIfPossible(Deque<AnnotationTypeMapping> queue,
107-
AnnotationTypeMapping source, Annotation ann) {
108-
104+
private void addIfPossible(Deque<AnnotationTypeMapping> queue, AnnotationTypeMapping source, Annotation ann) {
109105
addIfPossible(queue, source, ann.annotationType(), ann);
110106
}
111107

@@ -183,21 +179,20 @@ static AnnotationTypeMappings forAnnotationType(Class<? extends Annotation> anno
183179
static AnnotationTypeMappings forAnnotationType(
184180
Class<? extends Annotation> annotationType, AnnotationFilter annotationFilter) {
185181

186-
return forAnnotationType(annotationType,
187-
RepeatableContainers.standardRepeatables(), annotationFilter);
182+
return forAnnotationType(annotationType, RepeatableContainers.standardRepeatables(), annotationFilter);
188183
}
189184

190185
/**
191186
* Create {@link AnnotationTypeMappings} for the specified annotation type.
192187
* @param annotationType the source annotation type
188+
* @param repeatableContainers the repeatable containers that may be used by
189+
* the meta-annotations
193190
* @param annotationFilter the annotation filter used to limit which
194191
* annotations are considered
195192
* @return type mappings for the annotation type
196193
*/
197-
static AnnotationTypeMappings forAnnotationType(
198-
Class<? extends Annotation> annotationType,
199-
RepeatableContainers repeatableContainers,
200-
AnnotationFilter annotationFilter) {
194+
static AnnotationTypeMappings forAnnotationType(Class<? extends Annotation> annotationType,
195+
RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
201196

202197
if (repeatableContainers == RepeatableContainers.standardRepeatables()) {
203198
return standardRepeatablesCache.computeIfAbsent(annotationFilter,
@@ -207,8 +202,7 @@ static AnnotationTypeMappings forAnnotationType(
207202
return noRepeatablesCache.computeIfAbsent(annotationFilter,
208203
key -> new Cache(repeatableContainers, key)).get(annotationType);
209204
}
210-
return new AnnotationTypeMappings(repeatableContainers, annotationFilter,
211-
annotationType);
205+
return new AnnotationTypeMappings(repeatableContainers, annotationFilter, annotationType);
212206
}
213207

214208
static void clearCache() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
326326
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
327327
RepeatableContainers repeatableContainers) {
328328

329-
return TypeMappedAnnotations.from(element, searchStrategy, repeatableContainers, AnnotationFilter.PLAIN);
329+
return from(element, searchStrategy, repeatableContainers, AnnotationFilter.PLAIN);
330330
}
331331

332332
/**
@@ -340,7 +340,7 @@ static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStr
340340
* @param annotationFilter an annotation filter used to restrict the
341341
* annotations considered
342342
* @return a {@link MergedAnnotations} instance containing the merged
343-
* element annotations
343+
* annotations for the supplied element
344344
*/
345345
static MergedAnnotations from(AnnotatedElement element, SearchStrategy searchStrategy,
346346
RepeatableContainers repeatableContainers, AnnotationFilter annotationFilter) {
@@ -386,7 +386,7 @@ static MergedAnnotations from(Object source, Annotation... annotations) {
386386
* @return a {@link MergedAnnotations} instance containing the annotations
387387
*/
388388
static MergedAnnotations from(Object source, Annotation[] annotations, RepeatableContainers repeatableContainers) {
389-
return TypeMappedAnnotations.from(source, annotations, repeatableContainers, AnnotationFilter.PLAIN);
389+
return from(source, annotations, repeatableContainers, AnnotationFilter.PLAIN);
390390
}
391391

392392
/**

spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collections;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.stream.IntStream;
3132

3233
import javax.annotation.Nullable;
3334

@@ -38,6 +39,7 @@
3839
import org.springframework.lang.UsesSunMisc;
3940
import org.springframework.util.ReflectionUtils;
4041

42+
import static java.util.stream.Collectors.toList;
4143
import static org.assertj.core.api.Assertions.assertThat;
4244
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4345

@@ -500,11 +502,7 @@ private AnnotationTypeMapping getMapping(AnnotationTypeMappings mappings,
500502
private List<AnnotationTypeMapping> getAll(AnnotationTypeMappings mappings) {
501503
// AnnotationTypeMappings does not implement Iterable so we don't create
502504
// too many garbage Iterators
503-
List<AnnotationTypeMapping> result = new ArrayList<>(mappings.size());
504-
for (int i = 0; i < mappings.size(); i++) {
505-
result.add(mappings.get(i));
506-
}
507-
return result;
505+
return IntStream.range(0, mappings.size()).mapToObj(mappings::get).collect(toList());
508506
}
509507

510508
private List<String> getNames(MirrorSet mirrorSet) {

0 commit comments

Comments
 (0)