Skip to content

Detect build function by signature, not by name, in referenced-builder contract #319

Description

@igel-devin-ai

Sub-task of #301.

Goal

In the contract check for referenced builders (JavaLangAnalyser.hasBuildMethodReturning, called from BuilderScopeResolver.resolveByBuilderContract), detect the build function by signature instead of by name: any public, non-static, parameterless method whose return type is the referenced type T counts — regardless of whether it is named build().

Why

The contract should verify capability, not a naming convention. MapStruct-style and hand-written builders may name the terminal method differently (toTarget(), assemble(), …); a literal build() check rejects builders that would otherwise satisfy the contract. It also aligns the resolver with SimpleBuildersBuilderProvider.findBuildMethods, which already matches build methods by signature (public, non-static, no params, return type == T).

Pitfall

Needs an java.lang.Object-method guard (e.g. toString()): without it, StringBuilder.toString() + StringBuilder(String) satisfy the contract for String — the exact false positive the check is meant to prevent.

Status

Implemented in #320, which closes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions