Inspection: Expression can be folded into Stream chain (IDEA-187123)

This commit is contained in:
Tagir Valeev
2018-03-05 16:35:35 +07:00
parent 874011da51
commit 2c4af2781d
23 changed files with 382 additions and 32 deletions
@@ -0,0 +1,8 @@
import java.util.stream.Stream;
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return Stream.of(a, b, c, d).allMatch(s -> s.startsWith("xyz"));
}
}
@@ -0,0 +1,8 @@
import java.util.stream.IntStream;
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(double[] arr) {
return IntStream.of(1, 3, 7, 9).allMatch(i -> arr[i] >= 5);
}
}
@@ -0,0 +1,8 @@
import java.util.stream.Stream;
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return Stream.of(a, b, c, d).noneMatch(s -> s.startsWith("xyz"));
}
}
@@ -0,0 +1,9 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
// "Fold expression into Stream chain" "true"
class Test {
String foo(String a, String b, String c, String d) {
return Stream.of(a, b, c, d).map(String::trim).collect(Collectors.joining());
}
}
@@ -0,0 +1,9 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
// "Fold expression into Stream chain" "true"
class Test {
String foo(int a, int b, int c, int d) {
return IntStream.of(a, b, c, d).map(i -> i * 2).mapToObj(String::valueOf).collect(Collectors.joining("|"));
}
}
@@ -0,0 +1,8 @@
import java.util.stream.Stream;
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return Stream.of(a, b, c, d).noneMatch(s -> s.startsWith("xyz"));
}
}
@@ -0,0 +1,8 @@
import java.util.stream.Stream;
// "Fold expression into Stream chain" "true"
class Test {
int foo(String a, String b, String c, String d) {
return Stream.of(a, b, c, d).mapToInt(String::length).sum();
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return a.startsWith("xyz") &<caret>& b.startsWith("xyz") && c.startsWith("xyz") && d.startsWith("xyz");
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(double[] arr) {
return arr[1] >= 5 && arr[3] >= 5 && arr[7] >= 5 && arr[9] <caret>>= 5;
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return !a.startsWith("xyz") &<caret>& !b.startsWith("xyz") && !c.startsWith("xyz") && !d.startsWith("xyz");
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
String foo(String a, String b, String c, String d) {
return a.trim()+b.trim()+c.trim()+<caret>d.trim();
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
String foo(int a, int b, int c, int d) {
return a * 2 + "|" + b * 2 + "|" + c * 2 + "|"<caret> + d * 2;
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
boolean foo(String a, String b, String c, String d) {
return !(a.startsWith("xyz") |<caret>| b.startsWith("xyz") || c.startsWith("xyz") || d.startsWith("xyz"));
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "false"
class Test {
boolean foo(String a, String b, String c, String d) {
return a == null || b == null || c == null || d == <caret>null;
}
}
@@ -0,0 +1,6 @@
// "Fold expression into Stream chain" "true"
class Test {
int foo(String a, String b, String c, String d) {
return a.length()+b.length()+c.length()+<caret>d.length();
}
}