Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce predicate for searching enclosing classes in MergedAnnotations
Due to the deprecation of the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy (see gh-28079), this commit introduces a way for users to provide a Predicate<Class<?>> that is used to decide when the enclosing class for the class supplied to the predicate should be searched. This gives the user complete control over the "enclosing classes" aspect of the search algorithm in MergedAnnotations. - To achieve the same behavior as TYPE_HIERARCHY_AND_ENCLOSING_CLASSES, a user can provide `clazz -> true` as the predicate. - To limit the enclosing class search to inner classes, a user can provide `ClassUtils::isInnerClass` as the predicate. - To limit the enclosing class search to static nested classes, a user can provide `ClassUtils::isStaticClass` as the predicate. - For more advanced use cases, the user can provide a custom predicate. For example, the following performs a search on MyInnerClass within the entire type hierarchy and enclosing class hierarchy of that class. MergedAnnotations mergedAnnotations = MergedAnnotations.search(TYPE_HIERARCHY) .withEnclosingClasses(ClassUtils::isInnerClass) .from(MyInnerClass.class); In addition, TestContextAnnotationUtils in spring-test has been revised to use this new feature where feasible. Closes gh-28207
- Loading branch information
Showing
6 changed files
with
217 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.