[java-inspections] IDEA-312411 convert to switch and collapse everything into default branch. More tests

GitOrigin-RevId: ecc51cbb4012c96d898aa4418c1b039e0cf38bc7
This commit is contained in:
Mikhail Pyltsin
2023-02-10 15:46:58 +00:00
committed by intellij-monorepo-bot
parent e892a152bc
commit 3860147ce0
10 changed files with 120 additions and 0 deletions
@@ -0,0 +1,18 @@
// "Replace with 'switch' expression" "true-preview"
class ThroughUntilDefaultReturn {
static enum Letter {
A,
B,
C,
D
}
private static int test(Letter letter) {
return switch (letter) {
case A -> 1;
default -> 2;
};
}
}
@@ -0,0 +1,18 @@
// "Replace with 'switch' expression" "true-preview"
class ThroughUntilDefaultaAssignment {
static enum Letter {
A,
B,
C,
D
}
private static void test(Letter letter) {
int i = switch (letter) {
case A -> 2;
default -> 3;
};
}
}
@@ -0,0 +1,18 @@
// "Replace with enhanced 'switch' statement" "true-preview"
class ThroughUntilDefaultaAssignment {
static enum Letter {
A,
B,
C,
D
}
private static void test(Letter letter) {
switch (letter) {
case A -> System.out.println("1");
default -> System.out.println(2);
}
}
}
@@ -0,0 +1,23 @@
// "Replace with 'switch' expression" "true-preview"
class ThroughUntilDefaultaAssignment {
static enum Letter {
A,
B,
C,
D
}
private static void test(Letter letter) {
int i = 1;
switch<caret> (letter) {
case A:
i = 2;
break;
default:
case B:
i = 3;
}
}
}
@@ -0,0 +1,21 @@
// "Replace with 'switch' expression" "true-preview"
class ThroughUntilDefaultReturn {
static enum Letter {
A,
B,
C,
D
}
private static int test(Letter letter) {
switch<caret> (letter) {
case A:
return 1;
default:
case B:
return 2;
}
}
}
@@ -0,0 +1,22 @@
// "Replace with enhanced 'switch' statement" "true-preview"
class ThroughUntilDefaultaAssignment {
static enum Letter {
A,
B,
C,
D
}
private static void test(Letter letter) {
switch<caret> (letter) {
case A:
System.out.println("1");
break;
default:
case B:
System.out.println(2);
}
}
}