Skip to content

Commit 6623320

Browse files
refactor: Static imports for Collections and Collectors (#804)
Use this link to re-run the recipe: https://app.moderne.io/builder/m9HsHwu2Z?organizationId=ODQ2MGExMTUtNDg0My00N2EwLTgzMGMtNGE1NGExMTBmZDkw Co-authored-by: Moderne <[email protected]>
1 parent c0c5d56 commit 6623320

File tree

45 files changed

+144
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+144
-100
lines changed

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaAtomicsNewReference.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaAtomicsNewReference extends Recipe {
3233
private static final MethodMatcher NEW_ATOMIC_REFERENCE = new MethodMatcher("com.google.common.util.concurrent.Atomics newReference(..)");
3334

@@ -43,7 +44,7 @@ public String getDescription() {
4344

4445
@Override
4546
public Set<String> getTags() {
46-
return Collections.singleton("guava");
47+
return singleton("guava");
4748
}
4849

4950
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaDirectExecutor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaDirectExecutor extends Recipe {
3233
private static final MethodMatcher DIRECT_EXECUTOR = new MethodMatcher("com.google.common.util.concurrent.MoreExecutors directExecutor()");
3334

@@ -43,7 +44,7 @@ public String getDescription() {
4344

4445
@Override
4546
public Set<String> getTags() {
46-
return Collections.singleton("guava");
47+
return singleton("guava");
4748
}
4849

4950
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewArrayList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import org.openrewrite.java.tree.J;
2727
import org.openrewrite.java.tree.TypeUtils;
2828

29-
import java.util.Collections;
3029
import java.util.Set;
3130

31+
import static java.util.Collections.singleton;
32+
3233
public class NoGuavaListsNewArrayList extends Recipe {
3334
private static final MethodMatcher NEW_ARRAY_LIST = new MethodMatcher("com.google.common.collect.Lists newArrayList()");
3435
private static final MethodMatcher NEW_ARRAY_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newArrayList(java.lang.Iterable)");
@@ -46,7 +47,7 @@ public String getDescription() {
4647

4748
@Override
4849
public Set<String> getTags() {
49-
return Collections.singleton("guava");
50+
return singleton("guava");
5051
}
5152

5253
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewCopyOnWriteArrayList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import org.openrewrite.java.tree.J;
2727
import org.openrewrite.java.tree.TypeUtils;
2828

29-
import java.util.Collections;
3029
import java.util.Set;
3130

31+
import static java.util.Collections.singleton;
32+
3233
public class NoGuavaListsNewCopyOnWriteArrayList extends Recipe {
3334
private static final MethodMatcher NEW_ARRAY_LIST = new MethodMatcher("com.google.common.collect.Lists newCopyOnWriteArrayList()");
3435
private static final MethodMatcher NEW_ARRAY_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newCopyOnWriteArrayList(java.lang.Iterable)");
@@ -45,7 +46,7 @@ public String getDescription() {
4546

4647
@Override
4748
public Set<String> getTags() {
48-
return Collections.singleton("guava");
49+
return singleton("guava");
4950
}
5051

5152
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewLinkedList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import org.openrewrite.java.tree.J;
2727
import org.openrewrite.java.tree.TypeUtils;
2828

29-
import java.util.Collections;
3029
import java.util.Set;
3130

31+
import static java.util.Collections.singleton;
32+
3233
public class NoGuavaListsNewLinkedList extends Recipe {
3334
private static final MethodMatcher NEW_LINKED_LIST = new MethodMatcher("com.google.common.collect.Lists newLinkedList()");
3435
private static final MethodMatcher NEW_LINKED_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newLinkedList(java.lang.Iterable)");
@@ -45,7 +46,7 @@ public String getDescription() {
4546

4647
@Override
4748
public Set<String> getTags() {
48-
return Collections.singleton("guava");
49+
return singleton("guava");
4950
}
5051

5152
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaMapsNewHashMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaMapsNewHashMap extends Recipe {
3233
private static final MethodMatcher NEW_HASH_MAP = new MethodMatcher("com.google.common.collect.Maps newHashMap()");
3334
private static final MethodMatcher NEW_HASH_MAP_WITH_MAP = new MethodMatcher("com.google.common.collect.Maps newHashMap(java.util.Map)");
@@ -44,7 +45,7 @@ public String getDescription() {
4445

4546
@Override
4647
public Set<String> getTags() {
47-
return Collections.singleton("guava");
48+
return singleton("guava");
4849
}
4950

5051
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaMapsNewLinkedHashMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaMapsNewLinkedHashMap extends Recipe {
3233
private static final MethodMatcher NEW_LINKED_HASH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap()");
3334
private static final MethodMatcher NEW_LINKED_HASH_MAP_WITH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap(java.util.Map)");
@@ -44,7 +45,7 @@ public String getDescription() {
4445

4546
@Override
4647
public Set<String> getTags() {
47-
return Collections.singleton("guava");
48+
return singleton("guava");
4849
}
4950

5051
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaMapsNewTreeMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaMapsNewTreeMap extends Recipe {
3233
private static final MethodMatcher NEW_TREE_MAP = new MethodMatcher("com.google.common.collect.Maps newTreeMap()");
3334
private static final MethodMatcher NEW_TREE_MAP_WITH_COMPARATOR = new MethodMatcher("com.google.common.collect.Maps newTreeMap(java.util.Comparator)");
@@ -45,7 +46,7 @@ public String getDescription() {
4546

4647
@Override
4748
public Set<String> getTags() {
48-
return Collections.singleton("guava");
49+
return singleton("guava");
4950
}
5051

5152
@Override

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaPrimitiveAsList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
28+
import static java.util.Collections.nCopies;
2929

3030
public class NoGuavaPrimitiveAsList extends Recipe {
3131

@@ -59,7 +59,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation elem, Executi
5959
maybeRemoveImport("com.google.common.primitives.Bytes");
6060
maybeAddImport("java.util.Arrays");
6161

62-
String args = String.join(",", Collections.nCopies(elem.getArguments().size(), "#{any()}"));
62+
String args = String.join(",", nCopies(elem.getArguments().size(), "#{any()}"));
6363
return JavaTemplate
6464
.builder("Arrays.asList(" + args + ')')
6565
.imports("java.util.Arrays")

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaSetsNewConcurrentHashSet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import org.openrewrite.java.search.UsesMethod;
2626
import org.openrewrite.java.tree.J;
2727

28-
import java.util.Collections;
2928
import java.util.Set;
3029

30+
import static java.util.Collections.singleton;
31+
3132
public class NoGuavaSetsNewConcurrentHashSet extends Recipe {
3233
private static final MethodMatcher NEW_HASH_SET = new MethodMatcher("com.google.common.collect.Sets newConcurrentHashSet()");
3334

@@ -43,7 +44,7 @@ public String getDescription() {
4344

4445
@Override
4546
public Set<String> getTags() {
46-
return Collections.singleton("guava");
47+
return singleton("guava");
4748
}
4849

4950
@Override

0 commit comments

Comments
 (0)