From b752e725db1ba4c1d82119f416fde5754d721dd3 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 13 Nov 2023 06:26:39 +0100 Subject: [PATCH] Drop type split "hack" --- .../bugpatterns/CollectorMutability.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java index 235a1d0577e..e3b2c767761 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java @@ -58,7 +58,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (LIST_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( - tree, "com.google.common.collect.ImmutableList.toImmutableList", "ArrayList", state); + tree, + "com.google.common.collect.ImmutableList.toImmutableList", + "java.util.ArrayList", + state); } if (MAP_COLLECTOR.matches(tree, state)) { @@ -67,7 +70,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (SET_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( - tree, "com.google.common.collect.ImmutableSet.toImmutableSet", "HashSet", state); + tree, + "com.google.common.collect.ImmutableSet.toImmutableSet", + "java.util.HashSet", + state); } return Description.NO_MATCH; @@ -75,18 +81,17 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState private Description suggestToCollectionAlternatives( MethodInvocationTree tree, - String fullyQualifiedImmutableReplacement, + String immutableReplacement, String mutableReplacement, VisitorState state) { SuggestedFix.Builder mutableFix = SuggestedFix.builder(); String toCollectionSelect = SuggestedFixes.qualifyStaticImport( "java.util.stream.Collectors.toCollection", mutableFix, state); - String mutableCollection = - SuggestedFixes.qualifyType(state, mutableFix, "java.util." + mutableReplacement); + String mutableCollection = SuggestedFixes.qualifyType(state, mutableFix, mutableReplacement); return buildDescription(tree) - .addFix(replaceMethodInvocation(tree, fullyQualifiedImmutableReplacement, state)) + .addFix(replaceMethodInvocation(tree, immutableReplacement, state)) .addFix( mutableFix .replace(tree, String.format("%s(%s::new)", toCollectionSelect, mutableCollection))