2626import java .util .Arrays ;
2727import java .util .List ;
2828import java .util .Objects ;
29+ import java .util .function .Predicate ;
2930import java .util .stream .Stream ;
3031
3132import org .junit .jupiter .api .Test ;
3233
3334import org .springframework .core .annotation .MergedAnnotations .Search ;
3435import org .springframework .core .annotation .MergedAnnotations .SearchStrategy ;
3536import org .springframework .lang .Nullable ;
37+ import org .springframework .util .ClassUtils ;
3638import org .springframework .util .ReflectionUtils ;
3739
3840import static org .assertj .core .api .Assertions .assertThat ;
@@ -422,29 +424,34 @@ void typeHierarchyStrategyOnMethodWithGenericParameterNonOverrideScansAnnotation
422424 }
423425
424426 @ Test
425- @ SuppressWarnings ("deprecation" )
426- void typeHierarchyWithEnclosedStrategyOnEnclosedStaticClassScansAnnotations () {
427+ void typeHierarchyStrategyWithEnclosingClassPredicatesOnEnclosedStaticClassScansAnnotations () {
427428 Class <?> source = AnnotationEnclosingClassSample .EnclosedStatic .EnclosedStaticStatic .class ;
428- assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY_AND_ENCLOSING_CLASSES ))
429+ assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY , ClassUtils ::isInnerClass ))
430+ .containsExactly ("0:EnclosedThree" );
431+ assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY , Search .always ).toList ())
432+ .isEqualTo (scan (source , SearchStrategy .TYPE_HIERARCHY , ClassUtils ::isStaticClass ).toList ())
429433 .containsExactly ("0:EnclosedThree" , "1:EnclosedTwo" , "2:EnclosedOne" );
430434 }
431435
432436 @ Test
433- @ SuppressWarnings ("deprecation" )
434- void typeHierarchyWithEnclosedStrategyOnEnclosedInnerClassScansAnnotations () {
437+ void typeHierarchyStrategyWithEnclosingClassPredicatesOnEnclosedInnerClassScansAnnotations () {
435438 Class <?> source = AnnotationEnclosingClassSample .EnclosedInner .EnclosedInnerInner .class ;
436- assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY_AND_ENCLOSING_CLASSES ))
439+ assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY , ClassUtils ::isStaticClass ))
440+ .containsExactly ("0:EnclosedThree" );
441+ assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY , Search .always ).toList ())
442+ .isEqualTo (scan (source , SearchStrategy .TYPE_HIERARCHY , ClassUtils ::isInnerClass ).toList ())
437443 .containsExactly ("0:EnclosedThree" , "1:EnclosedTwo" , "2:EnclosedOne" );
438444 }
439445
440446 @ Test
441- @ SuppressWarnings ("deprecation" )
442- void typeHierarchyWithEnclosedStrategyOnMethodHierarchyUsesTypeHierarchyScan () {
447+ void typeHierarchyStrategyWithEnclosingClassPredicatesOnMethodHierarchyUsesTypeHierarchyScan () {
443448 Method source = methodFrom (WithHierarchy .class );
444- assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY_AND_ENCLOSING_CLASSES )).containsExactly (
445- "0:TestAnnotation1" , "1:TestAnnotation5" , "1:TestInheritedAnnotation5" ,
446- "2:TestAnnotation6" , "3:TestAnnotation2" , "3:TestInheritedAnnotation2" ,
447- "4:TestAnnotation3" , "5:TestAnnotation4" );
449+ assertThat (scan (source , SearchStrategy .TYPE_HIERARCHY , Search .always ).toList ())
450+ .isEqualTo (scan (source , SearchStrategy .TYPE_HIERARCHY , ClassUtils ::isInnerClass ).toList ())
451+ .containsExactly (
452+ "0:TestAnnotation1" , "1:TestAnnotation5" , "1:TestInheritedAnnotation5" ,
453+ "2:TestAnnotation6" , "3:TestAnnotation2" , "3:TestInheritedAnnotation2" ,
454+ "4:TestAnnotation3" , "5:TestAnnotation4" );
448455 }
449456
450457 @ Test
@@ -509,8 +516,14 @@ private Method methodFrom(Class<?> type) {
509516 }
510517
511518 private Stream <String > scan (AnnotatedElement element , SearchStrategy searchStrategy ) {
519+ return scan (element , searchStrategy , Search .never );
520+ }
521+
522+ private Stream <String > scan (AnnotatedElement element , SearchStrategy searchStrategy ,
523+ Predicate <Class <?>> searchEnclosingClass ) {
524+
512525 List <String > results = new ArrayList <>();
513- scan (this , element , searchStrategy ,
526+ scan (this , element , searchStrategy , searchEnclosingClass ,
514527 (criteria , aggregateIndex , source , annotations ) -> {
515528 trackIndexedAnnotations (aggregateIndex , annotations , results );
516529 return null ; // continue searching
@@ -521,7 +534,13 @@ private Stream<String> scan(AnnotatedElement element, SearchStrategy searchStrat
521534 private static <C , R > R scan (C context , AnnotatedElement source , SearchStrategy searchStrategy ,
522535 AnnotationsProcessor <C , R > processor ) {
523536
524- return AnnotationsScanner .scan (context , source , searchStrategy , Search .never , processor );
537+ return scan (context , source , searchStrategy , Search .never , processor );
538+ }
539+
540+ private static <C , R > R scan (C context , AnnotatedElement source , SearchStrategy searchStrategy ,
541+ Predicate <Class <?>> searchEnclosingClass , AnnotationsProcessor <C , R > processor ) {
542+
543+ return AnnotationsScanner .scan (context , source , searchStrategy , searchEnclosingClass , processor );
525544 }
526545
527546 private void trackIndexedAnnotations (int aggregateIndex , Annotation [] annotations , List <String > results ) {
0 commit comments