-
Notifications
You must be signed in to change notification settings - Fork 135
Add check replacing stream.sorted().findFirst() with stream.min()
#2555
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
Conversation
Generate changelog in
|
| return Description.NO_MATCH; | ||
| } | ||
|
|
||
| if (Matchers.receiverOfInvocation(STREAM_SORTED_NO_PARAMS_MATCHER).matches(tree, state)) { |
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.
Let's extract the Matchers.receiverOfInvocation( Matcher instances to static fields so they can be reused.
| return describeMatch( | ||
| tree, | ||
| SuggestedFix.builder() | ||
| .replace(tree, state.getSourceForNode(stream) + ".min(Comparator.naturalOrder())") |
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.
it may be slightly cleaner to use an index-based replace call from the beginning of sorted to the end of findFirst. That way we're more likely to preserve comments and such. Doesn't make a great deal of differnce either way though :-]
| state.getSourceForNode(stream) + ".min(" | ||
| + state.getSourceForNode( | ||
| sortedTree.getArguments().get(0)) + ")") | ||
| .addImport(Comparator.class.getCanonicalName()) |
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.
I don't think this addImport is used
|
|
||
| private RefactoringValidator fix() { | ||
| return RefactoringValidator.of(SortedStreamFirstElement.class, getClass()); | ||
| } |
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.
great tests!
…aseline into add-check-sorted-first
carterkozak
left a comment
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.
Looks great, thanks @mpritham!
|
Released 5.11.0 |
Before this PR
As part of this PR, the check to recommend using
stream.min()overstream.sorted().findFirst()was removed. This PR adds an error-prone rule with the same effect.After this PR
==COMMIT_MSG==
Add check replacing
stream.sorted().findFirst()withstream.min()==COMMIT_MSG==