Add MergedAnnotation.getTypeHierarchy method
Add a `getTypeHierarchy()` method to `MergedAnnotation` that can be used to return the full type hierarchy information. This method is specifically designed to be used in combination with `MergedAnnotationPredicates.unique`. This update also allows us to delete the `parentAndType` method from `AnnotatedElementUtils`. Closes gh-22908
This commit is contained in:
committed by
Juergen Hoeller
parent
f86affe404
commit
3b145a5a73
@@ -245,6 +245,15 @@ public class AnnotationTypeMappingsTests {
|
||||
assertThat(mappings.get(1).getAnnotationType()).isEqualTo(MappedTarget.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAnnotationTypeHierarchyReturnsTypeHierarchy() {
|
||||
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
|
||||
ThreeDeepA.class);
|
||||
AnnotationTypeMapping mappingC = mappings.get(2);
|
||||
assertThat(mappingC.getAnnotationTypeHierarchy()).containsExactly(
|
||||
ThreeDeepA.class, ThreeDeepB.class, ThreeDeepC.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAnnotationWhenRootReturnsNull() {
|
||||
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
|
||||
|
||||
@@ -170,6 +170,15 @@ public class MergedAnnotationsTests {
|
||||
assertThat(annotation.getRoot()).isSameAs(annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeHierarchy() {
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
ComposedTransactionalComponentClass.class).get(
|
||||
TransactionalComponent.class);
|
||||
assertThat(annotation.getTypeHierarchy()).containsExactly(
|
||||
ComposedTransactionalComponent.class, TransactionalComponent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMultiValueMapFromNonAnnotatedClass() {
|
||||
MultiValueMap<String, Object> map = MergedAnnotations.from(
|
||||
|
||||
@@ -44,6 +44,11 @@ public class MissingMergedAnnotationTests {
|
||||
assertThatNoSuchElementException().isThrownBy(this.missing::getType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeHierarchyReturnsEmptyList() {
|
||||
assertThat(this.missing.getTypeHierarchy()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPresentReturnsFalse() {
|
||||
assertThat(this.missing.isPresent()).isFalse();
|
||||
|
||||
Reference in New Issue
Block a user