IDEA-120738 Complete current statement creates broken code

This commit is contained in:
peter
2014-02-13 19:43:13 +01:00
parent 4fb9534f06
commit 5cd8a05139
6 changed files with 33 additions and 5 deletions

View File

@@ -17,7 +17,6 @@ package com.intellij.codeInsight.editorActions.smartEnter;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
@@ -57,10 +56,9 @@ public class MissingMethodBodyFixer implements Fixer {
}
return;
}
int endOffset = method.getTextRange().getEndOffset();
if (StringUtil.endsWithChar(method.getText(), ';')) {
doc.deleteString(endOffset - 1, endOffset);
endOffset--;
int endOffset = method.getThrowsList().getTextRange().getEndOffset();
if (endOffset < doc.getTextLength() && doc.getCharsSequence().charAt(endOffset) == ';') {
doc.deleteString(endOffset, endOffset + 1);
}
doc.insertString(endOffset, "{\n}");
}

View File

@@ -0,0 +1,6 @@
public class Test {
private String s()<caret>
/* a comment */ String foo;
}

View File

@@ -0,0 +1,8 @@
public class Test {
private String s() {
<caret>
}
/* a comment */ String foo;
}

View File

@@ -0,0 +1,6 @@
public class Test {
private String s()<caret>
/* a comment */ String foo() {}
}

View File

@@ -0,0 +1,8 @@
public class Test {
private String s() {
<caret>
}
/* a comment */ String foo() {}
}

View File

@@ -147,6 +147,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testFieldBeforeAnnotation() throws Exception { doTest(); }
public void testMethodBeforeAnnotation() throws Exception { doTest(); }
public void testMethodBeforeCommentField() throws Exception { doTest(); }
public void testMethodBeforeCommentMethod() throws Exception { doTest(); }
public void testParenthesized() throws Exception { doTest(); }