Deprecate "enclosing classes" search strategy for MergedAnnotations

This commit deprecates the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search
strategy for MergedAnnotations in 6.0 M3, allowing consumers of 6.0
milestones and release candidates to provide feedback before
potentially completely removing the search strategy or providing an
alternate mechanism for achieving the same goal prior to 6.0 GA.

Closes gh-28079
See gh-28080
This commit is contained in:
Sam Brannen
2022-03-16 19:32:52 +01:00
parent a3781a45d6
commit fc8f31ccfb
4 changed files with 14 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,6 +92,7 @@ abstract class AnnotationsScanner {
}
@Nullable
@SuppressWarnings("deprecation")
private static <C, R> R processClass(C context, Class<?> source,
SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor) {
@@ -229,6 +230,7 @@ abstract class AnnotationsScanner {
}
@Nullable
@SuppressWarnings("deprecation")
private static <C, R> R processMethod(C context, Method source,
SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor) {
@@ -499,6 +501,7 @@ abstract class AnnotationsScanner {
return (type.getName().startsWith("java.") || type == Ordered.class);
}
@SuppressWarnings("deprecation")
private static boolean isWithoutHierarchy(AnnotatedElement source, SearchStrategy searchStrategy) {
if (source == Object.class) {
return true;

View File

@@ -492,7 +492,10 @@ public interface MergedAnnotations extends Iterable<MergedAnnotation<Annotation>
* whether the source type is an <em>inner class</em>, a {@code static}
* nested class, or a nested interface. Thus, it may find more annotations
* than you would expect.
* @deprecated as of Spring Framework 6.0 M3, for potential removal or
* replacement before 6.0 GA
*/
@Deprecated
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -421,6 +421,7 @@ class AnnotationsScannerTests {
}
@Test
@SuppressWarnings("deprecation")
void typeHierarchyWithEnclosedStrategyOnEnclosedStaticClassScansAnnotations() {
Class<?> source = AnnotationEnclosingClassSample.EnclosedStatic.EnclosedStaticStatic.class;
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES))
@@ -428,6 +429,7 @@ class AnnotationsScannerTests {
}
@Test
@SuppressWarnings("deprecation")
void typeHierarchyWithEnclosedStrategyOnEnclosedInnerClassScansAnnotations() {
Class<?> source = AnnotationEnclosingClassSample.EnclosedInner.EnclosedInnerInner.class;
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES))
@@ -435,6 +437,7 @@ class AnnotationsScannerTests {
}
@Test
@SuppressWarnings("deprecation")
void typeHierarchyWithEnclosedStrategyOnMethodHierarchyUsesTypeHierarchyScan() {
Method source = methodFrom(WithHierarchy.class);
assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES)).containsExactly(

View File

@@ -711,6 +711,7 @@ class MergedAnnotationsTests {
}
@Test
@SuppressWarnings("deprecation")
void streamTypeHierarchyAndEnclosingClassesFromNonAnnotatedInnerClassWithAnnotatedEnclosingClass() {
Stream<Class<?>> classes = MergedAnnotations.from(AnnotatedClass.NonAnnotatedInnerClass.class,
SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES).stream().map(MergedAnnotation::getType);
@@ -718,6 +719,7 @@ class MergedAnnotationsTests {
}
@Test
@SuppressWarnings("deprecation")
void streamTypeHierarchyAndEnclosingClassesFromNonAnnotatedStaticNestedClassWithAnnotatedEnclosingClass() {
Stream<Class<?>> classes = MergedAnnotations.from(AnnotatedClass.NonAnnotatedStaticNestedClass.class,
SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES).stream().map(MergedAnnotation::getType);
@@ -725,6 +727,7 @@ class MergedAnnotationsTests {
}
@Test
@SuppressWarnings("deprecation")
void getFromMethodWithMethodAnnotationOnLeaf() throws Exception {
Method method = Leaf.class.getMethod("annotatedOnLeaf");
assertThat(method.getAnnotation(Order.class)).isNotNull();