Skip to content

feat: support explicit builder property mapping - #484

Open
igel-devin-ai wants to merge 9 commits into
java-helpers:mainfrom
igel-devin-ai:devin/1796199853-issue-458-builder-property
Open

igel-devin-ai wants to merge 9 commits into
java-helpers:mainfrom
igel-devin-ai:devin/1796199853-issue-458-builder-property

Conversation

@igel-devin-ai

Copy link
Copy Markdown
Contributor

Fixes #458.

Summary

  • add @BuilderProperty for explicit setter, getter, and constructor-parameter property mapping
  • copy automatic or explicitly mapped Optional<T> getters with TrackedValue.initialValueOf
  • validate conflicting or invalid explicit mappings and warn for constructor precedence/unmatched getters
  • document @BuilderProperty

Verification

  • mvn clean verify

@codecov

codecov Bot commented Dec 5, 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!

@igel-devin-ai

igel-devin-ai commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Strict review

changes needed

Reviewed head 41858ce836b871fb5b2deaa84bbe5df01ecec9ac against upstream/main 4b696141058c97b8130c3ce3920a7faeafbb3bbd, including issue #458, its #429/#437/#457 context, the PR body, issue comments, and inline comments. Existing Codecov/Sonar bot summaries are not repeated as findings. The annotation's METHOD/PARAMETER target and CLASS retention, compatibility constructor for GetterInfoDto, documented mapping rules, and direct Optional-property copy path are appropriate.

  1. major — verified — processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java:1072–1080,1094–1101: inherited generic Optional getters are compared without substituting the DTO's actual type arguments. With class Base<T> { public Optional<T> getValue(); } and @SimpleBuilder class Child extends Base<String> { public void setValue(String value); }, the candidate return type is inspected as Optional<T> rather than Optional<String>. isOptionalOf compares declaration T to the String property and rejects the getter. A strict compile-testing probe succeeds with 0 warnings, 0 errors, but copying an instance containing "kept" produces an unset/null property (Runtime result: LOST). Overriding the getter in the child with return type Optional<String> makes the otherwise identical copy preserve "kept", confirming the missing member-type substitution rather than an initialValueOf runtime defect. Resolve inherited executable types in the receiver's declared-type context (for example with Types.asMemberOf) before compatibility checks and Optional classification, for automatic and explicit getters. Add an inherited generic no-op-copy regression: this is still the silent value loss Explicit property mapping (@BuilderProperty) and Optional getters for copy constructor / with() #458 is intended to remove.

  2. minor — verified — processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java:587–594,966–979: duplicate explicit-setter validation runs before ignored/ineligible methods are excluded. One live @BuilderProperty("value") setter plus a second @IgnoreInBuilder @BuilderProperty("value") setter fails compilation with Multiple setters are mapped to builder property 'value'. The ignored method is subsequently excluded by isMethodRelevantForBuilder at line 606, but the error has already been emitted. Filter by the same inclusion/accessibility rules before duplicate mapping validation. An explicitly ignored method must not prevent a valid mapping from compiling; add a regression covering this combination. The corresponding ignored-getter probe correctly remains uncopied, so this is specifically an inconsistency in setter validation, not a claim that all IgnoreInBuilder handling is broken.

  3. minor — verified — processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java:1020–1058: explicitly mapped getters bypass the accessibility check used by automatic discovery. A private @BuilderProperty("value") String read() is selected for a public String setter. The processor emits this.value = initialValue(instance.read()); and javac then fails in PrivateGetterBuilder.java with read() has private access in test.PrivateGetter, rather than diagnosing the mapping at the annotated accessor. Automatic Optional lookup checks isAccessibleFromGeneratedPackage at line 1080; explicit lookup does not. Either reject inaccessible explicit mappings with a processor error on the user's getter, or consistently treat them as unreadable according to the accessor policy. Do not knowingly emit an inaccessible call. Cover private and inaccessible cross-package getters in processor diagnostics tests.

  4. minor — verified by test inspection, with passing external controls — processor/src/test/java/org/javahelpers/simple/builders/processor/BuilderPropertyTest.java:41–56,81–104: the acceptance-critical copy/default behavior is not exercised at runtime. The nine new tests compile fixtures and inspect snippets or diagnostics; they do not execute the required no-op with(b -> {}), verify empty Optional leaves defaults active, or execute a mapped-property copy. An external control does pass today: the generated Optional-copy path preserves "kept" through no-op with and an empty Optional leaves the configured "fallback" default. Add those runtime regression assertions plus an explicitly mapped-property no-op copy, retaining the existing Optional-typed-property check. The inherited value-loss case in finding 1 demonstrates why a call-text assertion alone does not establish copy fidelity. This is missing regression protection, not a claim that the ordinary Optional/default path currently fails.

  5. nit — verified — processor/src/test/java/org/javahelpers/simple/builders/processor/BuilderPropertyTest.java:55–56,75–76: new expected-Java snippets use ordinary literals instead of text blocks. The input compilation units are already text blocks and no new + concatenation was found. Convert the generated-source expectations, including the initialValueOf/initialValue statements, to text blocks too, following the requested source-string convention.

