Skip to content

feat(annotations): make @SimpleBuilderFor repeatable - #322

Merged
AndreasIgel merged 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/1791054986-repeatable-builder-for
Oct 3, 2026
Merged

AndreasIgel merged 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/1791054986-repeatable-builder-for

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Issues: follow-up to #296 and #293

Summary

Makes @SimpleBuilderFor @Repeatable: several declarations may be placed on the same holder class or package-info.java, each carrying its own value list and options. This lets one holder route different types into different generated packages:

@SimpleBuilderFor(
    value = ExternalUser.class,
    options = @SimpleBuilder.Options(packageName = "com.example.users"))
@SimpleBuilderFor(
    value = ExternalOrder.class,
    options = @SimpleBuilder.Options(packageName = "com.example.orders"))
public class ExternalBuildersProvider { }

Implementation

  • SimpleBuilderFors — the container annotation javac wraps repeated declarations in (same {TYPE, PACKAGE} target, CLASS retention).
  • JavaLangAnalyser.findAnnotationInstances — generic repeatable-annotation lookup: direct mirrors plus entries unwrapped from the container, in declaration order.
  • BuilderProcessor — collects holders annotated with either the annotation or its container, then resolves value and options per instance, so each declaration gets its own packageName/builderSuffix/etc. Duplicate targets across declarations still hit the existing "already generated elsewhere" skip.
  • BuilderConfigurationReader.resolveHolderConfiguration — now takes the specific annotation instance instead of re-finding one on the element.

Tests

  • repeatable_GeneratesBuildersIntoDifferentPackages — two declarations with different packageName on one holder
  • repeatable_OnPackageInfo_GeneratesBuildersIntoAnnotatedPackage — repeated declarations in package-info.java
  • repeatable_DuplicateType_SecondDeclarationSkippedWithWarning — same type listed twice

499 processor tests + example regeneration check green locally.

Documentation

  • Javadoc on @SimpleBuilderFor documents the repeatable usage
  • docs/CONFIGURATION.md: repeatable example in the "Generating Builders for External Types" section

Written by Devin

Repeatable declarations on the same holder (class or package-info) let
each listing carry its own options - e.g. a different packageName per
declaration. Adds the SimpleBuilderFors container, a generic
findAnnotationInstances lookup in JavaLangAnalyser, and per-instance
target/config resolution in BuilderProcessor.

Relates to java-helpers#296

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

codecov Bot commented Oct 3, 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

sonarqubecloud Bot commented Oct 3, 2026

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit 04405dd into java-helpers:main Oct 3, 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.

2 participants