Java: Intention to split switch branch with multiple values into separate branches (IDEA-203895)

This commit is contained in:
Pavel Dolgov
2019-01-30 15:52:26 +03:00
parent 3266673c7f
commit 1bb82a7f5c
39 changed files with 757 additions and 1 deletions
@@ -0,0 +1,14 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 2:
s = "x";
break;
case 1:
s = "x";
break;
}
}
}
@@ -0,0 +1,13 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 2:
s = "x";
break;
case 1:
s = "x";
}
}
}
@@ -0,0 +1,21 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
// 3
case 2: // 4
// 5
s = "x"; // 6
// 7
break; // 8
// 1
case 1: // 2
// 5
s = "x"; // 6
// 7
break; // 8
//9
}
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 2 -> s = "x";
<caret>case 1 -> s = "x";
}
}
}
@@ -0,0 +1,16 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
s = "x";
break;
case 2:
s = "x";
break;
case 4:
s = "y";
}
}
}
@@ -0,0 +1,14 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
s = "x";
break;
case 2:
s = "x";
break;
}
}
}
@@ -0,0 +1,13 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
s = "x";
break;
case 2:
s = "x";
}
}
}
@@ -0,0 +1,21 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
// 1
case 1: // 2
// 5
s = "x"; // 6
// 7
break; // 8
// 3
case 2: // 4
// 5
s = "x"; // 6
// 7
break; // 8
// 9
}
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1 -> s = "x";
<caret>case 2 -> s = "x";
}
}
}
@@ -0,0 +1,12 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1 -> s = "x";
case 2 -> s = "x";
case 3 -> s = "x";
<caret>case 4 -> s = "x";
}
}
}
@@ -0,0 +1,15 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
case 3:
s = "x";
break;
<caret>case 2:
s = "x";
break;
}
}
}
@@ -0,0 +1,17 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
case 3:
s = "x";
break;
<caret>case 2:
s = "x";
break;
case 4:
s = "y";
}
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1 -> s = "x";
<caret>case 2 -> s = "x";
}
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = switch (n) {
case 1 -> "x";
case 2 -> "x";
default -> "";
};
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
/*1*/case /*2*/1/*3*//*4*/ ->/*5*/ s /*6*/= "x";
case 2 -> s /*6*/= "x";/*7*/ //8
}
}
}
@@ -0,0 +1,10 @@
// "Split values of 'switch' rule" "false"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1, 2 -> s = "x";
<caret>default -> s = "";
}
}
}
@@ -0,0 +1,12 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
<caret>case 1:
case 2:
s = "x";
break;
}
}
}
@@ -0,0 +1,13 @@
// "Copy 'switch' branch" "false"
class C {
void foo(int n) {
String s = "";
switch (n) {
<caret>case 1:
case 2:
s = "x";
case 3:
System.out.println(s);
}
}
}
@@ -0,0 +1,11 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
<caret>case 1:
case 2:
s = "x";
}
}
}
@@ -0,0 +1,17 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
// 1
<caret>case 1: // 2
// 3
case 2: // 4
// 5
s = "x"; // 6
// 7
break; // 8
//9
}
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1<caret>, 2 -> s = "x";
}
}
}
@@ -0,0 +1,14 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
<caret>case 2:
s = "x";
break;
case 4:
s = "y";
}
}
}
@@ -0,0 +1,12 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
case 2:<caret>
s = "x";
break;
}
}
}
@@ -0,0 +1,11 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
case 2:<caret>
s = "x";
}
}
}
@@ -0,0 +1,17 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
// 1
case 1: // 2
// 3
case 2:<caret> // 4
// 5
s = "x"; // 6
// 7
break; // 8
// 9
}
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1, 2<caret> -> s = "x";
}
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1, 2, 3, 4 -><caret> s = "x";
}
}
}
@@ -0,0 +1,13 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
<caret>case 2:
case 3:
s = "x";
break;
}
}
}
@@ -0,0 +1,15 @@
// "Copy 'switch' branch" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
case 1:
<caret>case 2:
case 3:
s = "x";
break;
case 4:
s = "y";
}
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
<caret>case 1, 2 -> s = "x";
}
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = switch (n) {
<caret>case 1, 2 -> "x";
default -> "";
};
}
}
@@ -0,0 +1,9 @@
// "Split values of 'switch' rule" "true"
class C {
void foo(int n) {
String s = "";
switch (n) {
/*1*/<caret>case /*2*/1,/*3*/ 2/*4*/ ->/*5*/ s /*6*/= "x";/*7*/ //8
}
}
}