mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
IDEA-63335 complete current statement error when statement spans on 2 lines
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
Object method() {
|
||||
return
|
||||
null<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
Object method() {
|
||||
return
|
||||
null;<caret>
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user