AssortedRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. CheckIndexExpression
  2. CheckIndexBlock
  3. IteratorsGetNext
  4. Or
  5. StreamGenerate
  6. IterablesIsEmpty
  7. SplitterSplitToStream

CheckIndexExpression

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 int testCheckIndexExpression() {
-  return Preconditions.checkElementIndex(0, 1);
+  return checkIndex(0, 1);
 }

CheckIndexBlock

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testCheckIndexBlock() {
-  if (1 < 0 || 1 >= 2) {
-    throw new IndexOutOfBoundsException();
-  }
+  checkIndex(1, 2);
 }

IteratorsGetNext

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<String> testIteratorsGetNext() {
   return ImmutableSet.of(
-      ImmutableList.of("a").iterator().hasNext()
-          ? ImmutableList.of("a").iterator().next()
-          : "foo",
-      Streams.stream(ImmutableList.of("b").iterator()).findFirst().orElse("bar"),
-      Streams.stream(ImmutableList.of("c").iterator()).findAny().orElse("baz"));
+      Iterators.getNext(ImmutableList.of("a").iterator(), "foo"),
+      Iterators.getNext(ImmutableList.of("b").iterator(), "bar"),
+      Iterators.getNext(ImmutableList.of("c").iterator(), "baz"));
 }

Or

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Boolean> testOr() {
   return ImmutableSet.of(
-      toString().isEmpty() || (!toString().isEmpty() && Boolean.TRUE),
+      toString().isEmpty() || Boolean.TRUE,
       !toString().isEmpty() || (toString().isEmpty() && Boolean.TRUE),
       3 < 4 || (3 >= 4 && Boolean.TRUE),
       3 >= 4 || (3 < 4 && Boolean.TRUE));
 }

StreamGenerate

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 Stream<String> testStreamGenerate() {
-  return Streams.stream(Iterables.cycle("foo"));
+  return Stream.generate(() -> "foo");
 }

IterablesIsEmpty

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 boolean testIterablesIsEmpty() {
-  return !ImmutableList.of().iterator().hasNext();
+  return Iterables.isEmpty(ImmutableList.of());
 }

SplitterSplitToStream

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<Stream<String>> testSplitterSplitToStream() {
   return ImmutableSet.of(
-      Streams.stream(Splitter.on(':').split("foo")),
-      Splitter.on(',').splitToList(new StringBuilder("bar")).stream());
+      Splitter.on(':').splitToStream("foo"),
+      Splitter.on(',').splitToStream(new StringBuilder("bar")));
 }

Copyright © 2017-2026 Picnic Technologies BV