Rename MergedAnnotations.SearchStrategy.SUPER_CLASS to SUPERCLASS

For consistency within the framework, this commit renames the SUPER_CLASS enum constant
to SUPERCLASS.

See gh-21697
This commit is contained in:
Sam Brannen 2019-04-03 14:21:34 +02:00
parent d39e3cc0ba
commit a4279c5d00
5 changed files with 42 additions and 41 deletions

View File

@ -376,7 +376,7 @@ public abstract class AnnotationUtils {
RepeatableContainers repeatableContainers = (containerAnnotationType != null ? RepeatableContainers repeatableContainers = (containerAnnotationType != null ?
RepeatableContainers.of(annotationType, containerAnnotationType) : RepeatableContainers.of(annotationType, containerAnnotationType) :
RepeatableContainers.standardRepeatables()); RepeatableContainers.standardRepeatables());
return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPER_CLASS, return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPERCLASS,
repeatableContainers, AnnotationFilter.PLAIN) repeatableContainers, AnnotationFilter.PLAIN)
.stream(annotationType) .stream(annotationType)
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
@ -600,7 +600,7 @@ public abstract class AnnotationUtils {
return null; return null;
} }
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS) return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS)
.get(annotationType, MergedAnnotation::isDirectlyPresent) .get(annotationType, MergedAnnotation::isDirectlyPresent)
.getSource(); .getSource();
} }
@ -637,7 +637,7 @@ public abstract class AnnotationUtils {
return null; return null;
} }
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS) return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS)
.stream() .stream()
.filter(MergedAnnotationPredicates.typeIn(annotationTypes).and(MergedAnnotation::isDirectlyPresent)) .filter(MergedAnnotationPredicates.typeIn(annotationTypes).and(MergedAnnotation::isDirectlyPresent))
.map(MergedAnnotation::getSource) .map(MergedAnnotation::getSource)

View File

@ -121,7 +121,7 @@ abstract class AnnotationsScanner {
return processElement(context, source, processor, classFilter); return processElement(context, source, processor, classFilter);
case INHERITED_ANNOTATIONS: case INHERITED_ANNOTATIONS:
return processClassInheritedAnnotations(context, source, processor, classFilter); return processClassInheritedAnnotations(context, source, processor, classFilter);
case SUPER_CLASS: case SUPERCLASS:
return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, false); return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, false);
case EXHAUSTIVE: case EXHAUSTIVE:
return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, true); return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, true);
@ -229,7 +229,7 @@ abstract class AnnotationsScanner {
case DIRECT: case DIRECT:
case INHERITED_ANNOTATIONS: case INHERITED_ANNOTATIONS:
return processMethodInheritedAnnotations(context, source, processor, classFilter); return processMethodInheritedAnnotations(context, source, processor, classFilter);
case SUPER_CLASS: case SUPERCLASS:
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
processor, classFilter, source, false); processor, classFilter, source, false);
case EXHAUSTIVE: case EXHAUSTIVE:

View File

