IDEA-63335 complete current statement error when statement spans on 2 lines

This commit is contained in:
peter
2011-04-14 20:01:57 +02:00
parent ff473e1ce0
commit 54d554f1d1
4 changed files with 21 additions and 8 deletions

View File

@@ -33,18 +33,18 @@ public class MissingReturnExpressionFixer implements Fixer {
throws IncorrectOperationException {
if (psiElement instanceof PsiReturnStatement) {
PsiReturnStatement retStatement = (PsiReturnStatement) psiElement;
if (retStatement.getReturnValue() != null &&
startLine(editor, retStatement) == startLine(editor, retStatement.getReturnValue())) {
PsiExpression returnValue = retStatement.getReturnValue();
if (returnValue != null &&
lineNumber(editor, editor.getCaretModel().getOffset()) == lineNumber(editor, returnValue.getTextRange().getStartOffset())) {
return;
}
PsiElement parent = PsiTreeUtil.getParentOfType(psiElement, PsiClassInitializer.class, PsiMethod.class);
if (parent instanceof PsiMethod) {
PsiMethod method = (PsiMethod) parent;
final PsiType returnType = method.getReturnType();
final PsiType returnType = ((PsiMethod) parent).getReturnType();
if (returnType != null && returnType != PsiType.VOID) {
final int startOffset = retStatement.getTextRange().getStartOffset();
if (retStatement.getReturnValue() != null) {
if (returnValue != null) {
editor.getDocument().insertString(startOffset + "return".length(), ";");
}
@@ -54,7 +54,7 @@ public class MissingReturnExpressionFixer implements Fixer {
}
}
private int startLine(Editor editor, PsiElement psiElement) {
return editor.getDocument().getLineNumber(psiElement.getTextRange().getStartOffset());
private static int lineNumber(Editor editor, int offset) {
return editor.getDocument().getLineNumber(offset);
}
}

View File

@@ -0,0 +1,6 @@
class Test {
Object method() {
return
null<caret>
}
}

View File

@@ -0,0 +1,6 @@
class Test {
Object method() {
return
null;<caret>
}
}

View File

@@ -5,7 +5,6 @@ import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.EditorActionTestCase;
@@ -185,6 +184,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testIDEADEV40479() throws Exception { doTest(); }
public void testMultilineReturn() throws Exception { doTest(); }
public void testIDEADEV13019() throws Exception {
doTestBracesNextLineStyle();
}