mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-277236 Java 17 support: Conversion from if to switch - misplaced end of line comments and including unrelated return statement in switch.
GitOrigin-RevId: 3bb220692bc9d731f945be76996c314c9ee353f3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f299c8ecd4
commit
74da8644f3
@@ -1147,6 +1147,14 @@ public final class EnhancedSwitchMigrationInspection extends AbstractBaseJavaLoc
|
||||
grabCommentsBeforeColon(label, ct, sb);
|
||||
sb.append("->");
|
||||
sb.append(myRuleResult.generate(ct, this));
|
||||
if (!myUsedElements.isEmpty()) {
|
||||
PsiElement element = PsiTreeUtil.nextCodeLeaf(myUsedElements.get(myUsedElements.size() - 1));
|
||||
if(element instanceof PsiJavaToken javaToken && javaToken.textMatches("}") &&
|
||||
element.getParent() instanceof PsiCodeBlock codeBlock &&
|
||||
codeBlock.getParent() instanceof PsiSwitchBlock) {
|
||||
sb.append(ct.commentsBefore(element));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Comments {
|
||||
String foo(int par) {
|
||||
<caret>return switch (par) {
|
||||
case 11 -> "ciao";/* case 1*/
|
||||
case 14 -> "fourteen";//case 2
|
||||
case 15 -> "fifteen"; //case 3
|
||||
default -> "default";
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Comments {
|
||||
String foo(int par) {
|
||||
i<caret>f(par == 11)
|
||||
return "ciao";/* case 1*/
|
||||
else if(par == 14)
|
||||
return "fourteen";//case 2
|
||||
else if(par == 15)
|
||||
return "fifteen"; //case 3
|
||||
|
||||
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
+1
@@ -30,4 +30,5 @@ public class IfCanBeSwitchSwitchExpressionFixTest extends IGQuickFixesTestCase {
|
||||
|
||||
public void testJava14Expression() { doTest();}
|
||||
public void testJava14Comment() { doTest();}
|
||||
public void testJavaCommentsOutsideLastStatement() { doTest();}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user