Skip to content

Commit a4279c5

Browse files
committed
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
1 parent d39e3cc commit a4279c5

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedEl
376376
RepeatableContainers repeatableContainers = (containerAnnotationType != null ?
377377
RepeatableContainers.of(annotationType, containerAnnotationType) :
378378
RepeatableContainers.standardRepeatables());
379-
return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPER_CLASS,
379+
return MergedAnnotations.from(annotatedElement, SearchStrategy.SUPERCLASS,
380380
repeatableContainers, AnnotationFilter.PLAIN)
381381
.stream(annotationType)
382382
.filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex))
@@ -600,7 +600,7 @@ public static Class<?> findAnnotationDeclaringClass(
600600
return null;
601601
}
602602

603-
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS)
603+
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS)
604604
.get(annotationType, MergedAnnotation::isDirectlyPresent)
605605
.getSource();
606606
}
@@ -637,7 +637,7 @@ public static Class<?> findAnnotationDeclaringClassForTypes(
637637
return null;
638638
}
639639

640-
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS)
640+
return (Class<?>) MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS)
641641
.stream()
642642
.filter(MergedAnnotationPredicates.typeIn(annotationTypes).and(MergedAnnotation::isDirectlyPresent))
643643
.map(MergedAnnotation::getSource)

spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private static <C, R> R processClass(C context, Class<?> source,
121121
return processElement(context, source, processor, classFilter);
122122
case INHERITED_ANNOTATIONS:
123123
return processClassInheritedAnnotations(context, source, processor, classFilter);
124-
case SUPER_CLASS:
124+
case SUPERCLASS:
125125
return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, false);
126126
case EXHAUSTIVE:
127127
return processClassHierarchy(context, new int[] {0}, source, processor, classFilter, true);
@@ -229,7 +229,7 @@ private static <C, R> R processMethod(C context, Method source,
229229
case DIRECT:
230230
case INHERITED_ANNOTATIONS:
231231
return processMethodInheritedAnnotations(context, source, processor, classFilter);
232-
case SUPER_CLASS:
232+
case SUPERCLASS:
233233
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
234234
processor, classFilter, source, false);
235235
case EXHAUSTIVE:

spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
* </pre>
119119
*
120120
* @author Phillip Webb
121+
* @author Sam Brannen
121122
* @since 5.2
122123
* @see MergedAnnotation
123124
* @see MergedAnnotationCollectors
@@ -372,31 +373,31 @@ enum SearchStrategy {
372373
/**
373374
* Find only directly declared annotations, without considering
374375
* {@link Inherited @Inherited} annotations and without searching
375-
* super-classes or implemented interfaces.
376+
* superclasses or implemented interfaces.
376377
*/
377378
DIRECT,
378379

379380
/**
380-
* Find all directly declared annotations as well any
381-
* {@link Inherited @Inherited} super-class annotations. This strategy
381+
* Find all directly declared annotations as well as any
382+
* {@link Inherited @Inherited} superclass annotations. This strategy
382383
* is only really useful when used with {@link Class} types since the
383384
* {@link Inherited @Inherited} annotation is ignored for all other
384-
* {@link AnnotatedElement annotated elements}. This strategy does not
385-
* search implemented interfaces.
385+
* {@linkplain AnnotatedElement annotated elements}. This strategy does
386+
* not search implemented interfaces.
386387
*/
387388
INHERITED_ANNOTATIONS,
388389

389390
/**
390-
* Find all directly declared and super-class annotations. This strategy
391+
* Find all directly declared and superclass annotations. This strategy
391392
* is similar to {@link #INHERITED_ANNOTATIONS} except the annotations
392393
* do not need to be meta-annotated with {@link Inherited @Inherited}.
393394
* This strategy does not search implemented interfaces.
394395
*/
395-
SUPER_CLASS,
396+
SUPERCLASS,
396397

397398
/**
398-
* Perform a full search of all related elements, include those on any
399-
* super-classes or implemented interfaces. Superclass annotations do
399+
* Perform a full search of all related elements, including those on any
400+
* superclasses or implemented interfaces. Superclass annotations do
400401
* not need to be meta-annotated with {@link Inherited @Inherited}.
401402
*/
402403
EXHAUSTIVE

spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,41 +139,41 @@ public void inheritedAnnotationsStrategyOnClassWhenHasAnnotationOnBothClassesInc
139139
@Test
140140
public void superclassStrategyOnClassWhenNotAnnoatedScansNone() {
141141
Class<?> source = WithNoAnnotations.class;
142-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty();
142+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty();
143143
}
144144

145145
@Test
146146
public void superclassStrategyOnClassScansAnnotations() {
147147
Class<?> source = WithSingleAnnotation.class;
148-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
148+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
149149
"0:TestAnnotation1");
150150
}
151151

