[java-inspections] IDEA-357323 Propose case null during adding all cases

GitOrigin-RevId: 6d7ffccc28d64ed0f52db0235c41796d1d81284e
This commit is contained in:
Mikhail Pyltsin
2024-08-09 11:10:54 +02:00
committed by intellij-monorepo-bot
parent 0f5aa949cb
commit cb37003541
14 changed files with 223 additions and 5 deletions

View File

@@ -0,0 +1,20 @@
// "Create missing switch branches with null branch" "true-preview"
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class Test {
public static void main(String[] args) {
test(true);
}
public void test(@Nullable Boolean b) {
switch (b) {
case true -> {
}
case false -> {
}
case null -> {
}
}
}
}

View File

@@ -0,0 +1,15 @@
// "Create missing switch branches with null branch" "true-preview"
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class Test {
public static void main(String[] args) {
test(true);
}
public void test(@Nullable Boolean b) {
switch (b<caret>) {
}
}
}

View File

@@ -0,0 +1,15 @@
// "Create missing switch branches with null branch" "false"
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class Test {
public static void main(String[] args) {
test(true);
}
public void test(@Nullable Boolean b) {
switch (b<caret>) {
case null -> System.out.println();
}
}
}

View File

@@ -0,0 +1,25 @@
// "Create missing switch branches with null branch" "true-preview"
import org.jetbrains.annotations.Nullable;
class Test {
sealed interface SA permits R1, R2 {
}
record R1() implements SA {
}
record R2() implements SA {
}
public void test(@Nullable SA sa) {
switch (sa) {
case R1 r1 -> {
}
case R2 r2 -> {
}
case null -> {
}
}
}
}

View File

@@ -0,0 +1,19 @@
// "Create missing switch branches with null branch" "false"
import org.jetbrains.annotations.NotNull;
class Test {
sealed interface SA permits R1, R2 {
}
record R1() implements SA {
}
record R2() implements SA {
}
public void test(@NotNull SA sa) {
switch (sa<caret>) {
}
}
}

View File

@@ -0,0 +1,19 @@
// "Create missing switch branches with null branch" "true-preview"
import org.jetbrains.annotations.Nullable;
class Test {
sealed interface SA permits R1, R2 {
}
record R1() implements SA {
}
record R2() implements SA {
}
public void test(@Nullable SA sa) {
switch (sa<caret>) {
}
}
}