If I read this correctly, what you're asking for is an overloaded method in a generated builder. So, instead of generating, say:
PersonBuilder address(Address address) { this.address = address; return this; }
we generate that AND In addition, ALSO:
PersonBuilder address(Address.AddressBuilder addressBuilder) {this.address = address.build(); return this; }
and for singulars, a similar approach.
What we can do is something like:
@Builder @Value
public class Person {
@CombineBuilder Address address;
}
which would presume the 'standard' strategy for naming the builder (which depends first on an explicit parameter in @Builder, then on lombok.config, and finally _TypeName_Builder). Alternatively:
@Builder @Value
public class Person {
@CombineBuilder(AddressBuilder.class) Address address;
}
but note that when you use the name 'combine builder' I'm thinking about taking the individual bits of Address and adding those straight in. So, assuming AddressBuilder has a .street() method, that person itself gets .street, so that you can do:
Person.builder()
.name("Jane Abrahamson") // this ends up setting a field in Person
.street("Main Street") // this ends up being passed into the address builder
.build()
and doing that would be impossible without either [A] reflection or [B] a requirement that the Address class is in the same source file as the Person class so that we can introspect on it during compilation phase without requiring resolution trickery.
So.. given that I really don't want to waste the combine name on this.... anyone have a good idea about a name? More generally does this feature stand any chance? I don't think 'we complicate the lombok side of things both in our implementation and our manuals and learning curve, and all you get in return is that you can omit build() calls' is worth it in the first place. Now, that combining builder notion, maybe that's got legs, but implementing that is really hard due to requiring either resolution or unacceptably tight limits like 'all relevant classes must be in the same source file'.
So, sounds like a non-starter but perhaps I'm missing some tricks to make this simpler.