Description
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.
MergedAnnotations annotations = MergedAnnotations.from(myClass, SearchStrategy.TYPE_HIERARCHY,
RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class),
myCustomAnnotationFilter);
Proposal
For each strategy in SearchStrategy
, we will introduce a corresponding find*()
method that starts the fluent API. Methods such as usingRepeatableContainers()
and withAnnotationFilter()
will be optional. The fluent API culminates with an invocation of from(...)
which performs the search and returns the MergedAnnotations
instance.
With a fluent API, the above can be rewritten as follows.
MergedAnnotations annotations = MergedAnnotations
.findAnnotationsInTypeHierarchy()
.usingRepeatableContainers(RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class))
.withAnnotationFilter(myCustomAnnotationFilter)
.from(myClass);
For a less involved use case that relies on the defaults for repeatable containers and filtering, the code would reduce to the following.
MergedAnnotations annotations = MergedAnnotations.findAnnotationsInTypeHierarchy().from(myClass);