Skip to content

Conversation

Mahmoud-Khawaja
Copy link

Description

This PR introduces the lombok.builder.toBuilder configuration key, allowing toBuilder() to be enabled globally for all @Builder annotations via lombok.config. If not explicitly set in the annotation, the configuration value is applied (default: false).

Changes

  • Added BUILDER_TO_BUILDER key in ConfigurationKeys.java.
  • Integrated config key handling in HandleBuilder.java.
  • Ensured explicit annotation settings override configuration values.

This provides more flexibility in testing and code generation.
Fixes #3758.

@Mahmoud-Khawaja Mahmoud-Khawaja changed the title Add lombok.builder.toBuilder configuration key to enable toBuilder by… Add Configuration Key lombok.builder.toBuilder (Fixes #3758) Feb 5, 2025
@rzwitserloot
Copy link
Collaborator

I'm not entirely sure lombok.config is the right place for this sort of thing. Config is always fighting with itself: On one hand, lombok never was intended to be silent magic - the source file on its own without knowing what lombok.config contains ought to be enough to at least guesstimate what's happening.

Then again, your class still has @Builder on it; it should therefore be somewhat obvious where toBuilder() is coming from.

I'll discuss this one with @rspilker before merging.

One consideration fighting against this, @Mahmoud-Khawaja, is OpenJDK's plans for with. It might be limited to records (all the more reason to use toBuilder() more!), but it would look something like:

LocalDate x = fetchSomeLocalDate();
LocalDate y = x with {
  year = 10;
  month = 12;
};

If that was part of OpenJDK, it reduces the boilerplate considerations (the 'bang' part of the 'bang for the buck' equation that lombok features have to balance out).

@rzwitserloot
Copy link
Collaborator

Talked it over with @rspilker ; we're going to accept this.

@rzwitserloot
Copy link
Collaborator

Reviewed the code:

  • The merge conflict is trivial; master now has a new config key added at the end. The order between yours and the new one is not important.
  • Your one commit contains the update, but no docs (that's allright, we can write them), no tests (acceptable, we'll write them), and a whole boatload of weird docker stuff. That has to go.
  • Please add your name to the AUTHORS file for legal reasons.

If you could add the name to this PR we can accept it. And we'd take it as a kindness if you rebase it, remove the docker stuff.

@Mahmoud-Khawaja
Copy link
Author

done, thanks!

@cruftex
Copy link

cruftex commented Jul 18, 2025

ChatGPT is telling me already that the option is existing, but it seems the PR is still in progress. It would be great to have it included.

@Mahmoud-Khawaja
Can you please check your PR and clean it? Please check the changed files to contain only the intended changes. There is docker and Gradle things that that are unrelated. I think its best to squash in to a single commit and then force push.

@rzwitserloot
Copy link
Collaborator

@cruftex Just a life tip: "ChatGPT told me X" means nothing. LLM output has potentially useful creative value and totally, utterly pointless truth value.

@rzwitserloot rzwitserloot added this to the next-next-version milestone Sep 4, 2025
@rzwitserloot rzwitserloot modified the milestones: v1.18.42, next-version Sep 18, 2025
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.

[FEATURE] Add configuration key lombok.builder.toBuilder
3 participants