mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
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:
+15
@@ -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;
|
||||
}
|
||||
}
|
||||
+17
@@ -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;
|
||||
}
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
+15
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -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) {
|
||||
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user