[IDEA-295460] ConditionalBreak: Handle else & finite loop

GitOrigin-RevId: 51df8f08a54c35043d45f728e80f10f68543feee
This commit is contained in:
Fabrice TIERCELIN
2022-06-28 17:09:51 +02:00
committed by intellij-monorepo-bot
parent a124d59a71
commit d5963c01d2
30 changed files with 470 additions and 63 deletions

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
/*1*/
/*2*/
/*3*/
/*7*/
/*8*/
while (i % 10 != 0 && i < 12) {
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
/*1*/
/*2*/
/*3*/
/*7*/
/*8*/
do {
i =/*5*/ i * 2;/*6*/
/*4*/
} while (i < 12 && i % 10 != 0);
}
}

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
/*1*/
/*2*/
/*3*/
/*7*/
/*8*/
while (i % 10 != 0 && i < 12) {
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,9 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while (i < 12) {
i++;
}
}
}

View File

@@ -0,0 +1,11 @@
// "Move condition to loop" "true"
class Main {
private int variableWithSameName = 1;
public static void main(String[] args) {
int i = 1;
while (i < 100) {
int variableWithAnotherName = -100;
i = i + variableWithSameName;
}
}
}

View File

@@ -0,0 +1,10 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while (i < 14) {
i++;
System.out.println("I'm doing two things in this loop");
}
}
}

View File

@@ -0,0 +1,9 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while (i < 13) {
i++;
}
}
}

View File

@@ -0,0 +1,17 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
boolean isValid = true;
boolean isEnabled = true;
int i = 1;
/*1*/
/*2*/
/*3*/
/*7*/
/*8*/
while (i % 10 != 0 && (!isValid/*9*/ ||/*10*/ !isEnabled)) {
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,17 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
boolean isValid = true;
boolean isEnabled = true;
int i = 1;
/*1*/
/*2*/
/*3*/
/*7*/
/*8*/
while ((isValid || isEnabled) && i < 12) {
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,9 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while (i < 14) {
i++;
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "false"
class Main {
public static void main(String[] args) {
int i = 1;
do<caret> {
if (i < 100) {
break;
} else {
i = i * 3;
}
} while(true);
}
}

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "false"
class Main {
public static void main(String[] args) {
int i = 0;
int j = 0;
annoyingLabel: while(j++ < 100) {
while<caret>(true) {
i++;
if(i < 0) {
break annoyingLabel;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
for<caret>(;i % 10 != 0/*7*/;) /*8*/ {
if(i >= 12/*1*/)/*2*/ break;/*3*/
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,11 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
do {
i =/*5*/ i * 2;/*6*/
/*4*/
if(i >= 12/*1*/)/*2*/ break;/*3*/
} while<caret>(i % 10 != 0/*7*/) /*8*/;
}
}

View File

@@ -0,0 +1,11 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 1;
while<caret>(i % 10 != 0/*7*/) /*8*/ {
if(i >= 12/*1*/)/*2*/ break;/*3*/
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,10 @@
// "Move condition to loop" "false"
class Main {
public static void main(String[] args) {
int i = 1;
do {
if(i > 100) break;
i = i * 2;
} while<caret>(i % 10 != 0);
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
for<caret>(;;) {
if (i >= 12) {
break;
} else {
i++;
}
}
}
}

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "true"
class Main {
private int variableWithSameName = 1;
public static void main(String[] args) {
int i = 1;
while<caret>(true) {
if (i >= 100) {
break;
} else {
int variableWithAnotherName = -100;
}
i = i + variableWithSameName;
}
}
}

View File

@@ -0,0 +1,14 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while<caret>(true) {
if (i < 14) {
i++;
} else {
break;
}
System.out.println("I'm doing two things in this loop");
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
while<caret> (true) {
if (i < 13) {
i++;
} else {
break;
}
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
boolean isValid = true;
boolean isEnabled = true;
int i = 1;
while<caret>(i % 10 != 0/*7*/) /*8*/ {
if(isValid/*9*/ &&/*10*/ isEnabled/*1*/)/*2*/ break;/*3*/
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
boolean isValid = true;
boolean isEnabled = true;
int i = 1;
while<caret>(isValid || isEnabled/*7*/) /*8*/ {
if(i >= 12/*1*/)/*2*/ break;/*3*/
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move condition to loop" "false"
class Main {
public static void main(String[] args) {
boolean isValid = true;
boolean isEnabled = true;
int i = 1;
while<caret>(i % 10 != 0 && i < 100/*7*/) /*8*/ {
if(isValid/*9*/ ||/*10*/ isEnabled/*1*/)/*2*/ break;/*3*/
/*4*/
i =/*5*/ i * 2;/*6*/
}
}
}

View File

@@ -0,0 +1,12 @@
// "Move condition to loop" "true"
class Main {
public static void main(String[] args) {
int i = 0;
for<caret>(;;) {
if (i >= 14)
break;
else
i++;
}
}
}

View File

@@ -0,0 +1,15 @@
// "Move condition to loop" "false"
class Main {
private int variableWithSameName = 1;
public static void main(String[] args) {
int i = 1;
while<caret>(true) {
if (i < 100) {
break;
} else {
int variableWithSameName = -100;
}
i = i + variableWithSameName;
}
}
}

View File

@@ -0,0 +1,10 @@
// "Move condition to loop" "false"
class Main {
public static void main(String[] args) {
int i = 1;
while<caret>(i % 10 != 0) {
i = i * 2;
if(i > 100) break;
}
}
}