Context
@SimpleBuilder and the separate @SimpleBuilder.Template annotations are currently handled by two distinct discovery paths in BuilderProcessor:
getElementsAnnotatedWith(SimpleBuilder.class)
- a loop over custom annotations whose type is meta-annotated with
@SimpleBuilder.Template
SimpleBuilder is even explicitly excluded from the template scan in BuilderProcessor.shouldSkipAnnotation(...).
Idea
Instead of treating @SimpleBuilder as a special case, it could be made a built-in template annotation itself:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
@SimpleBuilder.Template(options = @Options())
public @interface SimpleBuilder {
// optional inline override of the template defaults
Options options() default @Options();
}
@SimpleBuilder.Template already defines an Options options() member, so all properties that live on @SimpleBuilder can be expressed through Template.options.
Benefits
- A single discovery loop over all annotation types that are meta-annotated with
@SimpleBuilder.Template (including @SimpleBuilder itself) would cover both built-in and custom templates.
- The processor code would no longer need the special
SimpleBuilder branch, reducing duplication.
- It would make the inheritance model explicit:
@SimpleBuilder (not @Inherited) is the default preset, while custom annotations can be @Inherited templates.
Open questions / caveats
- How are inline
SimpleBuilder.options() overrides merged with the Template/options defaults from the meta-annotation?
- What happens to the
@SimpleBuilder Javadoc and @Target? It must remain usable on types, while @Template is @Target(ANNOTATION_TYPE).
- Any changes here need dedicated tests to prove
@SimpleBuilder still works standalone and custom templates still inherit correctly.
Context
@SimpleBuilderand the separate@SimpleBuilder.Templateannotations are currently handled by two distinct discovery paths inBuilderProcessor:getElementsAnnotatedWith(SimpleBuilder.class)@SimpleBuilder.TemplateSimpleBuilderis even explicitly excluded from the template scan inBuilderProcessor.shouldSkipAnnotation(...).Idea
Instead of treating
@SimpleBuilderas a special case, it could be made a built-in template annotation itself:@SimpleBuilder.Templatealready defines anOptions options()member, so all properties that live on@SimpleBuildercan be expressed throughTemplate.options.Benefits
@SimpleBuilder.Template(including@SimpleBuilderitself) would cover both built-in and custom templates.SimpleBuilderbranch, reducing duplication.@SimpleBuilder(not@Inherited) is the default preset, while custom annotations can be@Inheritedtemplates.Open questions / caveats
SimpleBuilder.options()overrides merged with theTemplate/optionsdefaults from the meta-annotation?@SimpleBuilderJavadoc and@Target? It must remain usable on types, while@Templateis@Target(ANNOTATION_TYPE).@SimpleBuilderstill works standalone and custom templates still inherit correctly.