IDEA-169972 Smart Enter before else-if splits that else-if

This commit is contained in:
peter
2017-03-30 16:04:59 +02:00
parent 0583e244b0
commit 4b83d7bd0d
4 changed files with 18 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ public class MissingIfBranchesFixer implements Fixer {
}
private static void handleBranch(@NotNull Document doc, @NotNull PsiIfStatement ifStatement, @NotNull PsiElement beforeBranch, @Nullable PsiStatement branch) {
if (branch instanceof PsiBlockStatement) return;
if (branch instanceof PsiBlockStatement || beforeBranch.textMatches(PsiKeyword.ELSE) && branch instanceof PsiIfStatement) return;
boolean transformingOneLiner = branch != null && (startLine(doc, beforeBranch) == startLine(doc, branch) ||
startCol(doc, ifStatement) < startCol(doc, branch));

View File

@@ -0,0 +1,7 @@
class Foo {
{
if (a) <caret>
else if (elsecond) {
}
}
}

View File

@@ -0,0 +1,8 @@
class Foo {
{
if (a) {
<caret>
} else if (elsecond) {
}
}
}

View File

@@ -123,6 +123,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testElseIf() throws Exception { doTest(); }
public void testBlockBeforeElseIf() { doTest(); }
public void testIncompleteElseIf() throws Exception { doTest(); }
public void testField() throws Exception { doTest(); }