From f700870beaaf8af2b714045c0c91ce8df2d364e9 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 4 Sep 2013 14:42:50 +0400 Subject: [PATCH] KT-3791 (Move statement moves lambda parameters out of lambda itself) Fixed --- .../upDownMover/JetExpressionMover.java | 14 +++++++++++++ .../expressions/intoClosureWithParams1.kt | 8 ++++++++ .../intoClosureWithParams1.kt.after | 8 ++++++++ .../intoNestedClosureWithParams1.kt | 8 ++++++++ .../intoNestedClosureWithParams1.kt.after | 8 ++++++++ .../expressions/outOfClosureWithParams1.kt | 8 ++++++++ .../outOfClosureWithParams1.kt.after | 8 ++++++++ .../outOfNestedClosureWithParams1.kt | 8 ++++++++ .../outOfNestedClosureWithParams1.kt.after | 8 ++++++++ .../moveUpDown/CodeMoverTestGenerated.java | 20 +++++++++++++++++++ 10 files changed, 98 insertions(+) create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt.after diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java index 450ffc07ace..8572073b3b0 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java @@ -2,6 +2,7 @@ package org.jetbrains.jet.plugin.codeInsight.upDownMover; import com.google.common.base.Predicate; import com.intellij.codeInsight.editorActions.moveUpDown.LineRange; +import com.intellij.lang.ASTNode; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.Pair; @@ -213,6 +214,13 @@ public class JetExpressionMover extends AbstractJetUpDownMover { if (parent instanceof JetFunctionLiteral) { //noinspection ConstantConditions newBlock = findClosestBlock(((JetFunctionLiteral) parent).getBodyExpression(), down, false); + + if (!down) { + ASTNode arrow = ((JetFunctionLiteral) parent).getArrowNode(); + if (arrow != null) { + end = arrow.getPsi(); + } + } } else { newBlock = findClosestBlock(sibling, down, true); } @@ -254,6 +262,12 @@ public class JetExpressionMover extends AbstractJetUpDownMover { if (blockLikeElement != null) { if (down) { end = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.LBRACE); + if (blockLikeElement instanceof JetFunctionLiteral) { + ASTNode arrow = ((JetFunctionLiteral) blockLikeElement).getArrowNode(); + if (arrow != null) { + end = arrow.getPsi(); + } + } } else { start = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.RBRACE); diff --git a/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt b/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt new file mode 100644 index 00000000000..aa15bd13e98 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + println("foo") + run(1, 2) { + x -> + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt.after new file mode 100644 index 00000000000..807608abaf7 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt.after @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + run(1, 2) { + x -> + println("foo") + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt b/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt new file mode 100644 index 00000000000..da16b6860f5 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + println("foo") + val x = run(1, 2) { + x -> + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt.after new file mode 100644 index 00000000000..edf0b236086 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt.after @@ -0,0 +1,8 @@ +// MOVE: down +fun foo() { + val x = run(1, 2) { + x -> + println("foo") + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt new file mode 100644 index 00000000000..e771f1749f5 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + run(1, 2) { + x -> + println("foo") + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt.after new file mode 100644 index 00000000000..043d92bcb9c --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt.after @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + println("foo") + run(1, 2) { + x -> + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt b/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt new file mode 100644 index 00000000000..13b030dbc35 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + val x = run(1, 2) { + x -> + println("foo") + println("bar") + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt.after new file mode 100644 index 00000000000..d107382a15f --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt.after @@ -0,0 +1,8 @@ +// MOVE: up +fun foo() { + println("foo") + val x = run(1, 2) { + x -> + println("bar") + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java index 3864131f9e6..1802114f645 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java @@ -867,6 +867,11 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoClosure2.kt"); } + @TestMetadata("intoClosureWithParams1.kt") + public void testIntoClosureWithParams1() throws Exception { + doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt"); + } + @TestMetadata("intoNestedClosure1.kt") public void testIntoNestedClosure1() throws Exception { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosure1.kt"); @@ -877,6 +882,11 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosure2.kt"); } + @TestMetadata("intoNestedClosureWithParams1.kt") + public void testIntoNestedClosureWithParams1() throws Exception { + doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosureWithParams1.kt"); + } + @TestMetadata("lambda1.kt") public void testLambda1() throws Exception { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/lambda1.kt"); @@ -902,6 +912,11 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfClosure2.kt"); } + @TestMetadata("outOfClosureWithParams1.kt") + public void testOutOfClosureWithParams1() throws Exception { + doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt"); + } + @TestMetadata("outOfNestedClosure1.kt") public void testOutOfNestedClosure1() throws Exception { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosure1.kt"); @@ -912,6 +927,11 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosure2.kt"); } + @TestMetadata("outOfNestedClosureWithParams1.kt") + public void testOutOfNestedClosureWithParams1() throws Exception { + doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt"); + } + @TestMetadata("when1.kt") public void testWhen1() throws Exception { doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/when1.kt");