Skip to content

Resolve builders anchored inside the referenced type (#317) - #318

Merged
AndreasIgel merged 12 commits into
java-helpers:mainfrom
igel-devin-ai:devin/in-type-builder-lookup
Oct 3, 2026
Merged

AndreasIgel merged 12 commits into
java-helpers:mainfrom
igel-devin-ai:devin/in-type-builder-lookup

Conversation

@igel-devin-ai

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

Copy link
Copy Markdown
Contributor

Closes #317 — sub-task of #301.

Summary

Adds builder lookup anchored inside the referenced type itself (Lombok/Immutables/FreeBuilder shapes), before the same-package candidate lookup:

  • Nested types first: accessible nested types are checked against the full builder contract — Person.PersonBuilder/Person.Builder ranked before other nested names (Lombok vs FreeBuilder conventions).
  • Anchored static factories: accessible static parameterless methods on the type returning a declared type; builder() ranks first. The factory IS the empty-instantiation path — the return type only needs an accessible no-arg build() returning T (MapStruct's DefaultBuilderProvider semantics), so Lombok builders with package-private ctors qualify.
  • Seeded paths (in order): the builder's own contract path (ctor(T)/of(T)), a static builder(T)-style method on the type, or an instance method on the value like toBuilder() (Lombok toBuilder=true, AutoValue).
  • Two new BuilderInstantiation kinds: AnchorFactoryCall(anchor, method) renders T.m(args)/T::m; ValueFactoryCall(anchor, method) renders value.m()/T::m for toBuilder().
  • JavaLangAnalyser: findMethods/findMethodsStatic overloads returning List<ExecutableElement>; JavaLangMapper.mapToTypeName now keeps the enclosing name for nested types (lib.Person.PersonBuilder).

Tests

5 resolver tests: nested-type contract builder, anchored builder() in another package, contract-rejecting anchor falls through, builder()-name preference, toBuilder() seeded path. 479 processor tests green; generated example output unchanged.

Docs: class javadoc resolution-order list and CONFIGURATION.md updated.

@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 b36d4b4 into java-helpers:main Oct 3, 2026
5 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.

Find builders anchored inside the referenced type

3 participants