Merge branch 'master' of ssh://git.jetbrains.team/ij/intellij

GitOrigin-RevId: 17760d33b233893cb38ef1242a980f79e75bdd34
This commit is contained in:
EgorKulikov
2023-08-11 20:22:31 +02:00
committed by intellij-monorepo-bot
39 changed files with 557 additions and 138 deletions

View File

@@ -0,0 +1,10 @@
class SkipSwitchExpressionWithThrow {
static boolean test(int x) {
return switch (x) {
case 404 -> false;
case 401 -> throw new RuntimeException();
case 403 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}
}

View File

@@ -0,0 +1,15 @@
// "Replace with old style 'switch' statement" "true"
class SwitchExpressionMigration {
boolean toBoolean(int value) {
switch (value) {
//t1
case 0://t2
return false;
//t3
default://t4
System.out.println("1");
return true;
}
}
}

View File

@@ -3,8 +3,9 @@ import java.util.*;
class SwitchExpressionMigration {
private static void m(int x) {
/*1*//*3*//*4*//*6*//*7*//*8*//*18*//*2*/
switch (x +/*5*/ x) {/*14*//*9*//*11*/
/*1*//*3*//*4*//*6*//*7*//*2*/
switch (x +/*5*/ x) {
/*8*//*14*//*9*//*11*/
case 1 +/*10*/ 1:
if (true /*12*/)
/*13*/ return 0;
@@ -18,7 +19,7 @@ class SwitchExpressionMigration {
case 4 /*in2*/ + 33:
System.out.println("asda");
return 3;
/*19*/
/*18*//*19*/
default:
return 12 /*20*/ + 12;
}

View File

@@ -3,12 +3,13 @@ import java.util.*;
class SwitchExpressionMigration {
private static String m(int n) {
/*1*/
/*3*/
switch (n +/*cond*/ n) {/*case*/
switch (n +/*cond*/ n) {
/*1*/
/*case*/
case 1:
System.out.println("a"/*2*/);
break;
/*3*/
case 2:
System.out.println("b");
break;

View File

@@ -8,7 +8,8 @@ class SwitchExpressionMigration {
/*2*/
/*3*/
int x;
switch (x +/*cond*/ x) {/*5*/
switch (x +/*cond*/ x) {
/*5*/
case 1:
if (true) {
x = 0;

View File

@@ -3,9 +3,8 @@ import java.util.*;
public class GenerateThrow {
void foo(int i) {
// convert to 'old style' switch
int res;
switch (i) {
switch (i) { // convert to 'old style' switch
case 0:
res = 1;
break;

View File

@@ -0,0 +1,19 @@
// "Replace with old style 'switch' statement" "true"
class SwitchExpressionMigration {
boolean toBoolean(int value) {
return switch<caret> (value) {
//t1
case 0 -> {
//t2
yield false;
}
//t3
default -> {
//t4
System.out.println("1");
yield true;
}
};
}
}

View File

@@ -66,6 +66,8 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
public void testNewStringWrongEquals() { doTest(); }
public void testSkipSwitchExpressionWithThrow() { doTest(); }
public void testStringTemplates() {
myFixture.addClass("""
package java.lang;