From e5c8d06b3bfb8bfa2bfa34eeb581722f0a21961c Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 18 Apr 2023 10:54:40 +0200 Subject: [PATCH] Address feedback --- .../bugpatterns/AssociativeMethodInvocation.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java index 1b2691f29c..40259d7d15 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java @@ -10,7 +10,7 @@ import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -39,7 +39,7 @@ @AutoService(BugChecker.class) @BugPattern( summary = - "These methods implement an associative operation, so you can flatten the list of operands", + "These methods implement an associative operation, so the list of operands can be flattened", link = BUG_PATTERNS_BASE_URL + "AssociativeMethodInvocation", linkType = CUSTOM, severity = SUGGESTION, @@ -48,8 +48,8 @@ public final class AssociativeMethodInvocation extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Supplier ITERABLE = Suppliers.typeFromClass(Iterable.class); - private static final ImmutableList> ASSOCIATIVE_OPERATIONS = - ImmutableList.of( + private static final ImmutableSet> ASSOCIATIVE_OPERATIONS = + ImmutableSet.of( allOf( staticMethod().onClass(Suppliers.typeFromClass(Matchers.class)).named("allOf"), toType(MethodInvocationTree.class, not(hasArgumentOfType(ITERABLE)))), @@ -63,6 +63,11 @@ public AssociativeMethodInvocation() {} @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (tree.getArguments().isEmpty()) { + /* Absent any arguments, there is nothing to simplify. */ + return Description.NO_MATCH; + } + for (Matcher matcher : ASSOCIATIVE_OPERATIONS) { if (matcher.matches(tree, state)) { SuggestedFix.Builder fix = SuggestedFix.builder();