mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-03 03:37:58 +07:00
IDEA-199811 RefactoringUtil#ensureCodeBlock: support while conditions; support && chains in if-then and while
This commit is contained in:
@@ -1,18 +1,45 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
for (String s : list) {
|
||||
if (s != null) {
|
||||
if (s.startsWith("x")) {
|
||||
System.out.println("Ok!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(list.size() > 2) {
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
System.out.println("Ok!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(list.size() > 2) {
|
||||
boolean b = false;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
b = list.size() < 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
}
|
||||
if(list.size() > 2 || list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x"))) { // not supported
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
while(true) {
|
||||
boolean b = true;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
b = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b) break;
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test2(List<String> list) {
|
||||
while(list.size() > 2) {
|
||||
boolean b = true;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
b = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b) break;
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test3(List<String> list) {
|
||||
while(true) {
|
||||
boolean b = false;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
b = list.size() > 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(b)) break;
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4(List<String> list) {
|
||||
while(list.size() > 2) {
|
||||
long count = 0L;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(count > 10 && list.size() < 10)) break;
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
native List<String> process(List<String> list);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -8,6 +8,15 @@ public class Main {
|
||||
if(list.stream().filter(x -> x != null).an<caret>yMatch(x -> x.startsWith("x"))) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
if(list.size() > 2 && list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x"))) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
if(list.size() > 2 && list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x")) && list.size() < 10) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
if(list.size() > 2 || list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x"))) { // not supported
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
while(list.stream().filter(x -> x != null).an<caret>yMatch(x -> x.startsWith("x"))) {
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test2(List<String> list) {
|
||||
while(list.size() > 2 && list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x"))) {
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test3(List<String> list) {
|
||||
while(list.stream().filter(x -> x != null).anyMatch(x -> x.startsWith("x")) && list.size() > 2) {
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test4(List<String> list) {
|
||||
while(list.size() > 2 && list.stream().filter(x -> x != null).filter(x -> x.startsWith("x")).count() > 10 && list.size() < 10) {
|
||||
list = process(list);
|
||||
}
|
||||
}
|
||||
|
||||
native List<String> process(List<String> list);
|
||||
}
|
||||
Reference in New Issue
Block a user