Skip to content

Model static and final modifiers for fields and nested types - #498

Open
igel-devin-ai wants to merge 13 commits into
java-helpers:mainfrom
igel-devin-ai:devin/495-static-final
Open

igel-devin-ai wants to merge 13 commits into
java-helpers:mainfrom
igel-devin-ai:devin/495-static-final

Conversation

@igel-devin-ai

Copy link
Copy Markdown
Contributor

Fixes #495.

  • ClassFieldDto: staticModifier/finalModifier with builder support (supplier + value variants, copy-constructor tracking) — constants are static+final together, the only legal field kind in interfaces and annotation types
  • NestedTypeDto: staticModifier with builder support — static nested types don't capture the outer instance; ineffective (harmless) inside interfaces/annotation types/records where member types are implicitly static
  • Roaster rendering: setStatic/setFinal on fields; static on nested types via StaticCapableSource
  • Tests: constant rendering (public static final String X = "example"), static and non-static nested types — 26/26 roaster tests green, full reactor 1,262 green

Scope note on validator rules: the issue's record-specific validation (static fields legal in Java but unsupported by Roaster, forge/roaster#279) needs kind-awareness that lands with #492 — it belongs there rather than in this PR since main's validator has no kind concept yet.

…lpers#495)

- ClassFieldDto: staticModifier/finalModifier with builder support —
  constants are static+final together, the only legal field kind in
  interfaces and annotation types
- NestedTypeDto: staticModifier with builder support — static nested
  types no longer capture the outer instance; no effect inside
  interfaces/annotation types/records where member types are
  implicitly static
- Roaster rendering: setStatic/setFinal on fields, static on nested
  types (via StaticCapableSource)
- tests: constant rendering, static and non-static nested types
…extblock tests

- isStatic/isFinal naming aligned with MethodDto (field, setter,
  builder helpers)
- NestedTypeDto: isFinal added end-to-end — final nested types cannot
  be extended
- warning logged when a nested type kind cannot carry static/final
  instead of silently dropping the modifier
- the three new rendering tests compare full generated source
  textblocks
Setting a boolean modifier to true is the dominant use case — the
no-arg variant expresses it directly, and the seldom false case stays
covered by the boolean variant. Applied consistently to
ClassFieldDtoBuilder, NestedTypeDtoBuilder, MethodDtoBuilder and the
processor's BuilderMethodDtoBuilder
@codecov

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

blocking

