mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
NestedIfJoinLinesHandler: fix polyadic case.
Fixes IDEA-190660 ClassCastException after code reformatting using 'Join Lines' Fixes EA-119515 - CCE: NestedIfJoinLinesHandler.tryJoinLines
This commit is contained in:
@@ -57,8 +57,8 @@ public class NestedIfJoinLinesHandler implements JoinLinesHandlerDelegate {
|
||||
String childConditionText = ParenthesesUtils.getText(ct.markUnchanged(innerCondition), ParenthesesUtils.OR_PRECEDENCE);
|
||||
String parentConditionText = ParenthesesUtils.getText(ct.markUnchanged(outerCondition), ParenthesesUtils.OR_PRECEDENCE);
|
||||
|
||||
PsiBinaryExpression newCondition = (PsiBinaryExpression)ct.replace(outerCondition, parentConditionText + "&&" + childConditionText);
|
||||
PsiElement newCondition = ct.replace(outerCondition, parentConditionText + "&&" + childConditionText);
|
||||
ct.replaceAndRestoreComments(outerIf.getThenBranch(), innerIf.getThenBranch());
|
||||
return newCondition.getOperationSign().getTextRange().getStartOffset();
|
||||
return newCondition.getTextRange().getStartOffset() + parentConditionText.length() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
void test(int a, int b) {
|
||||
if(a > 0 && b < 0) System.out.println(a + b);
|
||||
if(a > 0 <caret>&& b < 0) System.out.println(a + b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
void test(int a, int b) {
|
||||
<caret>if(a > 0 && a < 10) {
|
||||
if (b > 0 && b < 10) System.out.println(a + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
void test(int a, int b) {
|
||||
if(a > 0 && a < 10 <caret>&& b > 0 && b < 10) System.out.println(a + b);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
class Foo {
|
||||
void test(int a, int b) {
|
||||
if(a > 0 && b < 0) {
|
||||
if(a > 0 <caret>&& b < 0) {
|
||||
System.out.println(a+b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
|
||||
public void testAssignmentAndReassignmentWithCall() { doTest(); }
|
||||
|
||||
public void testIfChain() { doTest(); }
|
||||
public void testIfChainPolyadic() { doTest(); }
|
||||
public void testIfChainNoBraces() { doTest(); }
|
||||
public void testIfChainElse() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user