152152
@Test
153153
public void superclassStrategyOnClassWhenMultipleAnnotationsScansAnnotations() {
154154
Class<?> source = WithMultipleAnnotations.class;
155-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
155+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
156156
"0:TestAnnotation1", "0:TestAnnotation2");
157157
}
158158

159159
@Test
160160
public void superclassStrategyOnClassWhenHasSuperclassScansSuperclass() {
161161
Class<?> source = WithSingleSuperclass.class;
162-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
162+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
163163
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
164164
}
165165

166166
@Test
167167
public void superclassStrategyOnClassWhenHasInterfaceDoesNotIncludeInterfaces() {
168168
Class<?> source = WithSingleInterface.class;
169-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
169+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
170170
"0:TestAnnotation1");
171171
}
172172

173173
@Test
174174
public void superclassStrategyOnClassHierarchyScansInCorrectOrder() {
175175
Class<?> source = WithHierarchy.class;
176-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
176+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
177177
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2",
178178
"2:TestAnnotation3");
179179
}
@@ -306,41 +306,41 @@ public void inheritedAnnotationsStrategyOnMethodHierarchyScansInCorrectOrder() {
306306
@Test
307307
public void superclassStrategyOnMethodWhenNotAnnoatedScansNone() {
308308
Method source = methodFrom(WithNoAnnotations.class);
309-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).isEmpty();
309+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).isEmpty();
310310
}
311311

312312
@Test
313313
public void superclassStrategyOnMethodScansAnnotations() {
314314
Method source = methodFrom(WithSingleAnnotation.class);
315-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
315+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
316316
"0:TestAnnotation1");
317317
}
318318

319319
@Test
320320
public void superclassStrategyOnMethodWhenMultipleAnnotationsScansAnnotations() {
321321
Method source = methodFrom(WithMultipleAnnotations.class);
322-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
322+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
323323
"0:TestAnnotation1", "0:TestAnnotation2");
324324
}
325325

326326
@Test
327327
public void superclassStrategyOnMethodWhenHasSuperclassScansSuperclass() {
328328
Method source = methodFrom(WithSingleSuperclass.class);
329-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
329+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
330330
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2");
331331
}
332332

333333
@Test
334334
public void superclassStrategyOnMethodWhenHasInterfaceDoesNotIncludeInterfaces() {
335335
Method source = methodFrom(WithSingleInterface.class);
336-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
336+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
337337
"0:TestAnnotation1");
338338
}
339339

