-
Notifications
You must be signed in to change notification settings - Fork 80
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
Rewrite Joiner.on(", ").join("a", "b")
to String.join(", ", "a", "b")
#389
Rewrite Joiner.on(", ").join("a", "b")
to String.join(", ", "a", "b")
#389
Conversation
…b")` Adds a recipe to rewrite calls to Guava Joiner#join with String.join in compatible cases. A call can be re-written if the delimiter is a String, and the arguments are an array, a list or an iterable of items that can be cast to a CharSequence. Addresses openrewrite#318
NOTE: test cases still fail, posting here to get feedback |
While rewrite-templating doesn't support this particular variant yet, a recipe such as this one could likely also be defined using Refaster. |
Sharing the test failures here to save others a click, before I have time to dive in
|
Yes, unfortunately we haven't added support for Refaster's |
@tobli I added a commit to use |
This change should close the type attribution gap for constructor calls: openrewrite/rewrite#3902 |
Thanks for helping out, I'm learning a lot =) |
I just merged openrewrite/rewrite#3902, so when the build is done, I think the tests in here might also pass. As you probably noticed, I changed the code to use |
thanks, I'll study it in more detail. I'll have to dig into the refaster/rewrite code a bit deeper, this is an area where more docs might help. I did see generics in refaster templates weren't supported, would I use something like a |
If I understand the comment in |
I think if your code uses generics you are at the moment out of luck with our Refaster support. Although that is something we would like to address soon. Refaster can be very convenient for simple things. But as soon as you need to add some variation, this declarative approach starts to fall down. But note that Here is an example where a And here is a visitor which uses this to match some input code: https://github.com/openrewrite/rewrite-micrometer/blob/83c4ce67c5c9898dd4ea41018d8a55f307d127e4/src/main/java/org/openrewrite/micrometer/misk/NoExplicitEmptyLabelList.java#L49-L68 |
Just like The idea of |
@tobli Thanks a lot for the contribution! |
Yes thanks! Once deployed on https://app.moderne.io we might want to try it against a couple project there, and if it works well include it in https://github.com/openrewrite/rewrite-migrate-java/blob/main/src/main/resources/META-INF/rewrite/no-guava.yml |
It is doing something: https://app.moderne.io/results/o2zCnjMuC |
I added it to |
What's changed?
Adds a recipe to rewrite calls to Guava Joiner#join with String.join in compatible cases. A call can be re-written if the delimiter is a String, and the arguments are an array, a list or an iterable of items that can be cast to a CharSequence.
What's your motivation?
Addresses #318
Anything in particular you'd like reviewers to focus on?
How to correctly replace the method invocation.
Have you considered any alternatives or workarounds?
I considered Refaster templates, but didn't see a way to narrow down to only the supported call patterns.
Checklist