mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
[java-intentions] IDEA-313226. Suggest the correct type for switch
GitOrigin-RevId: bd99d2b31049b94542a1745f48a33d0ee787e83d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf8ce55c6b
commit
938ed3204b
@@ -0,0 +1,18 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
import static A.Month.APRIL;
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
Month x2;
|
||||
var x = switch (x2)
|
||||
{
|
||||
case APRIL ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
enum Month{APRIL, MAY};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
int x2;
|
||||
var x = switch (x2)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
Integer x2;
|
||||
var x = switch (x2)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
case null -> "null";
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
String testPattern() {
|
||||
BaseInterface x2;
|
||||
return switch(x2){
|
||||
case BaseInterface.Record1 record1 -> "1";
|
||||
case BaseInterface.Record2 record1 -> "1";
|
||||
default -> "2";
|
||||
};
|
||||
}
|
||||
|
||||
sealed interface BaseInterface permits BaseInterface.Record1, BaseInterface.Record2 {
|
||||
|
||||
sealed class Record1() implements BaseInterface {
|
||||
}
|
||||
|
||||
record Record2() implements BaseInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
String x2;
|
||||
var x = switch (x2)
|
||||
{
|
||||
case "bar" ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
import static A.Month.APRIL;
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
var x = switch (x2<caret>)
|
||||
{
|
||||
case APRIL ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
enum Month{APRIL, MAY};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
var x = switch (x2<caret>)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
var x = switch (x2<caret>)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
case null -> "null";
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
String testPattern() {
|
||||
return switch(x2<caret>){
|
||||
case BaseInterface.Record1 record1 -> "1";
|
||||
case BaseInterface.Record2 record1 -> "1";
|
||||
default -> "2";
|
||||
};
|
||||
}
|
||||
|
||||
sealed interface BaseInterface permits BaseInterface.Record1, BaseInterface.Record2 {
|
||||
|
||||
sealed class Record1() implements BaseInterface {
|
||||
}
|
||||
|
||||
record Record2() implements BaseInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Create local variable 'x2'" "true-preview"
|
||||
|
||||
class A {
|
||||
public void foo() {
|
||||
var x = switch (x2<caret>)
|
||||
{
|
||||
case "bar" ->
|
||||
{
|
||||
yield "bar";
|
||||
}
|
||||
default -> "foo";
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user