-
Notifications
You must be signed in to change notification settings - Fork 79
ReplaceCollectToListWithToList #558
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
ReplaceCollectToListWithToList #558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 660-659
- lines 705-721
- lines 1254-1273
- lines 1306-1305
- lines 2337-2336
- lines 2352-2364
- lines 2801-2800
- lines 2820-2831
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that this code change is not semantically the same. The stream.collect(Collectors.toList())
returns a mutable list, while stream.toList()
returns an immutable collection.
So this cannot be applied blindly using a recipe imho.
on greenfield yes, to ensure https://adabeat.com/fp/immutability-in-functional-programming/ for legacy, or valid exceptions, like maven we need suppression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
yes we can: make change and wrap in Then we have same API, but no new violations following: https://kyleshevlin.com/just-enough-fp-immutability/ |
return method.getArguments().get(0) instanceof J.MethodInvocation && | ||
((J.MethodInvocation) method.getArguments().get(0)).getSimpleName().equals("toList") && | ||
((J.MethodInvocation) method.getArguments().get(0)).getSelect() != null && | ||
((J.MethodInvocation) method.getArguments().get(0)).getSelect().toString().equals("Collectors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would fail to pick up static imports of toList
. Wherever possible prefer to use MethodMatchers as opposed to looking at simple names, as that avoids these pitfalls.
src/test/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToListTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToList.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToList.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToListTest.java
Outdated
Show resolved
Hide resolved
…istWithToList.java Co-authored-by: Tim te Beek <[email protected]>
…istWithToList.java Co-authored-by: Tim te Beek <[email protected]>
…istWithToListTest.java Co-authored-by: Tim te Beek <[email protected]>
…istWithToListTest.java Co-authored-by: Tim te Beek <[email protected]>
recent discovery seems fishy -
then |
I've spoken at length with the author linked above at Code Remix Summit last week, helped him understand and analyze the changes, and got him set up to continue his work. Despite this he came out with a deeply flawed analysis and false statements, which unfortunately are being taken at face value. Figured I'd provide some more context about the changes made from our perspective: You're all welcome to use and contribute to OpenRewrite for as much as you'd like; we see no reason to be hesitant at all, but understand opinions may differ. |
rewrite-maven-plugin
: Introduce OpenRewrite by Moderne apache/maven#2322FYI: @gnodet @elharo
need suppression support for old API then we can fix it
once
. @timtebeek