Use less confusing MergedAnnotation method names

Rename some `MergedAnnotation` methods to prevent using parent/child
terminology, specifically:

	`getDepth()` has been renamed `getDistance()`
	`getParent()` has been renamed `getMetaSource()`
	`getTypeHierarchy()` has been renamed `getMetaTypes()`

The parent child naming was particularly confusing given that the
parent/child relationships were inverted from the way that a lot of
users think about meta-annotations. For example, a `@RequestMapping`
having a parent of `@GetMapping` feels odd given that `@GetMapping`
is the thing declaring the meta-annotation relationship.

The new method names are designed to align more closely with existing
terms. For example, `getMetaSource` hints at the relationship with
`isMetaAnnotated` and `getSource`.

Closes gh-22946
This commit is contained in:
Phillip Webb
2019-05-26 13:15:59 -07:00
parent 4f4427f550
commit e386e53f92
18 changed files with 173 additions and 162 deletions

View File

@@ -220,11 +220,11 @@ public class AnnotationTypeMappingsTests {
}
@Test
public void getDepthReturnsDepth() {
public void getDistanceReturnsDistance() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
Mapped.class);
assertThat(mappings.get(0).getDepth()).isEqualTo(0);
assertThat(mappings.get(1).getDepth()).isEqualTo(1);
assertThat(mappings.get(0).getDistance()).isEqualTo(0);
assertThat(mappings.get(1).getDistance()).isEqualTo(1);
}
@Test
@@ -236,11 +236,11 @@ public class AnnotationTypeMappingsTests {
}
@Test
public void getAnnotationTypeHierarchyReturnsTypeHierarchy() {
public void getMetaTypeReturnsTypes() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
ThreeDeepA.class);
AnnotationTypeMapping mappingC = mappings.get(2);
assertThat(mappingC.getAnnotationTypeHierarchy()).containsExactly(
assertThat(mappingC.getMetaTypes()).containsExactly(
ThreeDeepA.class, ThreeDeepB.class, ThreeDeepC.class);
}

View File

