-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce MapIsEmpty
Refaster rule
#339
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.
Nice! Will do a more thorough review later :)
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java
Outdated
Show resolved
Hide resolved
b6732fa
to
ff9415d
Compare
0b38be5
to
02397eb
Compare
ff9415d
to
0647b3e
Compare
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.
Added a commit.
Suggested commit message:
Prefer `Map#isEmpty()` over `Map#{keySet,values,entrySet}.isEmpty()` (#339)
(Not sure how to chain method calls with the #
...)
Alternative would be:
Introduce `MapIsEmpty` Refaster rule (#339)
One last thing to consider, we could sort the keySet
, values
and entrySet
lexicographically but I think this order also makes sense 🤔.
@@ -44,4 +44,15 @@ Stream<String> testMapKeyStream() { | |||
Stream<Integer> testMapValueStream() { | |||
return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue); | |||
} | |||
|
|||
Stream<boolean> testMapIsEmpty() { |
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 wasn't flagged because of a tiny line of code missing in the base PR 😬. Will drop this method :).
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.
Thanks, overlooked that
Yeah I was thinking of ordering it lexicographically, but I wanted to stick with the order Stephan already proposed in the other rule |
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.
W.r.t. ordering: it seems we often order by some fuzzy "frequency" metric. 🤷
Added one commit; don't ask me to exactly explain this ordering; also just following some existing fuzzy logic 😬. (Eventually we'll auto-sort this stuff.)
I think Introduce `MapIsEmpty` Refaster rule (#339)
matches what we've done before 👍
e05e367
to
973446e
Compare
Rebased |
map.keySet().isEmpty()
to map.isEmpty()
MapIsEmpty
Refaster rule
Adds an additional refaster Map rule that builts on #337
Suggested commit message: