diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 82617e121c..b1b5e4ef20 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -376,7 +376,7 @@ public abstract class AnnotationUtils { RepeatableContainers repeatableContainers = (containerAnnotationType != null ? RepeatableContainers.of(annotationType, containerAnnotationType) : RepeatableContainers.standardRepeatables()); - return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPER_CLASS, + return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPERCLASS, repeatableContainers, AnnotationFilter.PLAIN) .stream(annotationType) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) @@ -600,7 +600,7 @@ public abstract class AnnotationUtils { return null; } - return (Class) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS) + return (Class) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS) .get(annotationType, MergedAnnotation::isDirectlyPresent) .getSource(); } @@ -637,7 +637,7 @@ public abstract class AnnotationUtils { return null; } - return (Class) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS) + return (Class) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS) .stream() .filter(MergedAnnotationPredicates.typeIn(annotationTypes).and(MergedAnnotation::isDirectlyPresent)) .map(MergedAnnotation::getSource) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java index 4e859d268d..58be104d7f 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java @@ -121,7 +121,7 @@ abstract class AnnotationsScanner { return processElement(context, source, processor, classFilter); case INHERITED_ANNOTATIONS: return processClassInheritedAnnotations(context, source, processor, classFilter); - case SUPER_CLASS: + case SUPERCLASS: return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, false); case EXHAUSTIVE: return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, true); @@ -229,7 +229,7 @@ abstract class AnnotationsScanner { case DIRECT: case INHERITED_ANNOTATIONS: return processMethodInheritedAnnotations(context, source, processor, classFilter); - case SUPER_CLASS: + case SUPERCLASS: return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), processor, classFilter, source, false); case EXHAUSTIVE: 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 efbf75f95a..33bb4f4328 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 @@ -118,6 +118,7 @@ import org.springframework.lang.Nullable; * * * @author Phillip Webb + * @author Sam Brannen * @since 5.2 * @see MergedAnnotation * @see MergedAnnotationCollectors @@ -372,31 +373,31 @@ public interface MergedAnnotations extends Iterable /** * Find only directly declared annotations, without considering * {@link Inherited @Inherited} annotations and without searching - * super-classes or implemented interfaces. + * superclasses or implemented interfaces. */ DIRECT, /** - * Find all directly declared annotations as well any - * {@link Inherited @Inherited} super-class annotations. This strategy + * Find all directly declared annotations as well as any + * {@link Inherited @Inherited} superclass annotations. This strategy * is only really useful when used with {@link Class} types since the * {@link Inherited @Inherited} annotation is ignored for all other - * {@link AnnotatedElement annotated elements}. This strategy does not - * search implemented interfaces. + * {@linkplain AnnotatedElement annotated elements}. This strategy does + * not search implemented interfaces. */ INHERITED_ANNOTATIONS, /** - * Find all directly declared and super-class annotations. This strategy + * Find all directly declared and superclass annotations. This strategy * is similar to {@link #INHERITED_ANNOTATIONS} except the annotations * do not need to be meta-annotated with {@link Inherited @Inherited}. * This strategy does not search implemented interfaces. */ - SUPER_CLASS, + SUPERCLASS, /** - * Perform a full search of all related elements, include those on any - * super-classes or implemented interfaces. Superclass annotations do + * 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}. */ EXHAUSTIVE 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 834541538d..862c89eeec 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 @@ -139,41 +139,41 @@ public class AnnotationsScannerTests { @Test public void superclassStrategyOnClassWhenNotAnnoatedScansNone() { Class source = WithNoAnnotations.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty(); + assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty(); } @Test public void superclassStrategyOnClassScansAnnotations() { Class source = WithSingleAnnotation.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1"); } @Test public void superclassStrategyOnClassWhenMultipleAnnotationsScansAnnotations() { Class source = WithMultipleAnnotations.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "0:TestAnnotation2"); } @Test public void superclassStrategyOnClassWhenHasSuperclassScansSuperclass() { Class source = WithSingleSuperclass.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test public void superclassStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() { Class source = WithSingleInterface.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1"); } @Test public void superclassStrategyOnClassHierarchyScansInCorrectOrder() { Class source = WithHierarchy.class; - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2", "2:TestAnnotation3"); } @@ -306,41 +306,41 @@ public class AnnotationsScannerTests { @Test public void superclassStrategyOnMethodWhenNotAnnoatedScansNone() { Method source = methodFrom(WithNoAnnotations.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty(); + assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty(); } @Test public void superclassStrategyOnMethodScansAnnotations() { Method source = methodFrom(WithSingleAnnotation.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1"); } @Test public void superclassStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() { Method source = methodFrom(WithMultipleAnnotations.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "0:TestAnnotation2"); } @Test public void superclassStrategyOnMethodWhenHasSuperclassScansSuperclass() { Method source = methodFrom(WithSingleSuperclass.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); } @Test public void superclassStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() { Method source = methodFrom(WithSingleInterface.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1"); } @Test public void superclassStrategyOnMethodHierarchyScansInCorrectOrder() { Method source = methodFrom(WithHierarchy.class); - assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( + assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly( "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2", "2:TestAnnotation3"); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index d307ba125b..2539acacab 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -936,39 +936,39 @@ public class MergedAnnotationsTests { public void getSuperClassForAllScenarios() { // no class-level annotation assertThat(MergedAnnotations.from(NonAnnotatedInterface.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isNull(); assertThat(MergedAnnotations.from(NonAnnotatedClass.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isNull(); // inherited class-level annotation; note: @Transactional is inherited assertThat(MergedAnnotations.from(InheritedAnnotationInterface.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isEqualTo( InheritedAnnotationInterface.class); assertThat(MergedAnnotations.from(SubInheritedAnnotationInterface.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isNull(); assertThat(MergedAnnotations.from(InheritedAnnotationClass.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isEqualTo( InheritedAnnotationClass.class); assertThat(MergedAnnotations.from(SubInheritedAnnotationClass.class, - SearchStrategy.SUPER_CLASS).get( + SearchStrategy.SUPERCLASS).get( Transactional.class).getSource()).isEqualTo( InheritedAnnotationClass.class); // non-inherited class-level annotation; note: @Order is not inherited, // but we should still find it on classes. assertThat(MergedAnnotations.from(NonInheritedAnnotationInterface.class, - SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( + SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo( NonInheritedAnnotationInterface.class); assertThat(MergedAnnotations.from(SubNonInheritedAnnotationInterface.class, - SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isNull(); + SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isNull(); assertThat(MergedAnnotations.from(NonInheritedAnnotationClass.class, - SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( + SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo( NonInheritedAnnotationClass.class); assertThat(MergedAnnotations.from(SubNonInheritedAnnotationClass.class, - SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( + SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo( NonInheritedAnnotationClass.class); } @@ -1045,7 +1045,7 @@ public class MergedAnnotationsTests { private Object getSuperClassSourceWithTypeIn(Class clazz, List> annotationTypes) { - return MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS).stream().filter( + return MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS).stream().filter( MergedAnnotationPredicates.typeIn(annotationTypes).and( MergedAnnotation::isDirectlyPresent)).map( MergedAnnotation::getSource).findFirst().orElse(null); @@ -1279,7 +1279,7 @@ public class MergedAnnotationsTests { Class element = MyRepeatableClass.class; String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; - testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, + testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava, expectedValuesSpring); } @@ -1288,7 +1288,7 @@ public class MergedAnnotationsTests { Class element = SubMyRepeatableClass.class; String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; - testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, + testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava, expectedValuesSpring); } @@ -1297,7 +1297,7 @@ public class MergedAnnotationsTests { Class element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class; String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; - testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, + testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava, expectedValuesSpring); } @@ -1306,7 +1306,7 @@ public class MergedAnnotationsTests { Class element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class; String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; - testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, + testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava, expectedValuesSpring); }