mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 05:51:25 +07:00
IDEA-31554 "Complete Current Statement" does not format code on "else if" condition code block
This commit is contained in:
@@ -28,7 +28,9 @@ import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -197,6 +199,17 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
|
||||
atCaret = parent;
|
||||
}
|
||||
|
||||
if (parent instanceof PsiIfStatement && atCaret == ((PsiIfStatement)parent).getElseBranch()) {
|
||||
PsiFile file = atCaret.getContainingFile();
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
if (document != null) {
|
||||
TextRange elseIfRange = atCaret.getTextRange();
|
||||
int lineStart = document.getLineStartOffset(document.getLineNumber(elseIfRange.getStartOffset()));
|
||||
CodeStyleManager.getInstance(atCaret.getProject()).reformatText(file, lineStart, elseIfRange.getEndOffset());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.reformat(atCaret);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Test {
|
||||
public void foo(int x) {
|
||||
if (false) {
|
||||
return;
|
||||
} else if (tr<caret>ue) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Test {
|
||||
public void foo(int x) {
|
||||
if (false) {
|
||||
return;
|
||||
} else if (true) {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
|
||||
public void testCompleteElseIf() throws Exception { doTest(); }
|
||||
|
||||
public void testReformatElseIf() { doTest(); }
|
||||
|
||||
public void testCompleteStringLiteral() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user