inline: expand expression lambda to code block for return-inline (IDEA-180888)

This commit is contained in:
Anna Kozlova
2017-11-06 18:17:05 +01:00
parent 613fe3f67f
commit de923b346c
4 changed files with 50 additions and 3 deletions

View File

@@ -314,9 +314,12 @@ public class InlineUtil {
if (element instanceof PsiMethodReferenceExpression) return TailCallType.None;
PsiExpression methodCall = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
if (methodCall == null) return TailCallType.None;
if (methodCall.getParent() instanceof PsiReturnStatement) return TailCallType.Return;
if (methodCall.getParent() instanceof PsiExpressionStatement) {
PsiStatement callStatement = (PsiStatement) methodCall.getParent();
PsiElement callParent = methodCall.getParent();
if (callParent instanceof PsiReturnStatement || callParent instanceof PsiLambdaExpression) {
return TailCallType.Return;
}
if (callParent instanceof PsiExpressionStatement) {
PsiStatement callStatement = (PsiStatement)callParent;
PsiMethod callerMethod = PsiTreeUtil.getParentOfType(callStatement, PsiMethod.class);
if (callerMethod != null) {
final PsiStatement[] psiStatements = callerMethod.getBody().getStatements();

View File

@@ -0,0 +1,16 @@
import java.util.Comparator;
class InlineLambda {
private static int compare(Integer i, Integer j) {
if (i > j) {
return 1;
}
if (j > i) {
return -1;
}
return 0;
}
private static Comparator<Integer> COMP = (o1, o2) -> com<caret>pare(o1, o2);
}

View File

@@ -0,0 +1,24 @@
import java.util.Comparator;
class InlineLambda {
private static int compare(Integer i, Integer j) {
if (i > j) {
return 1;
}
if (j > i) {
return -1;
}
return 0;
}
private static Comparator<Integer> COMP = (o1, o2) -> {
if (o1 > o2) {
return 1;
}
if (o2 > o1) {
return -1;
}
return 0;
};
}

View File

@@ -339,6 +339,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
doTestConflict("Constructor <b><code>SomeClass.SomeClass()</code></b> that is used in inlined method is not accessible from call site(s) in method <b><code>InlineWithPrivateConstructorAccessMain.main(String...)</code></b>");
}
public void testExprLambdaExpandToCodeBlock() {
doTestInlineThisOnly();
}
public void testSuperCallWhenUnqualifiedInline() {
doTestInlineThisOnly();
}