Skip to content

feat(resolver): require no-arg constructor in referenced builder contract - #311

Merged
AndreasIgel merged 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/no-arg-ctor-contract
Oct 1, 2026
Merged

AndreasIgel merged 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/no-arg-ctor-contract

Conversation

@igel-devin-ai

Copy link
Copy Markdown
Collaborator

Issues: closes #308 · sub-task of #301

Summary

Extends the referenced-builder contract in BuilderScopeResolver.resolveByBuilderContract with a no-arg-constructor requirement: ctor(T) + B() + build().

Why

The nested-builder consumer emits new FooBuilder() when the field is unset, but the contract only verified ctor(T) + build() — a hand-written builder without a no-arg ctor passed and produced uncompilable generated code. The check reuses the existing JavaLangAnalyser.hasEmptyConstructor helper and matches the style of the other contract members (presence-based).

Breaking change

Referenced builders that satisfied the previous contract but lack B() stop qualifying; their fields degrade to plain setters (correct output, but observable).

Tests

  • New resolverUsageScope_RejectsBuilderWithoutNoArgConstructor covers the rejection path
  • All existing contract fixtures already declare B() — 469 processor tests green

Notes

  • The check is presence-based like the other contract members (no visibility check) — tightening all three to accessibility-aware checks could be a follow-up.
  • Docs updated in docs/CONFIGURATION.md (builderUsagePackages, builderUsageSuffix).

…ract

The nested-builder consumer emits new FooBuilder() when the field is
unset, but the contract check only verified ctor(T) + build(). A
hand-written builder without a no-arg constructor passed the contract
and produced uncompilable generated code.

The contract now additionally requires a no-arg constructor.
Referenced builders lacking it no longer qualify and their fields
degrade to plain setters (breaking change, resolves java-helpers#308).

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 ec8ae8b into java-helpers:main Oct 1, 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.

Extend minimal builder contract to require empty constructor

2 participants