Remove receiver when unwrapping trailing lambda KTIJ-21562

IntelliJ now transforms

    kotlin.run {
        println("abc")
    }

into

    println("abc")

when unwrapping.

closes https://github.com/JetBrains/intellij-community/pull/1996

GitOrigin-RevId: 7f547279382544eabe9252ec210857f62ba07815
This commit is contained in:
Christian Vonrüti
2022-07-20 15:25:34 +00:00
committed by intellij-monorepo-bot
parent 499529bd07
commit f73da4c0ea
4 changed files with 24 additions and 2 deletions
@@ -19,7 +19,14 @@ public class KotlinLambdaUnwrapper extends KotlinUnwrapRemoveBase {
PsiElement parent = lambda.getParent();
if (parent instanceof KtValueArgument) {
return PsiTreeUtil.getParentOfType(parent, KtCallExpression.class, true);
KtCallExpression callExpression = PsiTreeUtil.getParentOfType(parent, KtCallExpression.class, true);
if (callExpression != null) {
PsiElement parentParent = callExpression.getParent();
if (parentParent instanceof KtQualifiedExpression) {
return (KtElement) parentParent;
}
}
return callExpression;
}
if (parent instanceof KtCallExpression) {
@@ -39,7 +46,7 @@ public class KotlinLambdaUnwrapper extends KotlinUnwrapRemoveBase {
KtLambdaExpression lambda = (KtLambdaExpression) e;
KtBlockExpression body = lambda.getBodyExpression();
KtElement enclosingElement = getLambdaEnclosingElement((KtLambdaExpression) e);
KtElement enclosingElement = getLambdaEnclosingElement(lambda);
if (body == null || enclosingElement == null) return false;
@@ -289,6 +289,11 @@ public abstract class UnwrapRemoveTestGenerated extends AbstractUnwrapRemoveTest
public void testLambdaPropertyInBlock() throws Exception {
runTest("testData/codeInsight/unwrapAndRemove/unwrapLambda/lambdaPropertyInBlock.kt");
}
@TestMetadata("lambdaWithQualifiedReceiver.kt")
public void testLambdaWithQualifiedReceiver() throws Exception {
runTest("testData/codeInsight/unwrapAndRemove/unwrapLambda/lambdaWithQualifiedReceiver.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@@ -0,0 +1,6 @@
// OPTION: 0
fun test() {
kotlin.run <caret>{
println(123)
}
}
@@ -0,0 +1,4 @@
// OPTION: 0
fun test() {
println(123)<caret>
}