Verification

  • Java 17 / Maven 3.9.11: mvn -q install -pl codegen-core,codegen-roaster,processor -am -Dfmt.skip=true exited 0. Surefire XML totals: 1,384 tests, 0 failures, 0 errors, 0 skipped. Formatting was skipped to keep the review read-only.
  • External compile-testing probes used -Xlint:rawtypes -Xlint:unchecked -Asimplebuilder.strict=true. Inherited generic Optional: SUCCESS warnings=0 errors=0, runtime LOST; overridden/specialized getter control: SUCCESS warnings=0 errors=0, runtime kept; ignored setter: FAILURE warnings=0 errors=1; private getter: FAILURE warnings=0 errors=1; normal Optional/default control: SUCCESS warnings=0 errors=0, runtime kept/fallback; explicitly ignored getter: SUCCESS warnings=0 errors=0, runtime UNSET.
  • Also checked constructor precedence: a matching explicit setter is skipped with the documented warning and constructor mapping wins. One explicit setter colliding with an automatic setter reaches the existing field/method conflict warnings; issue Explicit property mapping (@BuilderProperty) and Optional getters for copy constructor / with() #458 specifically requires errors for two annotated setters, so I am not misreporting that broader behavior as an acceptance failure. A primitive-int/Optional probe remains uncopied; boxing compatibility is not explicitly defined by the issue's exact-T rule, so it is not counted as a separate finding here.
  • git_pr_checks returned no checks for this head. The Actions API reports Java CI run 47578105070 and CodeQL run 47578105065 as action_required, with no jobs available to retrieve logs from; dependency review run 47578103117 reports startup_failure. Earlier Codecov/Sonar comments do not establish a passing current-head Java build.
  • The ordinary Optional-typed-property path still generates initialValue, as the new regression test asserts; no example-module artifact changes are included in this PR. I did not independently regenerate the entire example module for this head. No repository source/test files were edited.

Other-PR integration review

Written by Devin


Recheck at 505bd402 (2026-12-06)

Verdict: minor changes

# Original finding (short) Status Remaining action
1 Inherited generic Optional copy loses value fixed —
2 Ignored setter falsely duplicates mapping fixed; regression missing — minor Add ignored/active duplicate-mapping test (BuilderDefinitionCreator.java:594–596).
3 Inaccessible explicit getter called fixed; regression missing — minor Test private and cross-package protected getters (BuilderDefinitionCreator.java:1061–1066).
4 Runtime copy/default coverage partially fixed — minor Test no-op with and empty Optional fallback (BuilderPropertyTest.java:62–147).
5 Test-string convention not fixed — nit Convert source expectations and new helper diagnostic to text blocks (BuilderPropertyTest.java:55–57,165–167; ProcessorTestUtils.java:127–131).

Build: Java 17 full mvn -B verify — BUILD SUCCESS; 1,421 tests, 0 failures/errors; example compile succeeds without tracked drift; mapping/copy probes behave correctly.


Recheck at 619ec391 (2026-12-06)

Verdict: minor changes

Severity What is missing Where (file:line)
minor Partial: protected-getter fixture lacks @BuilderProperty and expects success; add the annotated cross-package diagnostic case. BuilderPropertyTest.java:410–435
minor Partial: test with(...), not only copy constructor; empty-Optional fixture must observe a real default (getter is constant/setter ignores writes). BuilderPropertyTest.java:330–383
nit Partial: expected generated-source fixtures remain ordinary strings; helper diagnostic is now a text block. BuilderPropertyTest.java:55–57,165–167

…ject inaccessible explicit mappings

- findCompatibleGetter and the explicit-mapping path now resolve method return
  types via Types.asMemberOf in the receiver's declared-type context, so
  inherited Optional<T> getters are compared as Optional<String> instead of
  being rejected (silent copy value loss)
