Skip to content

Commit

Permalink
Use RepeatableContainers.none() in AnnotationUtils
Browse files Browse the repository at this point in the history
Update `AnnotationUtils` so that `RepeatableContainers.none()` is used
when performing an exhaustive search for merged annotations. These
parameters were accidentally removed in commit 210b178 and weren't
caught earlier because we were missing a test.

Closes gh-22702
  • Loading branch information
philwebb committed Mar 28, 2019
1 parent 800cbf2 commit f273fa9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public static <A extends Annotation> A getAnnotation(Annotation annotation, Clas
return null;
}
// Exhaustive retrieval of merged annotations...
return MergedAnnotations.from(annotation)
return MergedAnnotations.from(null, new Annotation[] {annotation},
RepeatableContainers.none(), AnnotationFilter.PLAIN)
.get(annotationType).withNonMergedAttributes()
.synthesize(AnnotationUtils::isSingleLevelPresent).orElse(null);
}
Expand Down Expand Up @@ -492,7 +493,8 @@ public static <A extends Annotation> A findAnnotation(
return annotatedElement.getDeclaredAnnotation(annotationType);
}
// Exhaustive retrieval of merged annotations...
return MergedAnnotations.from(annotatedElement, SearchStrategy.INHERITED_ANNOTATIONS)
return MergedAnnotations.from(annotatedElement, SearchStrategy.INHERITED_ANNOTATIONS,
RepeatableContainers.none(), AnnotationFilter.PLAIN)
.get(annotationType).withNonMergedAttributes()
.synthesize(MergedAnnotation::isPresent).orElse(null);
}
Expand Down Expand Up @@ -523,7 +525,8 @@ public static <A extends Annotation> A findAnnotation(Method method, @Nullable C
return method.getDeclaredAnnotation(annotationType);
}
// Exhaustive retrieval of merged annotations...
return MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE)
return MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE,
RepeatableContainers.none(), AnnotationFilter.PLAIN)
.get(annotationType).withNonMergedAttributes()
.synthesize(MergedAnnotation::isPresent).orElse(null);
}
Expand Down Expand Up @@ -561,7 +564,8 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable
return clazz.getDeclaredAnnotation(annotationType);
}
// Exhaustive retrieval of merged annotations...
return MergedAnnotations.from(clazz, SearchStrategy.EXHAUSTIVE)
return MergedAnnotations.from(clazz, SearchStrategy.EXHAUSTIVE,
RepeatableContainers.none(), AnnotationFilter.PLAIN)
.get(annotationType).withNonMergedAttributes()
.synthesize(MergedAnnotation::isPresent).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,13 @@ public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases(
assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}

@Test // gh-22702
public void findAnnotationWithRepeatablesElements() {
assertNull(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
TestRepeatable.class));
assertNotNull(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
TestRepeatableContainer.class));
}

@SafeVarargs
static <T> T[] asArray(T... arr) {
Expand Down Expand Up @@ -1808,4 +1815,21 @@ static class ComponentScanSingleFilterClass {
interface ContextConfigMismatch {
}

@Retention(RetentionPolicy.RUNTIME)
@Repeatable(TestRepeatableContainer.class)
static @interface TestRepeatable {

String value();
}

@Retention(RetentionPolicy.RUNTIME)
static @interface TestRepeatableContainer {

TestRepeatable[] value();
}

@TestRepeatable("a")
@TestRepeatable("b")
static class TestRepeatablesClass {
}
}

0 comments on commit f273fa9

Please sign in to comment.