mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178933 Complete current statement for if statement without opening bracket
This commit is contained in:
+9
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
@@ -53,5 +54,13 @@ public class IfConditionFixer implements Fixer {
|
||||
doc.insertString(condition.getTextRange().getEndOffset(), ")");
|
||||
}
|
||||
}
|
||||
else if (psiElement instanceof PsiExpression && psiElement.getParent() instanceof PsiExpressionStatement) {
|
||||
PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf(psiElement);
|
||||
if (prevLeaf != null && prevLeaf.textMatches(PsiKeyword.IF)) {
|
||||
Document doc = editor.getDocument();
|
||||
doc.insertString(psiElement.getTextRange().getEndOffset(), ")");
|
||||
doc.insertString(psiElement.getTextRange().getStartOffset(), "(");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
if 1 > 2<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
if (1 > 2) {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testForIncrementExpressionAndBody() { doTest(); }
|
||||
public void testEmptyBeforeReturn() { doTest(); }
|
||||
public void testIf() { doTest(); }
|
||||
public void testIfWithoutParentheses() { doTest(); }
|
||||
public void testBeforeStatement() { doTest(); }
|
||||
public void testTry1() { doTest(); }
|
||||
public void testInsideResourceVariable() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user