mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
SplitConditionUtil#createAndAnd: fix corner cases with ending line comment
Review ID: IDEA-CR-31527
This commit is contained in:
@@ -126,7 +126,7 @@ public class SplitConditionUtil {
|
||||
PsiExpression nextCondition = PsiUtil.skipParenthesizedExprDown(nextIf.getCondition());
|
||||
if (nextCondition == null) break;
|
||||
if (PsiEquivalenceUtil.areElementsEquivalent(extract, nextCondition) && nextIf.getThenBranch() != null) {
|
||||
elseChain.add(nextIf.getThenBranch().getText());
|
||||
elseChain.add(tracker.text(nextIf.getThenBranch()));
|
||||
chainFinished = true;
|
||||
}
|
||||
else {
|
||||
@@ -160,7 +160,7 @@ public class SplitConditionUtil {
|
||||
thenString = createIfString(leave, thenBranch, (String)null, tracker);
|
||||
}
|
||||
else {
|
||||
thenString = "{" + createIfString(leave, thenBranch, String.join(" else ", elseChain), tracker) + "}";
|
||||
thenString = "{" + createIfString(leave, thenBranch, String.join("\nelse ", elseChain), tracker) + "\n}";
|
||||
}
|
||||
String ifString = createIfString(extract, thenString, elseBranch, tracker);
|
||||
return (PsiIfStatement)factory.createStatementFromText(ifString, thenBranch);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class C {
|
||||
void foo() {
|
||||
if (a) {
|
||||
if (b) {
|
||||
call();
|
||||
} // foo
|
||||
else if (c) {
|
||||
otherCall();
|
||||
} // bar
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class C {
|
||||
void foo() {
|
||||
if (a) {
|
||||
if (b) {
|
||||
call();
|
||||
} // foo
|
||||
else if (c) {
|
||||
otherCall();
|
||||
} // bar
|
||||
else {
|
||||
thirdCall();
|
||||
} // baz
|
||||
} else {
|
||||
fourthCall();
|
||||
} // qux
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class C {
|
||||
void foo() {
|
||||
if (a &<caret>& b) {
|
||||
call();
|
||||
} // foo
|
||||
else if (a && c) {
|
||||
otherCall();
|
||||
} // bar
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class C {
|
||||
void foo() {
|
||||
if (a &<caret>& b) {
|
||||
call();
|
||||
} // foo
|
||||
else if (a && c) {
|
||||
otherCall();
|
||||
} // bar
|
||||
else if(a) {
|
||||
thirdCall();
|
||||
} // baz
|
||||
else {
|
||||
fourthCall();
|
||||
} // qux
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,10 @@ public class SplitIfActionTest extends LightCodeInsightTestCase {
|
||||
|
||||
public void testCommentInside() { doTest(); }
|
||||
|
||||
public void testCommentBeforeElse() { doTest(); }
|
||||
|
||||
public void testCommentBeforeElse2() { doTest(); }
|
||||
|
||||
public void testChain() { doTest(); }
|
||||
|
||||
public void testChain2() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user