wrap return value: ignore lambda return

This commit is contained in:
Anna Kozlova
2014-11-18 18:36:41 +01:00
parent 6524ea7a10
commit e0aa800bd1
6 changed files with 47 additions and 1 deletions
@@ -179,7 +179,7 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
@Override
public void visitReturnStatement(final PsiReturnStatement statement) {
super.visitReturnStatement(statement);
if (PsiTreeUtil.getParentOfType(statement, PsiMethod.class) != myMethod) return;
if (PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class) != myMethod) return;
final PsiExpression returnValue = statement.getReturnValue();
if (returnValue != null) {
returnTypes.add(returnValue.getType());
@@ -0,0 +1,12 @@
class Test {
Wrapper foo() {
I i = () -> {
return 1;
};
return new Wrapper("");
}
}
interface I {
Integer bar();
}
@@ -0,0 +1,10 @@
class Wrapper {
String myField;
Wrapper(String s) {
myField = s;
}
String getMyField() {
return myField;
}
}
@@ -0,0 +1,12 @@
class Test {
String foo() {
I i = () -> {
return 1;
};
return "";
}
}
interface I {
Integer bar();
}
@@ -0,0 +1,10 @@
class Wrapper {
String myField;
Wrapper(String s) {
myField = s;
}
String getMyField() {
return myField;
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.refactoring;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
@@ -55,6 +56,7 @@ public class WrapReturnValueTest extends MultiFileTestCase {
public void testRawReturnType() { doTest(true, "Existing class does not have appropriate constructor"); }
public void testReturnInsideLambda() { doTest(false, null, true); }
public void testTypeAnnotations() { doTest(false); }
public void testWithLambdaInside() { doTest(true); }
private void doTest(final boolean existing) {
doTest(existing, null);