mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
IDEA-204717 Can't convert enhanced 'switch' to 'if' if a branch's body contains an end-of-line comment
This commit is contained in:
@@ -338,8 +338,13 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
if (bodyStatement instanceof PsiBlockStatement) {
|
||||
final PsiBlockStatement blockStatement = (PsiBlockStatement)bodyStatement;
|
||||
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
|
||||
for (PsiStatement statement : codeBlock.getStatements()) {
|
||||
out.append(commentTracker.text(statement));
|
||||
PsiElement start = PsiTreeUtil.skipWhitespacesForward(codeBlock.getFirstBodyElement());
|
||||
PsiElement end = PsiTreeUtil.skipWhitespacesBackward(codeBlock.getLastBodyElement());
|
||||
if (start != null && end != null) {
|
||||
for (PsiElement child = start; child != null; child = child.getNextSibling()) {
|
||||
out.append(commentTracker.text(child));
|
||||
if (child == end) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class Test {
|
||||
void f(int n, int k) {
|
||||
if (n == 0) {
|
||||
if (k == 0) return; //this comment causes the exception IDEA-204717
|
||||
if (k == 1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class Test {
|
||||
void f(int n, int k) {
|
||||
sw<caret>itch (n) {
|
||||
case 0 -> {
|
||||
if (k == 0) return; //this comment causes the exception IDEA-204717
|
||||
if (k == 1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user