Skip to content

feat: builder generation and usage package scoping (#114) - #264

Open
AndreasIgel wants to merge 14 commits into
java-helpers:mainfrom
AndreasIgel:devin/fix-issue-114-builder-scope
Open

feat: builder generation and usage package scoping (#114)#264
AndreasIgel wants to merge 14 commits into
java-helpers:mainfrom
AndreasIgel:devin/fix-issue-114-builder-scope

Conversation

@AndreasIgel

Copy link
Copy Markdown
Collaborator

Summary

Introduce two comma-separated package-list options, builderGenerationPackages and builderUsagePackages, so the processor can distinguish DTOs whose builders it generates from DTOs whose builders may be referenced from other builders. This fixes broken references to precompiled @SimpleBuilder-annotated DTOs that do not have a builder on the classpath.

What changed

  • SimpleBuilder.Options gains builderGenerationPackages() and builderUsagePackages() (default "" = unscoped, comma-separated, subpackages included).
  • CompilerArgumentsEnum, BuilderConfigurationReader, and CompilerArgumentsReader expose -Asimplebuilder.builderGenerationPackages and -Asimplebuilder.builderUsagePackages.
  • BuilderConfiguration stores both string values, exposes parsed Set<String> accessors, and provides isInGenerationScope(String) / isInUsageScope(String) using pkg.equals(p) || pkg.startsWith(p + ".").
  • New BuilderScopeResolver centralizes the "may a builder be referenced here?" decision:
    • Builder types that BuilderProcessor will actually generate in the current round are trusted first, so a per-class builderGenerationPackages override cannot force a reference to a builder that is not generated.
    • builderGenerationPackages (global) is trusted without a type-existence search.
    • builderUsagePackages (per-target) is used only when ProcessingContext.getTypeElement(candidateFqn) resolves the builder.
    • @Ignore4BuilderGeneration or absence of a @SimpleBuilder.Template annotation prevents any reference.
  • BuilderProcessor filters elementsToProcess by the global builderGenerationPackages scope before generating.
  • JavaLangMapper delegates field and collection-element builder resolution to BuilderScopeResolver; generators and enhancers keep checking TypeName.getBuilderType().isPresent().
  • Added BuilderScopeProcessorTest integration tests and BuilderConfigurationScopeTest unit tests covering regression, inclusion/exclusion, usage scope with existing/missing builders, @Ignore4BuilderGeneration precedence, per-class override not leaking, and compiler-arg + inline option parsing.
  • Updated docs/CONFIGURATION.md (new "Builder Scoping" section + options reference + complete example), docs/CUSTOMIZING.md (resolver note), and SimpleBuilder Javadoc.

Verification

mvn -pl core,processor,example test -am passes with 356 tests, 0 failures.

Related

Fixes#114

AndreasIgeland others added 14 commits August 15, 2026 10:57
The class-level Javadoc and docs/CONFIGURATION.md implied that
@SimpleBuilder is inherited by subclasses, but the annotation was not
meta-annotated with @inherited. As a result BuilderProcessor, which
collects types via RoundEnvironment.getElementsAnnotatedWith(...),
only produced builders for the exact type carrying @SimpleBuilder and
not for unannotated subclasses.
Add @inherited to @SimpleBuilder so subclasses are treated as if they
also carried the annotation, mirroring the existing behaviour of
@SimpleBuilder.Template (which is already @inherited). Update the
Javadoc to document the inheritance explicitly and clarify the
CONFIGURATION.md wording. @Ignore4BuilderGeneration still suppresses
generation for the exact type it is placed on, so opt-outs continue
to work as before.
Add SimpleBuilderInheritanceTest covering direct inheritance, the
opt-out interaction, and multi-level (grandchild) inheritance.
Closesjava-helpers#244
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ance
Rename SimpleBuilderInheritanceTest to BuilderAnnotationInheritanceTest
so the name reflects that it covers both builder-triggering annotations.
Add unannotatedSubclassGetsBuilderFromInheritedTemplate, which verifies
that a custom @inherited template annotation (meta-annotated with
@SimpleBuilder.Template) propagates to unannotated subclasses, matching
the existing behaviour of @SimpleBuilder itself.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The Template Javadoc and CONFIGURATION.md "Template Annotations" section
did not explain that @SimpleBuilder.Template is @inherited, nor that a
custom template annotation must additionally declare @inherited to
propagate to unannotated subclasses. Add explicit documentation and an
example showing the @inherited custom annotation pattern.
Also move assertNoBuilderGenerated to ProcessorAsserts so it is shared
by BuilderAnnotationInheritanceTest and Ignore4BuilderGenerationTest
instead of being duplicated as a private helper in each test class.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
While @SimpleBuilder and @inherited template annotations now correctly
trigger builder generation for unannotated subclasses, the configuration
options declared on the parent's @SimpleBuilder(options = ...) or template
are not yet applied to inherited subclass builders — they use default
options instead. This is tracked separately in issue java-helpers#245.
Add caveats to the SimpleBuilder Javadoc, the CONFIGURATION.md Template
Annotations section, and the Template Annotations Not Working
troubleshooting section so users are not surprised by this limitation.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Add explicit guidance that @SimpleBuilder.Template is a meta-annotation
for custom annotation declarations (@interface) only and cannot be
placed directly on a class or record. @SimpleBuilder is for direct
one-off annotation of classes/records.
- SimpleBuilder.java: add 'When to use' section to class-level Javadoc
- SimpleBuilder.Template Javadoc: state it can only be placed on
annotation types (ANNOTATION_TYPE), not on classes/records
- CONFIGURATION.md 'Template Annotations': add comparison table and
introductory paragraph
- CONFIGURATION.md troubleshooting: add item about @SimpleBuilder.Template
not being a class annotation
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…Javadoc
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…arget
The compiler and IDE already enforce @target(ANNOTATION_TYPE) and show
a clear error when @SimpleBuilder.Template is placed on a class/record,
so this troubleshooting item adds no value.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…for issue java-helpers#114
- Introduce BuilderScopeResolver to centralize may-a-builder-be-used decision.
- Add Options fields and compiler args for the two package scopes.
- Extend BuilderConfiguration with parsing and subpackage matching helpers.
- Wire JavaLangMapper and BuilderProcessor through the resolver/config.
- Add unit/integration tests and documentation updates.
Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…rated-type set
Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@codecov

codecovBot commented Aug 22, 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 freeto 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.

scan Packages should be customizable

1 participant

@AndreasIgel