IDEA-41929 Ctrl + Shift + Enter doesn't work for "for (; ;)"

This commit is contained in:
peter
2015-07-09 20:49:00 +02:00
parent 4f6e27823e
commit 75f04d0383
5 changed files with 22 additions and 4 deletions
@@ -248,7 +248,8 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
final PsiElement[] children = atCaret.getChildren();
for (PsiElement child : children) {
if (atCaret instanceof PsiStatement && child instanceof PsiStatement) continue;
if (atCaret instanceof PsiStatement && child instanceof PsiStatement &&
!(atCaret instanceof PsiForStatement && child == ((PsiForStatement)atCaret).getInitialization())) continue;
collectAllElements(child, res, recurse);
}
}
@@ -42,12 +42,15 @@ public class MissingForBodyFixer implements Fixer {
if (body != null && startLine(doc, body) == startLine(doc, forStatement)) return;
PsiElement eltToInsertAfter = forStatement.getRParenth();
String text = "{}";
String braces = "{\n}";
String text = braces;
if (eltToInsertAfter == null) {
eltToInsertAfter = forStatement;
text = "){}";
text = ")" + text;
}
doc.insertString(eltToInsertAfter.getTextRange().getEndOffset(), text);
int offset = eltToInsertAfter.getTextRange().getEndOffset();
doc.insertString(offset, text);
editor.getCaretModel().moveToOffset(offset + text.length() - braces.length());
}
@Nullable
@@ -0,0 +1,5 @@
class Foo {
{
for (;;<caret>)
}
}
@@ -0,0 +1,7 @@
class Foo {
{
for (;;) {
<caret>
}
}
}
@@ -85,6 +85,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testFor() throws Exception { doTest(); }
public void testEmptyFor() { doTest(); }
public void testForEach() throws Exception { doTest(); }
public void testForBlock() throws Exception { doTest(); }