Uh oh!
There was an error while loading. Please reload this page.
fix: generate compilable collection helpers for primitive array fields (#261) - #267
Merged
AndreasIgel merged 20 commits intoAug 23, 2026
Conversation
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>
java-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…ive-array helpers Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…ve arrays (java-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…ive arrays (java-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…sumer helper (java-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…erload (java-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…a-helpers#261) Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#261
Problem
For array fields the processor generates two collection convenience helpers —
field(List<E>)(ArrayConversionGenerator) andfield(Consumer<ArrayListBuilder<E>>)(ArrayBuilderConsumerGenerator). Both were emitted for any array field, but their bodies were only valid for reference element types:Any DTO with a primitive array field produced a builder that did not compile.
Fix
Primitive element types now get explicit boxing/unboxing between the boxed
Listand the primitive array. Reference element types keep the existingtoArray(new E[0])/List.of(...)paths unchanged, so no generated output changes forString[],Integer[], etc.The project already depends on Apache Commons Lang3 at runtime (the generated builders already import
org.apache.commons.lang3.builder.ToStringBuilder). Itsorg.apache.commons.lang3.ArrayUtilsprovidestoPrimitive/toObjectfor all primitive/wrapper array pairs, andjava.util.Arrays.asListis used to seed theArrayListBuilderwith boxed values. With the new$label:Btemplate placeholder and a small mapper fix to preserve explicit code-block imports, the generated setter for a fieldint[] scoresbecomes:Changes
RoasterMapper—resolveCodeTemplatenow resolves$label:Bfor type placeholders via the existingmapBoxedType.BuilderToGenerationTypeMapper—toMethodDtonow copies explicitcodeBlockImportsfrom the generation-side method code DTO to the rendering-side DTO viaSet.addAll(...).ArrayConversionGenerator— primitive element types now useArrayUtils.toPrimitive(list.toArray(new Boxed[0])); reference types unchanged.ArrayBuilderConsumerGenerator— all array element types now seedArrayListBuilder<T>fromArrays.asList(...)(boxed existing array for primitives, or an empty list in the unset case) and convert back withtoArray(...); primitive arrays additionally box/unbox viaArrayUtils.CustomCollectionTypeTest— newprimitiveArrayFields_shouldGenerateCompilableCollectionHelperscoveringint[],boolean[]anddouble[]. Each generated collection-helper method and thebuild()method is asserted with a singlecontainsblock spanning the full method signature and body.Design note
The builder keeps storing the DTO's own type (
TrackedValue<int[]>) and converts at the setter boundary, rather than storing a boxedList<Integer>and unboxing inbuild(). The list-based helpers are not the only writers of an array field — the plain setter takesint... scores, the supplier setter takesSupplier<int[]>, the copy constructor readsint[]off an existing instance, and Jackson binds against the field type — so boxed storage would need a conversion on each of those paths plus inbuild(), and would make the builder field's type depend on its element type. There is also no incrementaladd-per-element method for array fields (AddToCollectionGeneratoronly applies to parameterizedList/Set), so the "avoid repeated reallocation while elements accumulate" argument for boxed storage does not apply here.Verification
mvn clean installfrom the repo root: BUILD SUCCESS for all modules (core, processor, example-custom-generator, example).processortest suite green; the new test relies on the compile-testing harness actually compiling the generated builder, which is exactly what failed before.examplemodule (checked in underexample/generated-example-builder) were regenerated and committed;PersonDtoBuildernow usesArrays.asList(...)for itsString[] nickNames2consumer helper, matching the new reference-array template.