-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Remove TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy for MergedAnnotations #28080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Comments
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Mar 16, 2022
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 spring-projectsgh-28079 See spring-projectsgh-28080
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Mar 18, 2022
This commit is a "proof of concept" for introducing a `Predicate<Class<?>> searchEnclosingClass` for use with the TYPE_HIERARCHY search strategy as a replacement for the deprecated TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy. Currently (in this commit) it is possible for a user to supply a searchEnclosingClass predicate for any SearchStrategy; however, the predicate is only honored if the search strategy is TYPE_HIERARCHY. Thus, we may later choose to throw an exception is the user supplies a predicate for a search strategy other than TYPE_HIERARCHY. This commit also demonstrates that this new feature can be utilized in TestContextAnnotationUtils for the implementation of hasAnnotation(...) and findMergedAnnotation(...). See spring-projectsgh-28080
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Mar 18, 2022
This commit is a "proof of concept" for introducing a SearchAlgorithm builder for simplifying the creation of a MergedAnnotations instance. With this commit it is no longer possible for a user to supply a searchEnclosingClass predicate for any SearchStrategy other than TYPE_HIERARCHY. See spring-projectsgh-28080
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Mar 19, 2022
This commit is a "proof of concept" for introducing a fluent API for MergedAnnotations searches. This commit replaces the SearchAlgorithm from the previous commit by adding a builder directly to MergedAnnotations and introducing static `find*(...)` factory methods in MergedAnnotations such as findDirectlyDeclaredAnnotations() and other similar methods matching the available strategies in SearchStrategy. A user can only supply a searchEnclosingClass predicate for SearchStrategy.TYPE_HIERARCHY via MergedAnnotations.findAnnotationsInTypeHierarchy(Predicate<Class<?>>). This leads to usage such as the following in TestContextAnnotationUtils. MergedAnnotations .findAnnotationsInTypeHierarchy(TestContextAnnotationUtils::searchEnclosingClass) .from(clazz) .isPresent(annotationType); See spring-projectsgh-28080
Blocked until #28207 is implemented |
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Mar 22, 2022
Prior to this commit, searching for merged annotations on an AnnotatedElement in the MergedAnnotations model was only supported via various overloaded from(...) factory methods. In addition, it was not possible to provide a custom AnnotationFilter without providing an instance of RepeatableContainers. This commit introduces a fluent API for searches in MergedAnnotations to address these issues and improve the programming model for users of MergedAnnotations. To begin a search, invoke MergedAnnotations.search(SearchStrategy) with the desired search strategy. Optional configuration can then be provided via one of the with(...) methods. To perform a search, invoke from(AnnotatedElement), supplying the element from which to begin the search -- for example, a Class or a Method. For example, the following performs a search on MyClass within the entire type hierarchy of that class while ignoring repeatable annotations. MergedAnnotations mergedAnnotations = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY) .withRepeatableContainers(RepeatableContainers.none()) .from(MyClass.class); To reuse search configuration to perform the same type of search on multiple elements, you can save the Search instance as demonstrated in the following example. Search search = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY) .withRepeatableContainers(RepeatableContainers.none()); MergedAnnotations mergedAnnotations = search.from(MyClass.class); // do something with the MergedAnnotations for MyClass mergedAnnotations = search.from(AnotherClass.class); // do something with the MergedAnnotations for AnotherClass In addition, this fluent search API paves the way for introducing support for a predicate that controls the search on enclosing classes (spring-projectsgh-28207) and subsequently for completely removing the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy (spring-projectsgh-28080). Closes spring-projectsgh-28208
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Overview
Since #28207 has introduced support for providing a
Predicate<Class<?>>
that allows for complete control over the "enclosing classes" aspect of the search algorithm inMergedAnnotations
, the deprecatedTYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy can now be completely removed.Related Issues
The text was updated successfully, but these errors were encountered: