StreamToLoopInspection: unwrap && and || chains; copy return statement in found/not found places; do not eagerly evaluate non-trivial ternary branch

This commit is contained in:
Tagir Valeev
2016-12-27 12:38:05 +07:00
parent eb1eb4de75
commit fb12495825
11 changed files with 154 additions and 19 deletions
@@ -0,0 +1,15 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
for (String s : list) {
if (s.isEmpty()) {
return list.stream().anyMatch(Objects::isNull);
}
}
return false;
}
}
@@ -0,0 +1,17 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
boolean x = false;
for (String s : list) {
if (s.isEmpty()) {
x = list.stream().anyMatch(Objects::isNull);
break;
}
}
return x;
}
}
@@ -0,0 +1,18 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
boolean b = true;
for (String s : list) {
if (s.isEmpty()) {
b = false;
break;
}
}
boolean x = b && list.stream().anyMatch(Objects::isNull) && list.size() > 2;
return x;
}
}
@@ -0,0 +1,15 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
for (String s : list) {
if (s.isEmpty()) {
return false;
}
}
return list.stream().anyMatch(Objects::isNull);
}
}
@@ -6,14 +6,12 @@ import java.util.Optional;
public class Main {
private static test(List<String> packages) {
Optional<String> found = Optional.empty();
for (String s : packages) {
if (s.startsWith("xyz")) {
found = Optional.of(s);
break;
return Optional.of(s).filter(pkg -> pkg.endsWith("abc")).isPresent();
}
}
return found.filter(pkg -> pkg.endsWith("abc")).isPresent();
return Optional.<String>empty().filter(pkg -> pkg.endsWith("abc")).isPresent();
}
public static void main(String[] args) {
@@ -0,0 +1,10 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
return list.stream().<caret>anyMatch(String::isEmpty) && list.stream().anyMatch(Objects::isNull);
}
}
@@ -0,0 +1,11 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
boolean x = list.stream().<caret>anyMatch(String::isEmpty) && list.stream().anyMatch(Objects::isNull);
return x;
}
}
@@ -0,0 +1,11 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
boolean x = !list.stream().<caret>anyMatch(String::isEmpty) && list.stream().anyMatch(Objects::isNull) && list.size() > 2;
return x;
}
}
@@ -0,0 +1,10 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
public boolean testCond(List<String> list) {
return !list.stream().<caret>anyMatch(String::isEmpty) && list.stream().anyMatch(Objects::isNull);
}
}