mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
[java] JoinLines: support incomplete &&-expression
Fixes EA-266646 - AE: JavaParserUtil.parseFragment GitOrigin-RevId: d9b0b9ebd0afe239a5c3086f4a27834ed475dc84
This commit is contained in:
committed by
intellij-monorepo-bot
parent
11c836c1c1
commit
8b850d6449
@@ -4,6 +4,7 @@ package com.intellij.codeInsight.editorActions;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -84,7 +85,15 @@ public class NestedIfJoinLinesHandler implements JoinRawLinesHandlerDelegate {
|
||||
String parentConditionText = ParenthesesUtils.getText(outerCondition, ParenthesesUtils.OR_PRECEDENCE);
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiFile.getProject());
|
||||
String condition = parentConditionText + " && " + childConditionText;
|
||||
PsiElement lastChild = outerCondition.getLastChild();
|
||||
String condition;
|
||||
if (lastChild instanceof PsiErrorElement &&
|
||||
PsiUtil.isJavaToken(PsiTreeUtil.skipWhitespacesAndCommentsBackward(lastChild), JavaTokenType.ANDAND)) {
|
||||
// unterminated condition like if(a &&) -- reuse existing &&
|
||||
condition = parentConditionText + " " + childConditionText;
|
||||
} else {
|
||||
condition = parentConditionText + " && " + childConditionText;
|
||||
}
|
||||
String innerIfBody = innerIf.getText().substring(rParenth.getTextRangeInParent().getStartOffset());
|
||||
if (!innerPrefix.isEmpty()) {
|
||||
String finalInnerPrefix = innerPrefix;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
void test(boolean a, boolean b) {
|
||||
<caret>if(a &&) {
|
||||
if (b) {
|
||||
System.out.println("x");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
void test(boolean a, boolean b) {
|
||||
if(a && b) {
|
||||
System.out.println("x");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public class JoinLinesTest extends LightJavaCodeInsightTestCase {
|
||||
public void testAssignmentAndReassignmentWithCall() { doTest(); }
|
||||
|
||||
public void testIfChain() { doTest(); }
|
||||
public void testIfChainIncomplete() { doTest(); }
|
||||
public void testIfChainCorrectIndent() { doTest(); }
|
||||
public void testIfChainPolyadic() { doTest(); }
|
||||
public void testIfChainNoBraces() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user