From 7748f2a1ae79f9caae717a388aa90323172ab19b Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 10 Apr 2022 11:56:15 +0200 Subject: [PATCH] Suggestion --- .../bugpatterns/StaticImportCheck.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java index dcf1483624a..09108229fb4 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImportCheck.java @@ -72,6 +72,7 @@ public final class StaticImportCheck extends BugChecker implements MemberSelectT "com.mongodb.client.model.Sorts", "com.mongodb.client.model.Updates", "java.nio.charset.StandardCharsets", + "java.util.Collections", "java.util.Comparator", "java.util.Map.Entry", "java.util.stream.Collectors", @@ -119,26 +120,6 @@ public final class StaticImportCheck extends BugChecker implements MemberSelectT .put("com.google.common.collect.ImmutableTable", "toImmutableTable") .put("com.google.common.collect.Sets", "toImmutableEnumSet") .put("com.google.common.base.Functions", "identity") - .putAll( - "java.util.Collections", - "disjoint", - "emptyList", - "emptyMap", - "emptySet", - "reverse", - "singleton", - "singletonList", - "singletonMap", - "synchronizedCollection", - "synchronizedList", - "synchronizedMap", - "synchronizedNavigableMap", - "synchronizedSet", - "unmodifiableCollection", - "unmodifiableList", - "unmodifiableMap", - "unmodifiableNavigableSet", - "unmodifiableSet") .put("java.util.function.Function", "identity") .put("java.util.function.Predicate", "not") .put("org.junit.jupiter.params.provider.Arguments", "arguments") @@ -159,10 +140,25 @@ public final class StaticImportCheck extends BugChecker implements MemberSelectT *

Identifiers listed by {@link #STATIC_IMPORT_EXEMPTED_IDENTIFIERS} should be omitted from * this collection. */ + // XXX: Perhaps the set of exempted `java.util.Collections` methods is too strict. For now any + // method name that could be considered "too vague" or could conceivably mean something else in a + // specific context is left out. @VisibleForTesting static final ImmutableSetMultimap STATIC_IMPORT_EXEMPTED_MEMBERS = ImmutableSetMultimap.builder() .put("com.mongodb.client.model.Filters", "empty") + .putAll( + "java.util.Collections", + "addAll", + "copy", + "fill", + "list", + "max", + "min", + "nCopies", + "rotate", + "sort", + "swap") .put("org.springframework.http.MediaType", "ALL") .build();