Support moving into "else" branch of conditional expression
#KT-3877 Fixed
This commit is contained in:
@@ -219,6 +219,13 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static LineRange getExpressionTargetRange(@NotNull Editor editor, @NotNull PsiElement sibling, boolean down) {
|
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 start = sibling;
|
||||||
PsiElement end = 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)
|
||||||
|
}
|
||||||
+20
@@ -932,6 +932,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
|||||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoClosureWithParams1.kt");
|
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")
|
@TestMetadata("intoNestedClosure1.kt")
|
||||||
public void testIntoNestedClosure1() throws Exception {
|
public void testIntoNestedClosure1() throws Exception {
|
||||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/intoNestedClosure1.kt");
|
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");
|
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")
|
@TestMetadata("outOfNestedClosure1.kt")
|
||||||
public void testOutOfNestedClosure1() throws Exception {
|
public void testOutOfNestedClosure1() throws Exception {
|
||||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosure1.kt");
|
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosure1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user