mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
StreamToLoopInspection: handle some if/ifPresent cases
This commit is contained in:
+3
-3
@@ -6,19 +6,19 @@ import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static void test(List<List<String>> list) {
|
||||
boolean allMatch = true;
|
||||
boolean b = true;
|
||||
OUTER:
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
if (!s.startsWith("a")) {
|
||||
allMatch = false;
|
||||
b = false;
|
||||
break OUTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allMatch) {
|
||||
if(b) {
|
||||
System.out.println("ok");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -5,18 +5,14 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
boolean found = false;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
found = true;
|
||||
System.out.println("Ok!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
for (String str : list) {
|
||||
if (str.contains("x")) {
|
||||
System.out.println(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "syz"));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -13,14 +13,14 @@ public class Main {
|
||||
// cannot replace as replacement would generate a statement before "super" call
|
||||
Child() {
|
||||
super(false);
|
||||
boolean found = false;
|
||||
boolean b = false;
|
||||
for (String s : Arrays.asList("a", "b", "c")) {
|
||||
if (Objects.nonNull(s)) {
|
||||
found = true;
|
||||
b = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
super.test(found);
|
||||
super.test(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
list.stream().filter(str -> str.contains("x")).fin<caret>dFirst().ifPresent(System.out::println);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "syz"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user