Hello,
I would like to customize the visibility of the method that gives an instance of the Builder class when using the @Builder annotation. Right now it is only possible to make the method public.
It is possible to achieve this by defining the method manually as in the following example, but this makes the code confusing.
I would be willing to make a Pull Request for this with a little guidance on how to start (I already found the class lombok.javac.handles.HandleBuilder, and the builder annotation itself, but I'm not sure if there are other modifications to make except docs and tests).
Example :
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
public class OmniContext {
private final String brand;
private final String country;
// This method is already created by the @Builder annotation but we redefine it here to make it package private.
static OmniContextBuilder builder() {
return new OmniContextBuilder();
}
}
I would like to be able to do this :
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PACKAGE)
public class OmniContext {
private final String brand;
private final String country;
}
This feature would also be useful when manually implementing another static builder method. For instance, when you have a required non-null field in your class and want to create the builder instance directly with MyClass.builder("requiredField").
I find it also very important, lets say I want to limit the builder to package level and I only use all args constructors. This means in current implementation I have to implmenet almost all of the builder process just to do it. otherwise builder opens up the class instanciation to the world!
+1
It should be useful to implement a public build() method that invokes the private generated build method generated by Lombok and implements a custom logic validation for the fields set.
what's the current status of this feature ?
Most helpful comment
This feature would also be useful when manually implementing another static builder method. For instance, when you have a required non-null field in your class and want to create the builder instance directly with
MyClass.builder("requiredField").