redundant lambda code block: do not suggest for expressions with non-void type

This commit is contained in:
Anna Kozlova
2012-09-10 12:53:36 +04:00
parent 11a2faaf14
commit 2c659ba2d9
2 changed files with 14 additions and 1 deletions

View File

@@ -97,7 +97,12 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaLocalInspectionT
return returnStatement.getReturnValue();
}
else {
return ((PsiExpressionStatement)statements[0]).getExpression();
final PsiExpression expression = ((PsiExpressionStatement)statements[0]).getExpression();
final PsiType psiType = expression.getType();
if (psiType != PsiType.VOID) {
return null;
}
return expression;
}
}
}

View File

@@ -0,0 +1,8 @@
// "Replace with one line expression" "false"
class Test {
{
Runnable c = () -> <caret>{foo();};
}
int foo() {return 1;}
}