ImmutableListRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$).* as compiler argument.

Table of contents
  1. ImmutableListBuilder
  2. IterableToImmutableList
  3. StreamToImmutableList
  4. ImmutableListSortedCopyOf
  5. ImmutableListSortedCopyOfWithCustomComparator
  6. StreamToDistinctImmutableList
  7. ImmutableListOf
  8. ImmutableListOf1
  9. ImmutableListOf2
  10. ImmutableListOf3
  11. ImmutableListOf4
  12. ImmutableListOf5

ImmutableListBuilder

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListBuilder") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListBuilder).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableList.Builder<String> testImmutableListBuilder() {
-  return new ImmutableList.Builder<>();
+  return ImmutableList.builder();
 }

IterableToImmutableList

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("IterableToImmutableList") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$IterableToImmutableList).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<ImmutableList<Integer>> testIterableToImmutableList() {
   return ImmutableSet.of(
-      ImmutableList.of(1).stream().collect(toImmutableList()),
-      Streams.stream(ImmutableList.of(2)::iterator).collect(toImmutableList()),
-      Streams.stream(ImmutableList.of(3).iterator()).collect(toImmutableList()),
-      ImmutableList.<Integer>builder().addAll(ImmutableList.of(4)).build(),
-      ImmutableList.<Integer>builder().addAll(ImmutableList.of(5)::iterator).build(),
-      ImmutableList.<Integer>builder().addAll(ImmutableList.of(6).iterator()).build(),
-      ImmutableList.<Integer>builder().add(new Integer[] {7}).build(),
-      Arrays.stream(new Integer[] {8}).collect(toImmutableList()));
+      ImmutableList.copyOf(ImmutableList.of(1)),
+      ImmutableList.copyOf(ImmutableList.of(2)::iterator),
+      ImmutableList.copyOf(ImmutableList.of(3).iterator()),
+      ImmutableList.copyOf(ImmutableList.of(4)),
+      ImmutableList.copyOf(ImmutableList.of(5)::iterator),
+      ImmutableList.copyOf(ImmutableList.of(6).iterator()),
+      ImmutableList.copyOf(new Integer[] {7}),
+      ImmutableList.copyOf(new Integer[] {8}));
 }

StreamToImmutableList

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("StreamToImmutableList") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$StreamToImmutableList).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableList<Integer> testStreamToImmutableList() {
-  return ImmutableList.copyOf(Stream.of(1).iterator());
+  return Stream.of(1).collect(toImmutableList());
 }

ImmutableListSortedCopyOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListSortedCopyOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
   return ImmutableSet.of(
-      ImmutableList.sortedCopyOf(naturalOrder(), ImmutableSet.of(1)),
-      ImmutableSet.of(2).stream().sorted().collect(toImmutableList()),
-      Streams.stream(ImmutableSet.of(3)::iterator).sorted().collect(toImmutableList()));
+      ImmutableList.sortedCopyOf(ImmutableSet.of(1)),
+      ImmutableList.sortedCopyOf(ImmutableSet.of(2)),
+      ImmutableList.sortedCopyOf(ImmutableSet.of(3)::iterator));
 }

ImmutableListSortedCopyOfWithCustomComparator

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListSortedCopyOfWithCustomComparator") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListSortedCopyOfWithCustomComparator).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<ImmutableList<String>> testImmutableListSortedCopyOfWithCustomComparator() {
   return ImmutableSet.of(
-      ImmutableSet.of("foo").stream()
-          .sorted(Comparator.comparing(String::length))
-          .collect(toImmutableList()),
-      Streams.stream(ImmutableSet.of("bar")::iterator)
-          .sorted(Comparator.comparing(String::isEmpty))
-          .collect(toImmutableList()));
+      ImmutableList.sortedCopyOf(Comparator.comparing(String::length), ImmutableSet.of("foo")),
+      ImmutableList.sortedCopyOf(
+          Comparator.comparing(String::isEmpty), ImmutableSet.of("bar")::iterator));
 }

StreamToDistinctImmutableList

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("StreamToDistinctImmutableList") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$StreamToDistinctImmutableList).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableList<Integer> testStreamToDistinctImmutableList() {
-  return Stream.of(1).distinct().collect(toImmutableList());
+  return Stream.of(1).collect(toImmutableSet()).asList();
 }

ImmutableListOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<List<Integer>> testImmutableListOf() {
   return ImmutableSet.of(
-      ImmutableList.<Integer>builder().build(),
-      Stream.<Integer>empty().collect(toImmutableList()),
-      Collections.<Integer>emptyList(),
-      List.<Integer>of());
+      ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of());
 }

ImmutableListOf1

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf1") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf1).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<List<Integer>> testImmutableListOf1() {
-  return ImmutableSet.of(Collections.singletonList(1), List.of(1));
+  return ImmutableSet.of(ImmutableList.of(1), ImmutableList.of(1));
 }

ImmutableListOf2

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf2") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf2).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 List<Integer> testImmutableListOf2() {
-  return List.of(1, 2);
+  return ImmutableList.of(1, 2);
 }

ImmutableListOf3

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf3") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf3).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 List<Integer> testImmutableListOf3() {
-  return List.of(1, 2, 3);
+  return ImmutableList.of(1, 2, 3);
 }

ImmutableListOf4

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf4") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf4).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 List<Integer> testImmutableListOf4() {
-  return List.of(1, 2, 3, 4);
+  return ImmutableList.of(1, 2, 3, 4);
 }

ImmutableListOf5

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableListOf5") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!ImmutableListRules\$ImmutableListOf5).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 List<Integer> testImmutableListOf5() {
-  return List.of(1, 2, 3, 4, 5);
+  return ImmutableList.of(1, 2, 3, 4, 5);
 }

Copyright © 2017-2024 Picnic Technologies BV