mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
switch -> if: fix comments line breaks (IDEA-195383)
This commit is contained in:
+11
-5
@@ -280,6 +280,8 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
out.append(variable.getType().getCanonicalText()).append(' ').append(variable.getName()).append(';');
|
||||
}
|
||||
}
|
||||
|
||||
boolean addLineBreak = true;
|
||||
for (PsiElement bodyStatement : bodyStatements) {
|
||||
if (bodyStatement instanceof PsiBlockStatement) {
|
||||
final PsiBlockStatement blockStatement = (PsiBlockStatement)bodyStatement;
|
||||
@@ -289,21 +291,25 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
}
|
||||
}
|
||||
else {
|
||||
appendElement(bodyStatement, out, commentTracker);
|
||||
addLineBreak = appendElement(bodyStatement, out, commentTracker);
|
||||
}
|
||||
}
|
||||
out.append("\n}");
|
||||
if (addLineBreak) {
|
||||
out.append("\n");
|
||||
}
|
||||
out.append("}");
|
||||
}
|
||||
|
||||
private static void appendElement(PsiElement element, @NonNls StringBuilder out, CommentTracker commentTracker) {
|
||||
if (element instanceof PsiWhiteSpace) return;
|
||||
private static boolean appendElement(PsiElement element, @NonNls StringBuilder out, CommentTracker commentTracker) {
|
||||
if (element instanceof PsiBreakStatement) {
|
||||
final PsiBreakStatement breakStatement = (PsiBreakStatement)element;
|
||||
final PsiIdentifier identifier = breakStatement.getLabelIdentifier();
|
||||
if (identifier == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
out.append(commentTracker.text(element));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void test(int i) {
|
||||
if (i == 1) {//foo
|
||||
if (Math.random() > 0.5) {
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace 'switch' with 'if'" "true"
|
||||
class X {
|
||||
void test(int i) {
|
||||
<caret>switch (i) {
|
||||
case 1:
|
||||
//foo
|
||||
if (Math.random() > 0.5) {
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user