mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
inline: expand expression lambda to code block for return-inline (IDEA-180888)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user