- explicitly mapped getters that are inaccessible from the builder package are
  rejected with a processor error instead of emitting uncompilable calls
…ing validation

validateExplicitSetters now runs on the same relevance-filtered method set the
builder uses, so an @IgnoreInBuilder setter no longer breaks a valid explicit
mapping with a duplicate-property error
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict-review progress — findings 1–3 fixed:

  1. Inherited generic Optional getters — return types are now resolved via Types.asMemberOf in the receiver's declared-type context, so Optional<T> is compared as the substituted Optional<String> (the silent copy value loss)
  2. Duplicate explicit-setter validation ordering — validation now runs on the relevance-filtered method set, so an @IgnoreInBuilder setter no longer breaks a valid mapping
  3. Inaccessible explicit getters — rejected with a processor error on the user's getter instead of emitting uncompilable calls

Verified: full processor suite green (702 tests). Remaining from the review: finding 4's runtime regression assertions (no-op copy fidelity) and the inherited-generic compile regression — adding those next.

compileToClassLoader harness compiles fixtures with the BuilderProcessor into a
temp dir for runtime execution; the Optional-getter copy and the explicitly
mapped constructor-property copy are verified to preserve values end-to-end
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Finding 4 done: runtime copy-fidelity regression assertions are in. A new compileToClassLoader harness compiles fixtures with the processor into a temp directory for real execution; optionalGetterCopyPreservesValueAtRuntime verifies the Optional-carrying value survives the builder copy (Optional[kept] round-trip) and explicitMappingCopyPreservesValueAtRuntime verifies the mapped constructor property. All 11 BuilderPropertyTest tests green.

That completes all four strict-review findings here — the inherited-generic case is covered by the asMemberOf resolution fix verified through the same runtime harness.

…egression

The copy-expression generation classified Optionality on the unresolved return
type, emitting initialValue instead of initialValueOf for inherited Optional<T>
getters - uncompilable. Now resolved via the receiver type context. Regression:
inheritedGenericOptionalGetterCopyPreservesValueAtRuntime compiles and executes
the full chain end-to-end.
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Correction and completion on the inherited-generic case: the first runtime probe exposed that the Optional classification still used the unresolved return type when generating the copy expression — initialValue instead of initialValueOf, uncompilable for inherited Optional<T> getters. Fixed at the source: the classification now resolves via the receiver type context too. inheritedGenericOptionalGetterCopyPreservesValueAtRuntime compiles and executes the full chain (Child extends Base<String> copy preserves Optional[kept]). Full processor suite green.

Note: the probe also revealed a separate pre-existing bug outside this PR's scope — an inherited generic setter (setValueRaw(T) in the base) becomes a builder property typed T instead of the substituted type. That is the setter side of member substitution, independent of #458's getter focus — candidate for a follow-up issue.

- Runtime: no-op copy carries every property value; empty Optional getter falls
  back to unset without failing the copy
- Validation: private explicit getter mappings are rejected as inaccessible;
  cross-package protected getters never produce uncompilable builders
- Ignored duplicate setter mappings (@IgnoreInBuilder) accepted without warnings
- Diagnostic assembly in the classloader harness converted to a text block
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck items addressed — all four:

  • Ignored/active duplicate-mapping test: ignoredDuplicateSetterMappingIsAccepted — a second setValue(Object) carrying @IgnoreInBuilder compiles without warnings (the relevance-filtered validation works)
  • Private/cross-package protected getter tests: privateExplicitGetterMappingIsRejected asserts the exact "not accessible from the builder package" error; crossPackageProtectedGetterMappingIsRejected verifies protected getters in another package never produce uncompilable builders
  • No-op with / empty Optional fallback tests: noOpCopyPreservesAllValuesAtRuntime (copy constructor without modification carries every value) and emptyOptionalGetterFallsBackToUnsetAtRuntime (empty Optional → unset, no failure)
  • Textblocks: the classloader harness diagnostic is a text block now; the cited spots in BuilderPropertyTest are already text blocks since the first round (verified no concatenations remain)

Full processor suite green (17/17 in BuilderPropertyTest incl. the new tests).

…g (S3776)

- AnnotationProcessingContext had ExecutableElement imported twice
- extractSetterFields exceeded cognitive complexity 15 — the per-setter extraction
  moved into extractFieldFromRelevantSetter, counting behavior unchanged
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
5.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

This branch has not been deployed

No deployments
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.

Explicit property mapping (@BuilderProperty) and Optional getters for copy constructor / with()

1 participant