Skip to content

Introduce fluent API for search options in MergedAnnotations #28208

Closed
@sbrannen

Description

@sbrannen

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);

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions