-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Builder/SuperBuilder setterPrefix
configurable from lombok.config
#3159
Comments
We won't do this. The reason we offered it in the first place is if you're making a builder that needs to fit specific needs, e.g. because it has to implement an interface or you're using it with some backwards library that expects silly defaults. Specifically, We like the java community and wouldn't want to make it worse by introducing pointless customization options like that. |
@rzwitserloot this would be very helpful though. The overarching idea behind Lombok is to reduce boilerplate and noise in code, isn't it? So now needing to add a specific param by in each every I appreciate your great input into java community but your position in which you think you know better what application, code style, or any other issue anyone may face or need is not very considerate, is it? Here's an use case in which Lombok's default builder name convention doesn't work very well. Prod code in Java @Builder
record Something(@NonNull NonBlankString foo, @NonNull NonNegativeInteger bar) {} Test fixture DSL in Groovy class SomethingDsl {
@Delegate
private final SomethingBuilder builder = Something.builder()
static Something anySomething(@DelegatesTo(SomethingDsl) Closure overrides = {}) {
new SomethingDsl().with {
foo 'foo-1'
bar 3
with overrides
build()
}
// convenience setters to improve SNR further on the use side
void foo(String value) {
foo new NonBlankString(value)
}
void bar(Integer value) {
bar new NonNegativeInteger(value)
}
} Test code in Spock given:
def foo = 'the-foo'
when:
def something = anySomething { // statically imported from SomethingDsl
foo foo // here is the problem where the name of local variable clashes with the default setter name so this doesn't work
}
then:
// whatever the assertion If the DSL's underlying builder had any setter prefix, the clash wouldn't happen, i.e. given:
def foo = 'the-foo'
when:
def something = anySomething { // statically imported from SomethingDsl
withFoo foo // here is the problem where the name of local variable clashes with the default setter name so this doesn't work
}
then:
// whatever the assertion I've been now going through multiple in our organization (some quite large) for a couple of years to ensure that explicit A global configuration option would really save a lot of otherwise unnecessarily wasted time, effort and noise in code 🙏 |
As there is the
@Builder(setterPrefix = "...")
option, it would make sense to have the ability of setting it once across the project at thelombok.config
.An example would be using
lombok.builder.setterPrefix = set
to have a project-wide prefixset
for bean-like builder access.For consistency, the config value should be used as default value by
@SuperBuilder
as well, just likelombok.builder.className
is used by@SuperBuilder
already.Justification:
BTW this feature request somewhat follows #2849, to have a project wide consistent config for (very) often used lombok features.
The text was updated successfully, but these errors were encountered: