> classFilter) {
@@ -233,6 +236,7 @@ abstract class AnnotationsScanner {
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
processor, classFilter, source, false);
case EXHAUSTIVE:
+ case TYPE_HIERARCHY:
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
processor, classFilter, source, true);
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
index 4a2d41268b..e2a96cb7c9 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java
@@ -91,7 +91,7 @@ import org.springframework.lang.Nullable;
*
* Different {@linkplain SearchStrategy search strategies} can be used to locate
* related source elements that contain the annotations to be aggregated. For
- * example, {@link SearchStrategy#EXHAUSTIVE} will search both superclasses and
+ * example, {@link SearchStrategy#TYPE_HIERARCHY} will search both superclasses and
* implemented interfaces.
*
*
From a {@link MergedAnnotations} instance you can either
@@ -428,8 +428,18 @@ public interface MergedAnnotations extends Iterable
* Perform a full search of all related elements, including those on any
* superclasses or implemented interfaces. Superclass annotations do
* not need to be meta-annotated with {@link Inherited @Inherited}.
+ * @deprecated since 5.2.0.RC1 in favor of {@link #TYPE_HIERARCHY}.
*/
- EXHAUSTIVE
+ @Deprecated
+ EXHAUSTIVE,
+
+ /**
+ * Perform a full search of the entire type hierarchy , including
+ * superclasses and implemented interfaces. Superclass annotations do
+ * not need to be meta-annotated with {@link Inherited @Inherited}.
+ */
+ TYPE_HIERARCHY
+
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
index 2e8c216b96..494f4c886e 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/OrderUtils.java
@@ -81,7 +81,7 @@ public abstract class OrderUtils {
*/
@Nullable
public static Integer getOrder(Class> type) {
- return getOrderFromAnnotations(type, MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE));
+ return getOrderFromAnnotations(type, MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY));
}
/**
@@ -127,7 +127,7 @@ public abstract class OrderUtils {
*/
@Nullable
public static Integer getPriority(Class> type) {
- return MergedAnnotations.from(type, SearchStrategy.EXHAUSTIVE).get(JAVAX_PRIORITY_ANNOTATION)
+ return MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(JAVAX_PRIORITY_ANNOTATION)
.getValue(MergedAnnotation.VALUE, Integer.class).orElse(null);
}
diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java
index 2e86c69546..e57341e4a0 100644
--- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java
+++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java
@@ -179,43 +179,43 @@ public class AnnotationsScannerTests {
}
@Test
- public void exhaustiveStrategyOnClassWhenNotAnnoatedScansNone() {
+ public void typeHierarchyStrategyOnClassWhenNotAnnoatedScansNone() {
Class> source = WithNoAnnotations.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).isEmpty();
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).isEmpty();
}
@Test
- public void exhaustiveStrategyOnClassScansAnnotations() {
+ public void typeHierarchyStrategyOnClassScansAnnotations() {
Class> source = WithSingleAnnotation.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1");
}
@Test
- public void exhaustiveStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
+ public void typeHierarchyStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
Class> source = WithMultipleAnnotations.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "0:TestAnnotation2");
}
@Test
- public void exhaustiveStrategyOnClassWhenHasSuperclassScansSuperclass() {
+ public void typeHierarchyStrategyOnClassWhenHasSuperclassScansSuperclass() {
Class> source = WithSingleSuperclass.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
}
@Test
- public void exhaustiveStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
+ public void typeHierarchyStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
Class> source = WithSingleInterface.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
}
@Test
- public void exhaustiveStrategyOnClassHierarchyScansInCorrectOrder() {
+ public void typeHierarchyStrategyOnClassHierarchyScansInCorrectOrder() {
Class> source = WithHierarchy.class;
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation5", "1:TestInheritedAnnotation5",
"2:TestAnnotation6", "3:TestAnnotation2", "3:TestInheritedAnnotation2",
"4:TestAnnotation3", "5:TestAnnotation4");
@@ -346,61 +346,61 @@ public class AnnotationsScannerTests {
}
@Test
- public void exhaustiveStrategyOnMethodWhenNotAnnoatedScansNone() {
+ public void typeHierarchyStrategyOnMethodWhenNotAnnoatedScansNone() {
Method source = methodFrom(WithNoAnnotations.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).isEmpty();
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).isEmpty();
}
@Test
- public void exhaustiveStrategyOnMethodScansAnnotations() {
+ public void typeHierarchyStrategyOnMethodScansAnnotations() {
Method source = methodFrom(WithSingleAnnotation.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1");
}
@Test
- public void exhaustiveStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() {
+ public void typeHierarchyStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() {
Method source = methodFrom(WithMultipleAnnotations.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "0:TestAnnotation2");
}
@Test
- public void exhaustiveStrategyOnMethodWhenHasSuperclassScansSuperclass() {
+ public void typeHierarchyStrategyOnMethodWhenHasSuperclassScansSuperclass() {
Method source = methodFrom(WithSingleSuperclass.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
}
@Test
- public void exhaustiveStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
+ public void typeHierarchyStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
Method source = methodFrom(WithSingleInterface.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
}
@Test
- public void exhaustiveStrategyOnMethodHierarchyScansInCorrectOrder() {
+ public void typeHierarchyStrategyOnMethodHierarchyScansInCorrectOrder() {
Method source = methodFrom(WithHierarchy.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation5", "1:TestInheritedAnnotation5",
"2:TestAnnotation6", "3:TestAnnotation2", "3:TestInheritedAnnotation2",
"4:TestAnnotation3", "5:TestAnnotation4");
}
@Test
- public void exhaustiveStrategyOnBridgeMethodScansAnnotations() throws Exception {
+ public void typeHierarchyStrategyOnBridgeMethodScansAnnotations() throws Exception {
Method source = BridgedMethod.class.getDeclaredMethod("method", Object.class);
assertThat(source.isBridge()).isTrue();
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2");
}
@Test
- public void exhaustiveStrategyOnBridgedMethodScansAnnotations() throws Exception {
+ public void typeHierarchyStrategyOnBridgedMethodScansAnnotations() throws Exception {
Method source = BridgedMethod.class.getDeclaredMethod("method", String.class);
assertThat(source.isBridge()).isFalse();
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2");
}
@@ -421,43 +421,43 @@ public class AnnotationsScannerTests {
}
@Test
- public void exhaustiveStrategyOnMethodWithIgnorablesScansAnnotations()
+ public void typeHierarchyStrategyOnMethodWithIgnorablesScansAnnotations()
throws Exception {
Method source = methodFrom(Ignoreable.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1");
}
@Test
- public void exhaustiveStrategyOnMethodWithMultipleCandidatesScansAnnotations()
+ public void typeHierarchyStrategyOnMethodWithMultipleCandidatesScansAnnotations()
throws Exception {
Method source = methodFrom(MultipleMethods.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1");
}
@Test
- public void exhaustiveStrategyOnMethodWithGenericParameterOverrideScansAnnotations()
+ public void typeHierarchyStrategyOnMethodWithGenericParameterOverrideScansAnnotations()
throws Exception {
Method source = ReflectionUtils.findMethod(GenericOverride.class, "method",
String.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2");
}
@Test
- public void exhaustiveStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations()
+ public void typeHierarchyStrategyOnMethodWithGenericParameterNonOverrideScansAnnotations()
throws Exception {
Method source = ReflectionUtils.findMethod(GenericNonOverride.class, "method",
StringBuilder.class);
- assertThat(scan(source, SearchStrategy.EXHAUSTIVE)).containsExactly(
+ assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY)).containsExactly(
"0:TestAnnotation1");
}
@Test
public void scanWhenProcessorReturnsFromDoWithAggregateExitsEarly() {
String result = AnnotationsScanner.scan(this, WithSingleSuperclass.class,
- SearchStrategy.EXHAUSTIVE, new AnnotationsProcessor