340340
@Test
341341
public void superclassStrategyOnMethodHierarchyScansInCorrectOrder() {
342342
Method source = methodFrom(WithHierarchy.class);
343-
assertThat(scan(source, SearchStrategy.SUPER_CLASS)).containsExactly(
343+
assertThat(scan(source, SearchStrategy.SUPERCLASS)).containsExactly(
344344
"0:TestAnnotation1", "1:TestAnnotation2", "1:TestInheritedAnnotation2",
345345
"2:TestAnnotation3");
346346
}

spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -936,39 +936,39 @@ public void getDirectFromClassWithSubSubNonInheritedAnnotationInterface() {
936936
public void getSuperClassForAllScenarios() {
937937
// no class-level annotation
938938
assertThat(MergedAnnotations.from(NonAnnotatedInterface.class,
939-
SearchStrategy.SUPER_CLASS).get(
939+
SearchStrategy.SUPERCLASS).get(
940940
Transactional.class).getSource()).isNull();
941941
assertThat(MergedAnnotations.from(NonAnnotatedClass.class,
942-
SearchStrategy.SUPER_CLASS).get(
942+
SearchStrategy.SUPERCLASS).get(
943943
Transactional.class).getSource()).isNull();
944944
// inherited class-level annotation; note: @Transactional is inherited
945945
assertThat(MergedAnnotations.from(InheritedAnnotationInterface.class,
946-
SearchStrategy.SUPER_CLASS).get(
946+
SearchStrategy.SUPERCLASS).get(
947947
Transactional.class).getSource()).isEqualTo(
948948
InheritedAnnotationInterface.class);
949949
assertThat(MergedAnnotations.from(SubInheritedAnnotationInterface.class,
950-
SearchStrategy.SUPER_CLASS).get(
950+
SearchStrategy.SUPERCLASS).get(
951951
Transactional.class).getSource()).isNull();
952952
assertThat(MergedAnnotations.from(InheritedAnnotationClass.class,
953-
SearchStrategy.SUPER_CLASS).get(
953+
SearchStrategy.SUPERCLASS).get(
954954
Transactional.class).getSource()).isEqualTo(
955955
InheritedAnnotationClass.class);
956956
assertThat(MergedAnnotations.from(SubInheritedAnnotationClass.class,
957-
SearchStrategy.SUPER_CLASS).get(
957+
SearchStrategy.SUPERCLASS).get(
958958
Transactional.class).getSource()).isEqualTo(
959959
InheritedAnnotationClass.class);
960960
// non-inherited class-level annotation; note: @Order is not inherited,
961961
// but we should still find it on classes.
962962
assertThat(MergedAnnotations.from(NonInheritedAnnotationInterface.class,
963-
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo(
963+
SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
964964
NonInheritedAnnotationInterface.class);
965965
assertThat(MergedAnnotations.from(SubNonInheritedAnnotationInterface.class,
966-
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isNull();
966+
SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isNull();
967967
assertThat(MergedAnnotations.from(NonInheritedAnnotationClass.class,
968-
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo(
968+
SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
969969
NonInheritedAnnotationClass.class);
970970
assertThat(MergedAnnotations.from(SubNonInheritedAnnotationClass.class,
971-
SearchStrategy.SUPER_CLASS).get(Order.class).getSource()).isEqualTo(
971+
SearchStrategy.SUPERCLASS).get(Order.class).getSource()).isEqualTo(
972972
NonInheritedAnnotationClass.class);
973973
}
974974

@@ -1045,7 +1045,7 @@ public void getSuperClassSourceForTypesWithMultipleCandidateTypes() {
10451045

10461046
private Object getSuperClassSourceWithTypeIn(Class<?> clazz,
10471047
List<Class<? extends Annotation>> annotationTypes) {
1048-
return MergedAnnotations.from(clazz, SearchStrategy.SUPER_CLASS).stream().filter(
1048+
return MergedAnnotations.from(clazz, SearchStrategy.SUPERCLASS).stream().filter(
10491049
MergedAnnotationPredicates.typeIn(annotationTypes).and(
10501050
MergedAnnotation::isDirectlyPresent)).map(
10511051
MergedAnnotation::getSource).findFirst().orElse(null);
@@ -1279,7 +1279,7 @@ public void getRepeatableDeclaredOnClass() {
12791279
Class<?> element = MyRepeatableClass.class;
12801280
String[] expectedValuesJava = { "A", "B", "C" };
12811281
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
1282-
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava,
1282+
testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
12831283
expectedValuesSpring);
12841284
}
12851285

@@ -1288,7 +1288,7 @@ public void getRepeatableDeclaredOnSuperclass() {
12881288
Class<?> element = SubMyRepeatableClass.class;
12891289
String[] expectedValuesJava = { "A", "B", "C" };
12901290
String[] expectedValuesSpring = { "A", "B", "C", "meta1" };
1291-
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava,
1291+
testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
12921292
expectedValuesSpring);
12931293
}
12941294

@@ -1297,7 +1297,7 @@ public void getRepeatableDeclaredOnClassAndSuperclass() {
12971297
Class<?> element = SubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
12981298
String[] expectedValuesJava = { "X", "Y", "Z" };
12991299
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
1300-
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava,
1300+
testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
13011301
expectedValuesSpring);
13021302
}
13031303

@@ -1306,7 +1306,7 @@ public void getRepeatableDeclaredOnMultipleSuperclasses() {
13061306
Class<?> element = SubSubMyRepeatableWithAdditionalLocalDeclarationsClass.class;
13071307
String[] expectedValuesJava = { "X", "Y", "Z" };
13081308
String[] expectedValuesSpring = { "X", "Y", "Z", "meta2" };
1309-
testRepeatables(SearchStrategy.SUPER_CLASS, element, expectedValuesJava,
1309+
testRepeatables(SearchStrategy.SUPERCLASS, element, expectedValuesJava,
13101310
expectedValuesSpring);
13111311
}
13121312

0 commit comments

Comments
 (0)