mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EnhancedSwitchMigrationInspection: do not create block when single statement in branch: IDEA-CR-40190
This commit is contained in:
@@ -503,6 +503,9 @@ public class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLocalInsp
|
||||
|
||||
@Override
|
||||
public String generate(CommentTracker ct) {
|
||||
if (myResultStatements.length == 1) {
|
||||
return ct.text(myResultStatements[0]);
|
||||
}
|
||||
return StreamEx.of(myResultStatements).map(stmt -> ct.text(stmt)).joining("\n", "{\n", "}");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-6
@@ -5,12 +5,8 @@ class SwitchExpressionMigration {
|
||||
private static String m(int n) {
|
||||
switch (n) {
|
||||
/*1*/
|
||||
case 1 -> {
|
||||
System.out.println("a"/*2*/); /*3*/
|
||||
}
|
||||
case 2 -> {
|
||||
System.out.println("b");
|
||||
}
|
||||
case 1 -> System.out.println("a"/*2*/); /*3*/
|
||||
case 2 -> System.out.println("b");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -4,12 +4,8 @@ import java.util.*;
|
||||
class SwitchExpressionMigration {
|
||||
private static String m(int n) {
|
||||
switch (n) {
|
||||
case 1 -> {
|
||||
return "a";
|
||||
}
|
||||
case 2 -> {
|
||||
return "b";
|
||||
}
|
||||
case 1 -> return "a";
|
||||
case 2 -> return "b";
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with enhanced 'switch' statement" "true"
|
||||
import java.util.*;
|
||||
|
||||
class SwitchExpressionMigration {
|
||||
private static int m(int x) {
|
||||
switch (x) {
|
||||
case 1 -> {
|
||||
if (true) return 0;
|
||||
else return 1;
|
||||
}
|
||||
case 2 -> return 2;
|
||||
case 3, 4 -> {
|
||||
System.out.println("asda");
|
||||
return 3;
|
||||
}
|
||||
default -> return 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-9
@@ -4,15 +4,9 @@ import java.util.*;
|
||||
class SwitchExpressionMigration {
|
||||
private static String m(int n) {
|
||||
switch (n) {
|
||||
case 3, 1 -> {
|
||||
System.out.println("a");
|
||||
}
|
||||
case 5, 6, 7 -> {
|
||||
System.out.println("a");
|
||||
}
|
||||
case 2, 4 -> {
|
||||
System.out.println("b");
|
||||
}
|
||||
case 3, 1 -> System.out.println("a");
|
||||
case 5, 6, 7 -> System.out.println("a");
|
||||
case 2, 4 -> System.out.println("b");
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace with enhanced 'switch' statement" "true"
|
||||
import java.util.*;
|
||||
|
||||
class SwitchExpressionMigration {
|
||||
private static int m(int x) {
|
||||
switch<caret> (x) {
|
||||
case 1: {
|
||||
if (true) return 0;
|
||||
else return 1;
|
||||
}
|
||||
case 2:
|
||||
return 2;
|
||||
case 3, 4: {
|
||||
System.out.println("asda");
|
||||
return 3;
|
||||
}
|
||||
default:
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user