-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Introduce fluent API for search options in MergedAnnotations #28208
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
Comments
After putting more thought into this, I wonder if it's best to end the fluent API with
@philwebb recommended all new factory methods in However, if the final action in the fluent API is a method named So, another idea I'm tinkering with is starting with a single static factory method for "search options" like this: MergedAnnotations annotations = MergedAnnotations.searchOptions()
.typeHierarchy()
.repeatableContainers(myRepeatableContainers)
.annotationFilter(myCustomAnnotationFilter)
.search(myClass); One additional (unplanned) benefit of that is that the |
Current proposal, based on brainstorming sessions and taking #28207 into account: MergedAnnotations
.search(searchStrategy)
.withEnclosingClasses(ClassUtils::isInnerClass)
.withRepeatableContainers(repeatableContainers)
.withAnnotationFilter(annotationFilter)
.from(myClass); |
Ha, I was about to suggest this :) MergedAnnotations
.searching(searchStrategy)
.withEnclosingClasses(ClassUtils::isInnerClass)
.withRepeatableContainers(repeatableContainers)
.withAnnotationFilter(annotationFilter)
.from(myClass); |
I think convenience search methods are also worth considering. MergedAnnotations.searchingTypeHierarchy().with...().from(myClass) |
We definitely considered that approach, but the choice of meaningful (and concise) names becomes challenging for any MergedAnnotations
// .searchDirect()
// .searchInheritedAnnotations()
// .searchSuperclass()
.searchTypeHierarchy()
.withEnclosingClasses(ClassUtils::isInnerClass)
.withRepeatableContainers(repeatableContainers)
.withAnnotationFilter(annotationFilter)
.from(myClass); The above seems too vague, and the following seems too verbose. MergedAnnotations
// .findDirectlyDeclaredAnnotations()
// .findInheritedAnnotations()
// .findSuperclassAnnotations()
.findAnnotationsInTypeHierarchy()
.withEnclosingClasses(ClassUtils::isInnerClass)
.withRepeatableContainers(repeatableContainers)
.withAnnotationFilter(annotationFilter)
.from(myClass); In the end, @jhoeller and I decided that it's probably best to let the user supply a But... if you have better ideas for how to name all 4 convenience methods, by all means speak up. 👍 |
Overview
Inspired by the requirements for implementing #28207, we have decided to introduce a fluent API for search options in
MergedAnnotations
.The following is an example of how one would supply search options using the existing API.
Proposal
For each strategy in
SearchStrategy
, we will introduce a correspondingfind*()
method that starts the fluent API. Methods such asusingRepeatableContainers()
andwithAnnotationFilter()
will be optional. The fluent API culminates with an invocation offrom(...)
which performs the search and returns theMergedAnnotations
instance.With a fluent API, the above can be rewritten as follows.
For a less involved use case that relies on the defaults for repeatable containers and filtering, the code would reduce to the following.
The text was updated successfully, but these errors were encountered: