IDEA-112552 "Replace with lambda" should use expression lambda when possible

This commit is contained in:
Anna Kozlova
2014-04-08 17:18:34 +02:00
parent 16dca7cf21
commit 2fa8491e90
7 changed files with 14 additions and 23 deletions

View File

@@ -161,10 +161,14 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
final PsiStatement[] statements = body.getStatements();
PsiElement copy = body.copy();
if (statements.length == 1 && statements[0] instanceof PsiReturnStatement) {
PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
if (value != null) {
copy = value.copy();
if (statements.length == 1) {
if (statements[0] instanceof PsiReturnStatement) {
PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
if (value != null) {
copy = value.copy();
}
} else if (statements[0] instanceof PsiExpressionStatement) {
copy = ((PsiExpressionStatement)statements[0]).getExpression().copy();
}
}

View File

@@ -7,9 +7,7 @@ class Test {
interface InOutEx extends InOut {
InOut bind() {
return () -> {
foo();
};
return () -> foo();
}
}
}

View File

@@ -6,8 +6,6 @@ class Test {
}
InOut bind() {
return () -> {
InOut.foo();
};
return () -> InOut.foo();
}
}

View File

@@ -4,10 +4,7 @@ class HelloLambda {
HelloLambda() {
x = 1;
Runnable r = () -> {
System.out.println(x);
};
Runnable r = () -> System.out.println(x);
}

View File

@@ -1,7 +1,5 @@
// "Replace with lambda" "true"
class HelloLambda {
private final Runnable r = () -> {
System.out.println(x);
};
private final Runnable r = () -> System.out.println(x);
private static int x = 0;
}

View File

@@ -1,8 +1,6 @@
// "Replace with lambda" "true"
class Test {
{
Runnable r = () -> {
System.out.println("");
};
Runnable r = () -> System.out.println("");
}
}

View File

@@ -1,8 +1,6 @@
// "Replace with lambda" "true"
class Test {
{
Runnable[] r = new Runnable[] {() -> {
System.out.println("");
}};
Runnable[] r = new Runnable[] {() -> System.out.println("")};
}
}