IDEA-131845 Lambdas. Wrong current statement completion.

This commit is contained in:
peter
2014-11-10 17:22:13 +01:00
parent db0cef9cc1
commit 38e08bdcf9
5 changed files with 34 additions and 2 deletions

View File

@@ -83,7 +83,7 @@ public class MissingReturnExpressionFixer implements Fixer {
if (!(prev instanceof PsiJavaToken)) {
int offset = returnStatement.getTextRange().getEndOffset();
final PsiMethod method = PsiTreeUtil.getParentOfType(returnStatement, PsiMethod.class);
final PsiMethod method = PsiTreeUtil.getParentOfType(returnStatement, PsiMethod.class, true, PsiLambdaExpression.class);
if (method != null && method.getReturnType() == PsiType.VOID) {
offset = returnStatement.getTextRange().getStartOffset() + "return".length();
}

View File

@@ -47,7 +47,7 @@ public class SemicolonFixer implements Fixer {
private static boolean fixReturn(@NotNull Editor editor, @Nullable PsiElement psiElement) {
if (psiElement instanceof PsiReturnStatement) {
PsiMethod method = PsiTreeUtil.getParentOfType(psiElement, PsiMethod.class);
PsiMethod method = PsiTreeUtil.getParentOfType(psiElement, PsiMethod.class, true, PsiLambdaExpression.class);
if (method != null && PsiType.VOID.equals(method.getReturnType())) {
PsiReturnStatement stmt = (PsiReturnStatement)psiElement;
if (stmt.getReturnValue() != null) {

View File

@@ -0,0 +1,15 @@
public class Class1 {
interface Lamb {
Object call(Object... args);
}
public void m(Lamb l) {
}
public static void main(String[] args) {
new Ex().m((arg) -> {
return "<caret>"
});
}
}

View File

@@ -0,0 +1,15 @@
public class Class1 {
interface Lamb {
Object call(Object... args);
}
public void m(Lamb l) {
}
public static void main(String[] args) {
new Ex().m((arg) -> {
return "";<caret>
});
}
}

View File

@@ -270,6 +270,8 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testArrayInitializerRBracket() throws Exception { doTest(); }
public void testReturnInLambda() { doTest(); }
private void doTestBracesNextLineStyle() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;