IDEA-158249 Complete Current Statement of for loop: code is not reformatted

This commit is contained in:
peter
2018-01-02 15:55:43 +01:00
parent d047658f81
commit dd9fa434e0
5 changed files with 24 additions and 1 deletions
@@ -338,6 +338,16 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
reformat(elt);
settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = old;
editor.getCaretModel().moveToOffset(caretOffset - 1);
reformatBlockParentIfNeeded(editor, file);
}
}
private void reformatBlockParentIfNeeded(@NotNull Editor editor, @NotNull PsiFile file) {
commit(editor);
PsiCodeBlock block = PsiTreeUtil.findElementOfClassAtOffset(file, editor.getCaretModel().getOffset(), PsiCodeBlock.class, false);
if (block != null && psiElement().withParents(PsiBlockStatement.class, PsiForStatement.class).accepts(block)) {
reformat(block.getParent().getParent());
}
}
@@ -1,6 +1,6 @@
class Foo {
{
for (;;) {
for (; ; ) {
<caret>
}
}
@@ -0,0 +1,5 @@
public class Foo {
void test() {
for (int j=1; j<10; j++) <caret>
}
}
@@ -0,0 +1,7 @@
public class Foo {
void test() {
for (int j = 1; j < 10; j++) {
<caret>
}
}
}
@@ -165,6 +165,7 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testSpaceAfterSemicolon() { mySettings.getCommonSettings(JavaLanguage.INSTANCE).SPACE_AFTER_SEMICOLON = true; doTest(); }
public void testNoSpaceAfterSemicolon() { myJavaSettings.SPACE_AFTER_SEMICOLON = false; doTest(); }
public void testForUpdateGeneration() { doTest(); }
public void testReformatForHeader() { doTest(); }
public void testValidCodeBlock() { doTest(); }
public void testValidCodeBlockWithEmptyLineAfterIt() { doTest(); }
public void testFromJavadocParameterDescriptionEndToNextParameter() { doTest(); }