Skip to content
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

Replace lombok.val with final var on projects using Java 11 or higher #124

Merged
merged 1 commit into from
Sep 9, 2022
Merged

Replace lombok.val with final var on projects using Java 11 or higher #124

merged 1 commit into from
Sep 9, 2022

Conversation

timtebeek
Copy link
Contributor

@timtebeek timtebeek commented Sep 4, 2022

Figured this would be a fun one, and learning exercise. It replaces lombok.val with final var, as there's not a lot of value in retaining lombok.val nowadays. As a bonus it makes projects more compatible with OpenRewrite, at least until there's integrated support.

Only thing that I'm not yet sure how to resolve is the tests containing infix whitespace & comment. Some guidance there would be appreciated once again. My attempts at using maybeAutoFormat failed up to now.

Fixes projectlombok/lombok#3207
Fixes openrewrite/rewrite#1297

TODO

  • Reference from META-INF yaml
  • Either fix or ignore infix whitespace & comments

@timtebeek
Copy link
Contributor Author

Wasn't entirely sure whether this recipe would fit in best here or in openrewrite/rewrite. My guess was here as it's most applicable for users upgrading between Java versions.

@pway99 pway99 self-requested a review September 9, 2022 15:48
@pway99
Copy link
Contributor

pway99 commented Sep 9, 2022

Thanks Tim!

The recipe should also account for the case where lombok.val types are used in for-each statements

List<String> lst = new ArrayList<>();
for (val s : lst) {}

If you would like, I've got your PR loaded up and am happy to help with these changes :)

@timtebeek
Copy link
Contributor Author

If you would like, I've got your PR loaded up and am happy to help with these changes :)

Yes please! Just arrived in Stavanger, so won't get to it myself otherwise for another week. Feel free to change it however you feel is best!

@pway99
Copy link
Contributor

pway99 commented Sep 9, 2022

Well, It turns out the changes were not that simple after all... I discovered a Javatemplate BlockStamentGenerator bug which was preventing for-each loop transformations. I'll add some changes to your PR and merge them in after PR is merged.

@pway99 pway99 merged commit 1ff7d8d into openrewrite:main Sep 9, 2022
@pway99
Copy link
Contributor

pway99 commented Sep 9, 2022

Hi Tim, I've managed to get this merged in and will test it on the SaaS if everything looks good I will add a reference to the appropriate META-INF yaml file. Thanks again for your help on this one :)

@timtebeek timtebeek deleted the lombok.val_to_final_var branch September 10, 2022 04:47
@timtebeek
Copy link
Contributor Author

Thanks for the fixes & merge! The bug in JavaTemplateBlockStatementGenerator would have surely tripped me up, so I'm glad you were able to dive into this one. Curious to hear what effects you see on SaaS! :)

@pway99 pway99 added this to the 1.11.0 milestone Sep 14, 2022
@tkvangorder tkvangorder added the recipe Recipe requested label Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[FEATURE] Replace lombok.val with final var in source code Support Lombok Annotations
3 participants