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

[FEATURE] Replace lombok.val with final var in source code #3207

Closed
timtebeek opened this issue Jun 2, 2022 · 2 comments · Fixed by openrewrite/rewrite-migrate-java#124
Closed

Comments

@timtebeek
Copy link

Describe the feature
As discussed here, it would be nice to either have a new command valToVar or mode of delombok to replace existing usage of lombok.val with final var in the source code. This is intended to move away from lombok.val specifically, leaving all other code, comments and lombok features intact.

public String example() {
-   val example = new ArrayList<String>();
+   final var example = new ArrayList<String>();
    example.add("Hello, World!");
-   val foo = example.get(0);
+   final var foo = example.get(0);
    return foo.toLowerCase();
}

Describe the target audience
Anyone using Java 10/11+, and looking to move away from lombok.val specifically, towards final var, while leaving all other usage of lombok features intact.

Additional context
lombok.val was added to reduce boilerplate, and up to Java 10 that was indeed true. With the arrival of final var there is less of a need to use lombok.val, and it can be troublesome for other tools to work with.

To keep things simple support could be limited to Java 11+; that way there's no need to replace val with the actual type on Java 8.

At present delombok produces the code to a separate target folder; instructions can be provided to move the altered files back into the source folder to complete the phase out of lombok.val. Even better if replacement could be done in place, but that's optional.

@timtebeek
Copy link
Author

@rzwitserloot from an end user perspective this has been covered through a new OpenRewrite recipe. The documentation is not yet up, but is it's now possible to phase out lombok.val with their Maven or Gradle plugin.

Question then becomes what you want to do with the issue on this project. You can for instance refer to the implementation at OpenRewrite from the lombok documentation, or keep this issue open if you still plan to implement this yourselves. Either approach could open the door to eventual deprecation (with optional removal), if that's the way you want to go.

@timtebeek
Copy link
Author

Unlikely to be picked up here; users interested in this change can execute this recipe:
https://docs.openrewrite.org/recipes/java/migrate/lombok/lombokvaltofinalvar

Closing issue.

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 a pull request may close this issue.

1 participant