Java: Add code block and break-with-value when wrapping result expression of a switch expression (IDEA-204012)

This commit is contained in:
Pavel Dolgov
2019-01-21 17:58:22 +03:00
parent cf0248d263
commit 89bebb048d
40 changed files with 434 additions and 27 deletions
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>{ break "a"; }</selection>
default -> "";
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
if () {
break "a";
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>"a".substring(1);</selection>
default -> "";
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
if () {
break "a".substring(1);
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> /*0*/<selection>/*1*/"a" +/*2*/ "b"/*3*/;</selection>/*4*/
default -> "";
};
}
}
@@ -0,0 +1,13 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> /*0*/{
synchronized () {
/*1*/
"a" +/*2*/ "b"/*3*/;
}
}/*4*/
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>throw new RuntimeException();</selection>
default -> "";
};
}
}
@@ -0,0 +1,10 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
throw new RuntimeException();
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>throw new RuntimeException();</selection>
default -> "";
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
if () {
throw new RuntimeException();
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> /*0*/<selection>/*1*/throw new /*2*/RuntimeException("a")/*3*/;</selection>/*4*/
default -> "";
};
}
}
@@ -0,0 +1,15 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> /*0*/{
try {
/*1*/
throw new /*2*/RuntimeException("a")/*3*/;/*4*/
} catch (RuntimeException e) {
e.printStackTrace();
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>{ break "a"; }</selection>
default -> "";
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
for () {
break "a";
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> <selection>"a".substring(1);</selection>
default -> "";
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> {
for () {
"a".substring(1);
}
}
default -> "";
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> <selection>{ break "a".substring(1); }</selection>;
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> {
do {
break "a".substring(1);
} while (true);
};
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> /*0*/<selection>{/*1*/break /*2*/"a";/*3*/}</selection>/*4*/
};
}
}
@@ -0,0 +1,15 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> /*0*/{
try {
/*1*/
break /*2*/"a";/*3*/
} finally {
<caret>
}
}/*4*/
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> /*0*/<selection>/*1*/"a" + "b"/*2*/;</selection>/*3*/
};
}
}
@@ -0,0 +1,15 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> /*0*/{
Runnable runnable = new Runnable() {
public void run() {
/*1*/
"a" + "b"/*2*/;
}
};
}/*3*/
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> <selection>"a" + "b";</selection>;
};
}
}
@@ -0,0 +1,16 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> {
try {
break "a" + "b";
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
;
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> <selection>"a" + "b";</selection>
};
}
}
@@ -0,0 +1,12 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> {
while (true) {
"a" + "b";
}
}
};
}
}
@@ -0,0 +1,8 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> <selection>throw new RuntimeException("a");</selection>
};
}
}
@@ -0,0 +1,13 @@
class C {
void test(int n) {
String s = switch (n) {
case 1 -> "";
default -> {
if () {
throw new RuntimeException("a");
} else {
}
}
};
}
}