Skip to content

Add @Ignore4BuilderGeneration opt-out for DTO builder generation - #242

Open
AndreasIgel wants to merge 1 commit into
java-helpers:mainfrom
AndreasIgel:feature/ignore4builder-generation
Open

Add @Ignore4BuilderGeneration opt-out for DTO builder generation#242
AndreasIgel wants to merge 1 commit into
java-helpers:mainfrom
AndreasIgel:feature/ignore4builder-generation

Conversation

@AndreasIgel

Copy link
Copy Markdown
Collaborator

Summary

Introduces @Ignore4BuilderGeneration so a class/record can opt out of builder generation even when it inherits @SimpleBuilder or an @SimpleBuilder.Template annotation from a parent type. Opted-out DTOs are treated as "no builder available", so other builders fall back to plain setters instead of emitting nested-builder consumers that would reference a non-existent builder.

What's changed

  • New annotation org.javahelpers.simple.builders.core.annotations.Ignore4BuilderGeneration
    • @Target(ElementType.TYPE), @Retention(RetentionPolicy.CLASS)
    • Intentionally NOT @Inherited; it suppresses only the exact type it is placed on.
  • BuilderProcessor.process(...) now filters the elementsToProcess set, removing any element that directly carries @Ignore4BuilderGeneration and logging a debug message. The check uses the element's own annotation mirrors, so a parent's opt-out never leaks to subclasses.
  • JavaLangMapper centralises the "no builder" decision:
    • setBuilderTypeIfAnnotated(...) returns early for @Ignore4BuilderGeneration types.
    • setElementBuilderTypeForGenericCollections(...) likewise skips element-builder generation when the element type is opted out.
  • Added Ignore4BuilderGenerationTest with three scenarios:
    1. Subclass inherits an @Inherited @SimpleBuilder.Template from its parent and is annotated with @Ignore4BuilderGeneration — parent's builder is generated, child's is not.
    2. A DTO has a field whose type is @Ignore4BuilderGeneration — the referencing builder uses a plain ignored(IgnoredDto) setter and does not mention IgnoredDtoBuilder or Consumer<IgnoredDtoBuilder>.
    3. Regression: a normally annotated DTO still gets a builder and is referenced by other builders.
  • Documentation updated:
    • docs/CONFIGURATION.md: new "Excluding Types from Builder Generation" section.
    • SimpleBuilder class-level Javadoc: added related-annotations summary linking to IgnoreInBuilder and Ignore4BuilderGeneration.

mvn clean verify passes for the full project and all 286 processor tests pass.

- new TYPE-level annotation @Ignore4BuilderGeneration with CLASS retention
- BuilderProcessor filters out elements carrying the annotation directly,
  logging a debug message; inheritance not checked so it does not cascade
- JavaLangMapper skips builder type and element-builder references for
  opted-out TypeElements, preventing other DTOs from emitting nested-builder
  consumers for them
- add Ignore4BuilderGenerationTest covering inherited template opt-out,
  referenced opted-out field fallback, and regression for normal DTOs
- document in CONFIGURATION.md and SimpleBuilder class-level Javadoc

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the feature/ignore4builder-generation branch from 44ad09d to f78aaee Compare August 9, 2026 13:45
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant