16
16
package com .google .errorprone .bugpatterns ;
17
17
18
18
import static com .google .errorprone .BugPattern .SeverityLevel .WARNING ;
19
+ import static com .google .errorprone .matchers .Description .NO_MATCH ;
20
+ import static java .util .stream .Collectors .groupingBy ;
19
21
20
22
import com .google .common .collect .ImmutableSet ;
23
+ import com .google .common .collect .Sets ;
21
24
import com .google .errorprone .BugPattern ;
22
25
import com .google .errorprone .VisitorState ;
23
26
import com .google .errorprone .bugpatterns .BugChecker .MethodInvocationTreeMatcher ;
@@ -38,7 +41,7 @@ public class MultipleUnaryOperatorsInMethodCall extends BugChecker
38
41
implements MethodInvocationTreeMatcher {
39
42
40
43
private static final ImmutableSet <Kind > UNARY_OPERATORS =
41
- ImmutableSet . of (
44
+ Sets . immutableEnumSet (
42
45
Kind .POSTFIX_DECREMENT ,
43
46
Kind .POSTFIX_INCREMENT ,
44
47
Kind .PREFIX_DECREMENT ,
@@ -47,16 +50,16 @@ public class MultipleUnaryOperatorsInMethodCall extends BugChecker
47
50
@ Override
48
51
public Description matchMethodInvocation (
49
52
MethodInvocationTree methodInvocationTree , VisitorState visitorState ) {
50
-
51
53
if (methodInvocationTree .getArguments ().stream ()
52
54
.filter (arg -> UNARY_OPERATORS .contains (arg .getKind ()))
53
55
.map (arg -> ASTHelpers .getSymbol (((UnaryTree ) arg ).getExpression ()))
54
- .collect (Collectors .groupingBy (Function .identity (), Collectors .counting ()))
56
+ .filter (sym -> sym != null )
57
+ .collect (groupingBy (Function .identity (), Collectors .counting ()))
55
58
.entrySet ()
56
59
.stream ()
57
60
.anyMatch (e -> e .getValue () > 1 )) {
58
61
return describeMatch (methodInvocationTree );
59
62
}
60
- return Description . NO_MATCH ;
63
+ return NO_MATCH ;
61
64
}
62
65
}
0 commit comments