RefactoringUtil#ensureCodeBlock: support &&-chains in returns/lambdas (IDEA-199811)

Also implementation extracted to package-private class
This commit is contained in:
Tagir Valeev
2018-10-03 13:46:47 +07:00
parent 485e950c2c
commit f12b4848c6
5 changed files with 300 additions and 183 deletions
@@ -0,0 +1,39 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.function.*;
import java.util.*;
public class Main {
void test(List<String> list) {
if (list.size() <= 2) return false;
for (String s : list) {
if (s.isEmpty()) {
return true;
}
}
return false;
}
void test2(List<String> list) {
if (list.size() <= 2) return false;
for (String s : list) {
if (s.isEmpty()) {
return true;
}
}
return list.size() < 10;
}
Predicate<List<String>> testLambda() {
return list -> {
if (list.size() <= 2) return false;
long count = 0L;
for (String s : list) {
if (s.isEmpty()) {
count++;
}
}
return count > 2;
};
}
}
@@ -0,0 +1,21 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.function.*;
import java.util.*;
public class Main {
void test(List<String> list) {
return list.size() > 2 &&
list.stream().an<caret>yMatch(s -> s.isEmpty());
}
void test2(List<String> list) {
return list.size() > 2 &&
(list.stream().anyMatch(s -> s.isEmpty()) || list.size() < 10);
}
Predicate<List<String>> testLambda() {
return list -> list.size() > 2 &&
list.stream().filter(s -> s.isEmpty()).count() > 2;
}
}