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

This commit is contained in:
Anna Kozlova
2014-04-08 18:28:25 +02:00
parent 16dca7cf21
commit 2fa8491e90
7 changed files with 14 additions and 23 deletions
@@ -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();
}
}