expand one line lambda: fix value compatibility check

This commit is contained in:
Anna Kozlova
2014-11-03 15:50:02 +01:00
parent e887542c3e
commit 4c490557a9
4 changed files with 22 additions and 1 deletions
@@ -44,7 +44,7 @@ public class ExpandOneLineLambda2CodeBlockIntention extends Intention {
final PsiElement body = lambdaExpression.getBody();
LOG.assertTrue(body instanceof PsiExpression);
String blockText = "{";
blockText += ((PsiExpression)body).getType() == PsiType.VOID ? "" : "return ";
blockText += PsiType.VOID.equals(LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression)) ? "" : "return ";
blockText += body.getText() + ";}";
final String resultedLambdaText = lambdaExpression.getParameterList().getText() + "->" + blockText;
@@ -0,0 +1,7 @@
import java.util.List;
class X {
void foo(List<String> list){
Runnable c = () <caret>-> list.add("");
}
}
@@ -0,0 +1,9 @@
import java.util.List;
class X {
void foo(List<String> list){
Runnable c = () -> {
list.add("");
};
}
}
@@ -22,6 +22,11 @@ public class ExpandOneLineLambda2CodeBlockIntentionTest extends IPPTestCase {
public void testSimple() {
doTest();
}
public void testVoidCompatibleInExpr() {
doTest();
}
@Override
protected String getIntentionName() {
return "Expand lambda expression body to {...}";