@@ -163,7 +163,7 @@ public class MergedAnnotationsCollectionTests {
public void getWithPredicateReturnsOnlyMatching() {
MergedAnnotations annotations = getMutiRoute1();
assertThat(annotations.get(MutiRouteTarget.class,
annotation -> annotation.getDepth() >= 3).getString(
annotation -> annotation.getDistance() >= 3).getString(
MergedAnnotation.VALUE)).isEqualTo("111");
}
@@ -171,7 +171,7 @@ public class MergedAnnotationsCollectionTests {
public void getWithSelectorReturnsSelected() {
MergedAnnotations annotations = getMutiRoute1();
MergedAnnotationSelector<MutiRouteTarget> deepest = (existing,
candidate) -> candidate.getDepth() > existing.getDepth() ? candidate
candidate) -> candidate.getDistance() > existing.getDistance() ? candidate
: existing;
assertThat(annotations.get(MutiRouteTarget.class, null, deepest).getString(
MergedAnnotation.VALUE)).isEqualTo("111");

View File

@@ -153,7 +153,7 @@ public class MergedAnnotationsTests {
@Test
public void getParent() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
assertThat(annotations.get(TransactionalComponent.class).getParent().getType())
assertThat(annotations.get(TransactionalComponent.class).getMetaSource().getType())
.isEqualTo(ComposedTransactionalComponent.class);
}
@@ -161,7 +161,7 @@ public class MergedAnnotationsTests {
public void getRootWhenNotDirect() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
MergedAnnotation<?> annotation = annotations.get(TransactionalComponent.class);
assertThat(annotation.getDepth()).isGreaterThan(0);
assertThat(annotation.getDistance()).isGreaterThan(0);
assertThat(annotation.getRoot().getType()).isEqualTo(ComposedTransactionalComponent.class);
}
@@ -169,16 +169,16 @@ public class MergedAnnotationsTests {
public void getRootWhenDirect() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
MergedAnnotation<?> annotation = annotations.get(ComposedTransactionalComponent.class);
assertThat(annotation.getDepth()).isEqualTo(0);
assertThat(annotation.getDistance()).isEqualTo(0);
assertThat(annotation.getRoot()).isSameAs(annotation);
}
@Test
public void getTypeHierarchy() {
public void getMetaTypes() {
MergedAnnotation<?> annotation = MergedAnnotations.from(
ComposedTransactionalComponentClass.class).get(
TransactionalComponent.class);
assertThat(annotation.getTypeHierarchy()).containsExactly(
assertThat(annotation.getMetaTypes()).containsExactly(
ComposedTransactionalComponent.class, TransactionalComponent.class);
}
@@ -696,30 +696,30 @@ public class MergedAnnotationsTests {
public void getFromMethodWithMethodAnnotationOnLeaf() throws Exception {
Method method = Leaf.class.getMethod("annotatedOnLeaf");
assertThat(method.getAnnotation(Order.class)).isNotNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
0);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
public void getFromMethodWithAnnotationOnMethodInInterface() throws Exception {
Method method = Leaf.class.getMethod("fromInterfaceImplementedByRoot");
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
-1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
public void getFromMethodWithMetaAnnotationOnLeaf() throws Exception {
Method method = Leaf.class.getMethod("metaAnnotatedOnLeaf");
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(1);
Order.class).getDistance()).isEqualTo(1);
}
@Test
@@ -727,50 +727,50 @@ public class MergedAnnotationsTests {
Method method = Leaf.class.getMethod("metaMetaAnnotatedOnLeaf");
assertThat(method.getAnnotation(Component.class)).isNull();
assertThat(
MergedAnnotations.from(method).get(Component.class).getDepth()).isEqualTo(
MergedAnnotations.from(method).get(Component.class).getDistance()).isEqualTo(
2);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Component.class).getDepth()).isEqualTo(2);
Component.class).getDistance()).isEqualTo(2);
}
@Test
public void getWithAnnotationOnRoot() throws Exception {
Method method = Leaf.class.getMethod("annotatedOnRoot");
assertThat(method.getAnnotation(Order.class)).isNotNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
0);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
public void getFromMethodWithMetaAnnotationOnRoot() throws Exception {
Method method = Leaf.class.getMethod("metaAnnotatedOnRoot");
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(1);
Order.class).getDistance()).isEqualTo(1);
}
@Test
public void getFromMethodWithOnRootButOverridden() throws Exception {
Method method = Leaf.class.getMethod("overrideWithoutNewAnnotation");
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
-1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
public void getFromMethodWithNotAnnotated() throws Exception {
Method method = Leaf.class.getMethod("notAnnotated");
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
-1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(-1);
Order.class).getDistance()).isEqualTo(-1);
}
@Test
@@ -779,10 +779,10 @@ public class MergedAnnotationsTests {
Object.class);
assertThat(method.isBridge()).isTrue();
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
-1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
boolean runningInEclipse = Arrays.stream(
new Exception().getStackTrace()).anyMatch(
element -> element.getClassName().startsWith("org.eclipse.jdt"));
@@ -799,9 +799,9 @@ public class MergedAnnotationsTests {
assertThat(method.getAnnotation(Transactional.class)).isNotNull();
}
assertThat(MergedAnnotations.from(method).get(
Transactional.class).getDepth()).isEqualTo(0);
Transactional.class).getDistance()).isEqualTo(0);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Transactional.class).getDepth()).isEqualTo(0);
Transactional.class).getDistance()).isEqualTo(0);
}
@Test
@@ -810,22 +810,22 @@ public class MergedAnnotationsTests {
String.class);
assertThat(method.isBridge()).isFalse();
assertThat(method.getAnnotation(Order.class)).isNull();
assertThat(MergedAnnotations.from(method).get(Order.class).getDepth()).isEqualTo(
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(
-1);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
assertThat(method.getAnnotation(Transactional.class)).isNotNull();
assertThat(MergedAnnotations.from(method).get(
Transactional.class).getDepth()).isEqualTo(0);
Transactional.class).getDistance()).isEqualTo(0);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Transactional.class).getDepth()).isEqualTo(0);
Transactional.class).getDistance()).isEqualTo(0);
}
@Test
public void getFromMethodWithInterface() throws Exception {
Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test // SPR-16060
@@ -833,7 +833,7 @@ public class MergedAnnotationsTests {
Method method = ImplementsInterfaceWithGenericAnnotatedMethod.class.getMethod(
"foo", String.class);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test // SPR-17146
@@ -841,7 +841,7 @@ public class MergedAnnotationsTests {
Method method = ExtendsBaseClassWithGenericAnnotatedMethod.class.getMethod("foo",
String.class);
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
@@ -849,7 +849,7 @@ public class MergedAnnotationsTests {
Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod(
"foo");
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test
@@ -858,7 +858,7 @@ public class MergedAnnotationsTests {
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod(
"foo");
assertThat(MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE).get(
Order.class).getDepth()).isEqualTo(0);
Order.class).getDistance()).isEqualTo(0);
}
@Test

View File

@@ -46,8 +46,8 @@ public class MissingMergedAnnotationTests {
}
@Test
public void getTypeHierarchyReturnsEmptyList() {
assertThat(this.missing.getTypeHierarchy()).isEmpty();
public void MetaTypesReturnsEmptyList() {
assertThat(this.missing.getMetaTypes()).isEmpty();
}
@Test
@@ -66,8 +66,8 @@ public class MissingMergedAnnotationTests {
}
@Test
public void getDepthReturnsMinusOne() {
assertThat(this.missing.getDepth()).isEqualTo(-1);
public void getDistanceReturnsMinusOne() {
assertThat(this.missing.getDistance()).isEqualTo(-1);
}
@Test
@@ -81,8 +81,8 @@ public class MissingMergedAnnotationTests {
}
@Test
public void getParentReturnsNull() {
assertThat(this.missing.getParent()).isNull();
public void getMetaSourceReturnsNull() {
assertThat(this.missing.getMetaSource()).isNull();
}
@Test