Skip to content

feat(options): add packageName option for generated builders - #306

Merged
AndreasIgel merged 3 commits into
java-helpers:mainfrom
igel-devin-ai:devin/package-name-option
Sep 30, 2026
Merged

AndreasIgel merged 3 commits into
java-helpers:mainfrom
igel-devin-ai:devin/package-name-option

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Issues: closes #294 · follow-up to #293 (#296)

Summary

Adds a packageName member to @SimpleBuilder.Options that places generated builders into a configured package instead of the default one. The default is unchanged: the annotated type's package for @SimpleBuilder, resp. the holder's package for @SimpleBuilderFor.

@SimpleBuilderFor(
    value = ExternalUser.class,
    options = @SimpleBuilder.Options(packageName = "com.example.generated"))
public class ExternalBuilders { }

// Generated class: com.example.generated.ExternalUserBuilder

packageName is annotation-only (CompilerArgumentsEnum.annotationOnly): a global -Asimplebuilder.packageName / -D value would collapse all generated builders into a single package, so it is deliberately ignored on the compiler-argument path.

Implementation

  • BuilderConfiguration / CompilerArgumentsEnum: packageName threaded through as a regular string option on the annotation-parsing path.
  • BuilderProcessor: an effectiveBuilderPackage() helper resolves configured packageName or falls back to the reporting element's package; it feeds ProcessingTarget.builderPackage and the generated-builder registration, so builder TypeName, file placement, and the registerGeneratedBuilder mapping all agree.
  • Accessibility follows the configured package: members not reachable from it (package-private/protected constructors, setters, getters) are treated as absent — new test packageName_PackagePrivateConstructorIsNotReachable.
  • Compile-time validation: SourceVersion.isName rejects invalid package names with a diagnostic on the affected element.

Tests

  • packageName_GeneratesBuilderIntoConfiguredPackage — for both @SimpleBuilderFor (holder) and @SimpleBuilder
  • packageName_Invalid_ProducesDiagnosticAndNoBuilder
  • packageName_PackagePrivateConstructorIsNotReachable
  • packageName_GlobalCompilerArgumentIsIgnored

468 processor tests + 30 example tests green locally.

Documentation

  • New #### packageName section in docs/CONFIGURATION.md (default, annotation-only semantics, accessibility, example)
  • Javadoc on the new Options member
  • README: @SimpleBuilderFor + packageName called out in the "How Simple Builders compares" section

Closes #294

devin-ai-integration Bot and others added 3 commits September 30, 2026 19:34
Adds a new packageName member to @SimpleBuilder.Options that places
generated builders into a configured package instead of the default one
(the annotated type's package, resp. the @SimpleBuilderFor holder's
package).

- Effective package flows through ProcessingTarget.builderPackage, so
  builder TypeName, accessibility checks and file placement all follow
  the configured package consistently.
- Members not reachable from the configured package (package-private
  and protected constructors/setters/getters) are treated as absent.
- Invalid package names are rejected at compile time via
  SourceVersion.isName with a diagnostic on the affected element.
- Also available as compiler option -Asimplebuilder.packageName.

Resolves java-helpers#294

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
A global -Asimplebuilder.packageName / -Dsimplebuilder.packageName would
collapse all generated builders into a single package, so the option is
now declared annotationOnly and ignored on the compiler-arg path.

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
Moves the packageName validity check into BuilderConfigurationReader
next to validateAccessModifiers - the resolved configuration is
validated once for @SimpleBuilder targets and @SimpleBuilderFor
holders.

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@codecov

codecov Bot commented Sep 30, 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!

@sonarqubecloud

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit 7c94558 into java-helpers:main Sep 30, 2026
6 checks passed
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.

Configure the Package of Generated Builders for external types

2 participants