Support moving into "else" branch of conditional expression

#KT-3877 Fixed
This commit is contained in:
Alexey Sedunov
2014-01-27 18:01:35 +04:00
parent 609154bab3
commit 0e9875aec3
10 changed files with 109 additions and 0 deletions
@@ -219,6 +219,13 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
@Nullable
private static LineRange getExpressionTargetRange(@NotNull Editor editor, @NotNull PsiElement sibling, boolean down) {
if (sibling instanceof JetIfExpression && !down) {
JetExpression elseBranch = ((JetIfExpression) sibling).getElse();
if (elseBranch instanceof JetBlockExpression) {
sibling = elseBranch;
}
}
PsiElement start = sibling;
PsiElement end = sibling;
@@ -0,0 +1,10 @@
// MOVE: down
fun foo(x: Boolean) {
if (x) {
<caret>println(x)
}
else {
}
}
@@ -0,0 +1,10 @@
// MOVE: down
fun foo(x: Boolean) {
if (x) {
}
else {
<caret>println(x)
}
}
@@ -0,0 +1,11 @@
// MOVE: up
fun foo(x: Boolean) {
if (x) {
}
else {
}
<caret>println(x)
}
@@ -0,0 +1,11 @@
// MOVE: up
fun foo(x: Boolean) {
if (x) {
}
else {
<caret>println(x)
}
}
@@ -0,0 +1,10 @@
// MOVE: up
fun foo(x: Boolean) {
if (x) {
}
else {
<caret>println(x)
}
}
@@ -0,0 +1,10 @@
// MOVE: up
fun foo(x: Boolean) {
if (x) {
<caret>println(x)
}
else {
}
}
@@ -0,0 +1,10 @@
// MOVE: down
fun foo(x: Boolean) {
if (x) {
}
else {
<caret>println(x)
}
}
@@ -0,0 +1,10 @@
// MOVE: down
fun foo(x: Boolean) {
if (x) {
}
else {
}
<caret>println(x)
}
@@ -932,6 +932,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt");
}
@TestMetadata("intoElse1.kt")
public void testIntoElse1() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoElse1.kt");
}
@TestMetadata("intoElse2.kt")
public void testIntoElse2() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoElse2.kt");
}
@TestMetadata("intoNestedClosure1.kt")
public void testIntoNestedClosure1() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosure1.kt");
@@ -1007,6 +1017,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt");
}
@TestMetadata("outOfElse1.kt")
public void testOutOfElse1() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfElse1.kt");
}
@TestMetadata("outOfElse2.kt")
public void testOutOfElse2() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfElse2.kt");
}
@TestMetadata("outOfNestedClosure1.kt")
public void testOutOfNestedClosure1() throws Exception {
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosure1.kt");