From 3c1b41c0200da6486eb15f3490a5f56dbcc48d50 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sat, 3 Aug 2019 18:02:32 +0200 Subject: [PATCH] Move statement: move into lambda correctly #KT-17887 Fixed --- .../codeInsight/upDownMover/KotlinExpressionMover.kt | 4 ++++ .../expressions/lambdaInQualifiedExpression.kt | 12 ++++++++++++ .../expressions/lambdaInQualifiedExpression.kt.after | 12 ++++++++++++ .../moveUpDown/MoveStatementTestGenerated.java | 5 +++++ 4 files changed, 33 insertions(+) create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.kt index 2b74d9fc269..5cb2f086981 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.kt @@ -291,6 +291,10 @@ class KotlinExpressionMover : AbstractKotlinUpDownMover() { element is KtLoopExpression ) return null + (element as? KtQualifiedExpression)?.selectorExpression?.let { + return getDSLLambdaBlock(editor, it, down) + } + val callExpression = KtPsiUtil.getOutermostDescendantElement(element, down, IS_CALL_EXPRESSION) as KtCallExpression? ?: return null val functionLiterals = callExpression.lambdaArguments diff --git a/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt b/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt new file mode 100644 index 00000000000..428ab7c3cea --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt @@ -0,0 +1,12 @@ +// MOVE: down +fun test() { + val foo = foo() + Bar().also { + if (foo != null) { + } + } +} + +fun foo(): String? = null + +class Bar \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt.after new file mode 100644 index 00000000000..1ddc77b904f --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt.after @@ -0,0 +1,12 @@ +// MOVE: down +fun test() { + Bar().also { + val foo = foo() + if (foo != null) { + } + } +} + +fun foo(): String? = null + +class Bar \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java index b7ca02aecef..87ad0a4d417 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java @@ -1093,6 +1093,11 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest { runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInIf2.kt"); } + @TestMetadata("lambdaInQualifiedExpression.kt") + public void testLambdaInQualifiedExpression() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInQualifiedExpression.kt"); + } + @TestMetadata("lambdaInTry.kt") public void testLambdaInTry() throws Exception { runTest("idea/testData/codeInsight/moveUpDown/expressions/lambdaInTry.kt");