@ -118,6 +118,7 @@ import org.springframework.lang.Nullable;
* </pre> * </pre>
* *
* @author Phillip Webb * @author Phillip Webb
* @author Sam Brannen
* @since 5.2 * @since 5.2
* @see MergedAnnotation * @see MergedAnnotation
* @see MergedAnnotationCollectors * @see MergedAnnotationCollectors
@ -372,31 +373,31 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
/** /**
* Find only directly declared annotations, without considering * Find only directly declared annotations, without considering
* {@link Inherited @Inherited} annotations and without searching * {@link Inherited @Inherited} annotations and without searching
* super-classes or implemented interfaces. * superclasses or implemented interfaces.
*/ */
DIRECT, DIRECT,
/** /**
* Find all directly declared annotations as well any * Find all directly declared annotations as well as any
* {@link Inherited @Inherited} super-class annotations. This strategy * {@link Inherited @Inherited} superclass annotations. This strategy
* is only really useful when used with {@link Class} types since the * is only really useful when used with {@link Class} types since the
* {@link Inherited @Inherited} annotation is ignored for all other * {@link Inherited @Inherited} annotation is ignored for all other
* {@link AnnotatedElement annotated elements}. This strategy does not * {@linkplain AnnotatedElement annotated elements}. This strategy does
* search implemented interfaces. * not search implemented interfaces.
*/ */
INHERITED_ANNOTATIONS, 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 * is similar to {@link #INHERITED_ANNOTATIONS} except the annotations
* do not need to be meta-annotated with {@link Inherited @Inherited}. * do not need to be meta-annotated with {@link Inherited @Inherited}.
* This strategy does not search implemented interfaces. * This strategy does not search implemented interfaces.
*/ */
SUPER_CLASS, SUPERCLASS,
/** /**
* Perform a full search of all related elements, include those on any * Perform a full search of all related elements, including those on any
* super-classes or implemented interfaces. Superclass annotations do * superclasses or implemented interfaces. Superclass annotations do
* not need to be meta-annotated with {@link Inherited @Inherited}. * not need to be meta-annotated with {@link Inherited @Inherited}.
*/ */
EXHAUSTIVE EXHAUSTIVE

View File

@ -139,41 +139,41 @@ public class AnnotationsScannerTests {
@Test @Test
public void superclassStrategyOnClassWhenNotAnnoatedScansNone() { public void superclassStrategyOnClassWhenNotAnnoatedScansNone() {
Class<?> source = WithNoAnnotations.class; Class<?> source = WithNoAnnotations.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty(); assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty();
} }
@Test @Test
public void superclassStrategyOnClassScansAnnotations() { public void superclassStrategyOnClassScansAnnotations() {
Class<?> source = WithSingleAnnotation.class; Class<?> source = WithSingleAnnotation.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1"); "0:TestAnnotation1");
} }
@Test @Test
public void superclassStrategyOnClassWhenMultipleAnnotationsScansAnnotations() { public void superclassStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
Class<?> source = WithMultipleAnnotations.class; Class<?> source = WithMultipleAnnotations.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "0:TestAnnotation2"); "0:TestAnnotation1", "0:TestAnnotation2");
} }
@Test @Test
public void superclassStrategyOnClassWhenHasSuperclassScansSuperclass() { public void superclassStrategyOnClassWhenHasSuperclassScansSuperclass() {
Class<?> source = WithSingleSuperclass.class; Class<?> source = WithSingleSuperclass.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
} }
@Test @Test
public void superclassStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() { public void superclassStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
Class<?> source = WithSingleInterface.class; Class<?> source = WithSingleInterface.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1"); "0:TestAnnotation1");
} }
@Test @Test
public void superclassStrategyOnClassHierarchyScansInCorrectOrder() { public void superclassStrategyOnClassHierarchyScansInCorrectOrder() {
Class<?> source = WithHierarchy.class; Class<?> source = WithHierarchy.class;
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2", "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2",
"2:TestAnnotation3"); "2:TestAnnotation3");
} }
@ -306,41 +306,41 @@ public class AnnotationsScannerTests {
@Test @Test
public void superclassStrategyOnMethodWhenNotAnnoatedScansNone() { public void superclassStrategyOnMethodWhenNotAnnoatedScansNone() {
Method source = methodFrom(WithNoAnnotations.class); Method source = methodFrom(WithNoAnnotations.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty(); assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty();
} }
@Test @Test
public void superclassStrategyOnMethodScansAnnotations() { public void superclassStrategyOnMethodScansAnnotations() {
Method source = methodFrom(WithSingleAnnotation.class); Method source = methodFrom(WithSingleAnnotation.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1"); "0:TestAnnotation1");
} }
@Test @Test
public void superclassStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() { public void superclassStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() {
Method source = methodFrom(WithMultipleAnnotations.class); Method source = methodFrom(WithMultipleAnnotations.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "0:TestAnnotation2"); "0:TestAnnotation1", "0:TestAnnotation2");
} }
@Test @Test
public void superclassStrategyOnMethodWhenHasSuperclassScansSuperclass() { public void superclassStrategyOnMethodWhenHasSuperclassScansSuperclass() {
Method source = methodFrom(WithSingleSuperclass.class); Method source = methodFrom(WithSingleSuperclass.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2"); "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
} }
@Test @Test
public void superclassStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() { public void superclassStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
Method source = methodFrom(WithSingleInterface.class); Method source = methodFrom(WithSingleInterface.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1"); "0:TestAnnotation1");
} }
@Test @Test
public void superclassStrategyOnMethodHierarchyScansInCorrectOrder() { public void superclassStrategyOnMethodHierarchyScansInCorrectOrder() {
Method source = methodFrom(WithHierarchy.class); Method source = methodFrom(WithHierarchy.class);
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly( assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2", "0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2",
"2:TestAnnotation3"); "2:TestAnnotation3");
} }

View File

@ -936,39 +936,39 @@ public class MergedAnnotationsTests {
public void getSuperClassForAllScenarios() { public void getSuperClassForAllScenarios() {
// no class-level annotation // no class-level annotation
assertThat(MergedAnnotations.from(NonAnnotatedInterface.class, assertThat(MergedAnnotations.from(NonAnnotatedInterface.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isNull(); Transactional.class).getSource()).isNull();
assertThat(MergedAnnotations.from(NonAnnotatedClass.class, assertThat(MergedAnnotations.from(NonAnnotatedClass.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isNull(); Transactional.class).getSource()).isNull();
// inherited class-level annotation; note: @Transactional is inherited // inherited class-level annotation; note: @Transactional is inherited
assertThat(MergedAnnotations.from(InheritedAnnotationInterface.class, assertThat(MergedAnnotations.from(InheritedAnnotationInterface.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isEqualTo( Transactional.class).getSource()).isEqualTo(
InheritedAnnotationInterface.class); InheritedAnnotationInterface.class);
assertThat(MergedAnnotations.from(SubInheritedAnnotationInterface.class, assertThat(MergedAnnotations.from(SubInheritedAnnotationInterface.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isNull(); Transactional.class).getSource()).isNull();
assertThat(MergedAnnotations.from(InheritedAnnotationClass.class, assertThat(MergedAnnotations.from(InheritedAnnotationClass.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isEqualTo( Transactional.class).getSource()).isEqualTo(
InheritedAnnotationClass.class); InheritedAnnotationClass.class);
assertThat(MergedAnnotations.from(SubInheritedAnnotationClass.class, assertThat(MergedAnnotations.from(SubInheritedAnnotationClass.class,
SearchStrategy.SUPER_CLASS).get( SearchStrategy.SUPERCLASS).get(
Transactional.class).getSource()).isEqualTo( Transactional.class).getSource()).isEqualTo(
InheritedAnnotationClass.class); InheritedAnnotationClass.class);
// non-inherited class-level annotation; note: @Order is not inherited, // non-inherited class-level annotation; note: @Order is not inherited,
// but we should still find it on classes. // but we should still find it on classes.
assertThat(MergedAnnotations.from(NonInheritedAnnotationInterface.class, assertThat(MergedAnnotations.from(NonInheritedAnnotationInterface.class,
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
NonInheritedAnnotationInterface.class); NonInheritedAnnotationInterface.class);
assertThat(MergedAnnotations.from(SubNonInheritedAnnotationInterface.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, assertThat(MergedAnnotations.from(NonInheritedAnnotationClass.class,
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
NonInheritedAnnotationClass.class); NonInheritedAnnotationClass.class);
assertThat(MergedAnnotations.from(SubNonInheritedAnnotationClass.class, assertThat(MergedAnnotations.from(SubNonInheritedAnnotationClass.class,
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo( SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
NonInheritedAnnotationClass.class); NonInheritedAnnotationClass.class);
} }
@ -1045,7 +1045,7 @@ public class MergedAnnotationsTests {
private Object getSuperClassSourceWithTypeIn(Class<?> clazz, private Object getSuperClassSourceWithTypeIn(Class<?> clazz,
List<Class<? extends Annotation>> annotationTypes) { List<Class<? extends Annotation>> annotationTypes) {
return MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS).stream().filter( return MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS).stream().filter(
MergedAnnotationPredicates.typeIn(annotationTypes).and( MergedAnnotationPredicates.typeIn(annotationTypes).and(
MergedAnnotation::isDirectlyPresent)).map( MergedAnnotation::isDirectlyPresent)).map(
MergedAnnotation::getSource).findFirst().orElse(null); MergedAnnotation::getSource).findFirst().orElse(null);
@ -1279,7 +1279,7 @@ public class MergedAnnotationsTests {
Class<?> element = MyRepeatableClass.class; Class<?> element = MyRepeatableClass.class;
String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesJava = { "A", "B", "C" };
String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
expectedValuesSpring); expectedValuesSpring);
} }
@ -1288,7 +1288,7 @@ public class MergedAnnotationsTests {
Class<?> element = SubMyRepeatableClass.class; Class<?> element = SubMyRepeatableClass.class;
String[] expectedValuesJava = { "A", "B", "C" }; String[] expectedValuesJava = { "A", "B", "C" };
String[] expectedValuesSpring = { "A", "B", "C", "meta1" }; String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
expectedValuesSpring); expectedValuesSpring);
} }
@ -1297,7 +1297,7 @@ public class MergedAnnotationsTests {
Class<?> element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class; Class<?> element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesJava = { "X", "Y", "Z" };
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
expectedValuesSpring); expectedValuesSpring);
} }
@ -1306,7 +1306,7 @@ public class MergedAnnotationsTests {
Class<?> element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class; Class<?> element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
String[] expectedValuesJava = { "X", "Y", "Z" }; String[] expectedValuesJava = { "X", "Y", "Z" };
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" }; String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava, testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
expectedValuesSpring); expectedValuesSpring);
} }