Skip to content

Refactor: unify @SimpleBuilder and @SimpleBuilder.Template by making @SimpleBuilder a built-in template #246

Description

@devin-ai-integration

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions