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.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)

View File

@ -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:

View File

@ -118,6 +118,7 @@ import org.springframework.lang.Nullable;
* </pre>
*
* @author Phillip Webb
* @author Sam Brannen
* @since 5.2
* @see MergedAnnotation
* @see MergedAnnotationCollectors
@ -372,31 +373,31 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
/**
* 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

View File

@ -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");
}

View File

@ -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<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(
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);
}