Reviewed head b4a5242fbe579ae8e6af7ca17be0bda52b5955de against upstream/main 4b696141058c97b8130c3ce3920a7faeafbb3bbd, including issue #495, the PR body, issue comments, and inline review comments. I am not repeating the already-addressed naming, full-source comparison, warning-policy, or dangling-Javadoc discussions. The previously reported Sonar coverage failure is recorded under verification, not counted as a new finding.

  1. blocker — verified — codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodDtoBuilder.java:456–471; processor/src/main/java/org/javahelpers/simple/builders/processor/model/method/BuilderMethodDtoBuilder.java:404–419: existing public supplier overloads are removed. Both isStatic(BooleanSupplier) methods are replaced with no-argument conveniences. Existing callers such as MethodDtoBuilder.create().isStatic(() -> true) and BuilderMethodDtoBuilder.create().isStatic(() -> true) now fail to compile (boolean is not a functional interface); previously compiled callers also lose the corresponding method descriptor. An external client compiled against the unchanged main APIs (using the Fix quality gate on main: test asserts and regex backtracking #500 build, whose method builders are identical to main) with exit 0, and against this head with exit 1, reporting both errors. This is unrelated to adding field/nested-type flags and is avoidable: retain the supplier overloads and add no-arg helpers alongside them. Restore their tests instead of changing supplier calls to boolean calls and deleting their null-supplier assertions (CodegenDtoBuildersTest and ProcessorDtoBuildersTest).

  2. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:418–425; codegen-core/src/main/java/org/javahelpers/codegen/validation/GenerationTargetValidator.java:177–194: interface constants are still neither accepted nor rendered. Issue Model static and final modifiers for fields and nested types #495 explicitly includes interface fields being static-final constants. Building a nested INTERFACE with a public static-final initialized String field reaches the existing validator and fails: Nested interface 'Constants' in test.Target declares fields, but fields on interfaces are implicit constants and cannot be generated as declared. Bypassing validation and invoking Roaster directly produces an empty interface: the renderer only appends fields in its JavaClassSource branch. Deferring record-specific rules until feat: extend type kinds in codegen model — stage 1 (#489) #492 is reasonable, but this interface case already has kind-awareness on main and does not require feat: extend type kinds in codegen model — stage 1 (#489) #492. Update the interface validation and rendering paths to permit legal constants and reject illegal instance fields, with compile-testing coverage. This is an acceptance gap rather than a regression from previously supported interface fields.

  3. minor — verified by diff/test inspection — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:403–411; codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java:870–945: final nested types and new flag copy/default paths lack regression assertions. The three added renderer tests cover one static-final field, one static nested class, and one default non-static nested class. None asserts final nested-class output, so removing the new nested setFinal call would leave those tests green. Existing all-properties copy fixtures were not extended with the new flags either. Add exact whole-source assertions for a final/static-final nested class, independent static/final field states, and true/false/no-op-copy contracts for both DTOs, including restored supplier APIs. My external no-op-copy probe preserves both true flags today; the issue here is protection against reverting the implementation, not a reproduced copy loss.

  4. minor — verified — codegen-core/src/main/java/org/javahelpers/codegen/model/type/NestedTypeDto.java:140–142; codegen-core/src/main/java/org/javahelpers/codegen/model/type/NestedTypeDtoBuilder.java:888–890: the record documentation is incorrect. Ordinary member classes of a record are not implicitly static. A record can declare class Inner { int read() { return value; } } and instantiate it with new RecordOwner(7).new Inner(). That exact example compiled successfully in the Java 17 probe. Remove records from this blanket statement; distinguish a nested record declaration (implicitly static) from a member class declared inside a record. This distinction matters when composing the feature with feat: extend type kinds in codegen model — stage 1 (#489) #492.

  5. nit — verified — codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java:884: the new initializer-source fixture still uses an escaped ordinary string. Express the "example" Java initializer using a text block, trimming its trailing newline if necessary, to meet the requested test-source convention. The three complete generated-source expectations are already text blocks, and no new test-string concatenation was found.

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,378 tests, 0 failures, 0 errors, 0 skipped. Formatting was skipped to keep the review read-only.
  • External probes: existing-API client baseline exit 0, PR-head exit 1 with two supplier-call errors; interface constant validation rejected and direct rendering omitted the field; copied field/nested-type flags remain true/true; record inner-class compilation SUCCESS, errors=0.
  • git_pr_checks: 5 passed, 0 failed, 0 pending. Retrieved JDK 25 job 146010666098 using git_ci_job_logs; Maven reports BUILD SUCCESS. The separately queried Sonar gate remains ERROR, new coverage 59.1% against the 80% threshold, consistent with the existing bot comment.
  • There are no processor-generator implementation changes, so no generated-example regeneration is required by this diff. The method-builder API removal is a hand-maintained API edit, not unavoidable regenerated output.

Other-PR integration review

Read bodies/file lists and ran read-only pairwise merge-tree checks against #430, #480, #482, #483, #484, #492, #497, #499, and #500.

Written by Devin


Recheck at 8af93fb6 (2026-12-06)

Verdict: minor changes

# Original finding (short) Status Remaining action
1 Removed isStatic(BooleanSupplier) APIs accepted as breaking change — announced in #495 Add the breaking-change PR label.
2 Interface constants rejected/omitted fixed —
3 Modifier/copy regression coverage partially fixed — minor Add independent static/final field and true/false/no-op-copy tests (DtoBuilderCopyTest.java:67–77,209–222).
4 Record member classes documented as static not fixed — minor Correct NestedTypeDto.java:140–142 and NestedTypeDtoBuilder.java:888–890.
5 Escaped source fixtures not fixed — nit Use text blocks (RoasterCodeGeneratorTest.java:857,887; GenerationTargetValidatorTest.java:357).

Build: Java 17 module install — BUILD SUCCESS; interface-constant compilation and modifier-copy probes pass.


Recheck at 8770ac39 (2026-12-06)

Verdict: minor changes

Severity What is missing Where (file:line)
note Suggest breaking-change label; supplier removal accepted and announced in #495. MethodDtoBuilder.java:456–471; BuilderMethodDtoBuilder.java:404–419
minor Partial: static-only/final-only field-output assertions still missing; new copy contracts cover true/false. RoasterCodeGeneratorTest.java:876–903; DtoBuilderCopyTest.java:127–168

devin-ai-integration Bot added a commit to igel-devin-ai/simple-builders-devin-fork that referenced this pull request Dec 6, 2026
The validator stays generator-agnostic: other future generators may support
generic records. RoasterCodeGenerator now raises a generation error for
nested records with generic parameters (roaster limitation, forge/roaster#275).
Also drops the isFinal usage in the enum test (modifier modeling belongs to java-helpers#498).
…xt blocks

- Member types of records are NOT implicitly static (verified against javac) —
  the isStatic javadoc wrongly claimed they were; corrected in NestedTypeDto and
  its builder
- Copy regressions: static/final flags survive copy-constructor copies in both
  true and false states, on fields and nested types, incl. no-op copies
- Escaped-quote literal initializers converted to stripped text blocks
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck items addressed:

  • Record-member javadoc corrected: verified against javac — member types of records are NOT implicitly static (a non-static inner class in a record compiles fine), so the isStatic javadoc's claim was wrong for records. Corrected in NestedTypeDto and NestedTypeDtoBuilder
  • Copy tests added: staticFinalFlagsSurviveCopiesInBothStates and staticFinalFlagsSurviveCopiesOnNestedTypes — true/false states and no-op copies through the copy constructor, field-by-field comparison (the DTOs carry no equals)
  • Text-block conversion of the literal initializers is still open

@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck finding 5 done: the escaped literal-initializer fixtures (\"hello\", \"example\", \"hi\") are text blocks now. With the earlier commits (copy regressions, record-member javadoc correction) all review items on this PR are addressed — only the breaking-change label remains, which is on your side.

appendNestedType exceeded cognitive complexity 15 — generics creation and the
static/final capable-source handling are extracted into helpers, behavior unchanged
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

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.

Model static and final modifiers for fields and nested types

3 participants