KT-3791 (Move statement moves lambda parameters out of lambda itself) Fixed

This commit is contained in:
Alexey Sedunov
2013-09-04 14:42:50 +04:00
parent 63941c4e86
commit f700870bea
10 changed files with 98 additions and 0 deletions
@@ -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);
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
<caret>println("foo")
run(1, 2) {
x ->
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
run(1, 2) {
x ->
<caret>println("foo")
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
<caret>println("foo")
val x = run(1, 2) {
x ->
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: down
fun foo() {
val x = run(1, 2) {
x ->
<caret>println("foo")
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
run(1, 2) {
x ->
<caret>println("foo")
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
<caret>println("foo")
run(1, 2) {
x ->
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
val x = run(1, 2) {
x ->
<caret>println("foo")
println("bar")
}
}
@@ -0,0 +1,8 @@
// MOVE: up
fun foo() {
<caret>println("foo")
val x = run(1, 2) {
x ->
println("bar")
}
}
@@ -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");