Generalize movable element constraint
#KT-4468 Fixed #KT-4376 Fixed
This commit is contained in:
@@ -31,11 +31,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
}
|
||||
|
||||
private final static Class[] MOVABLE_ELEMENT_CLASSES = {
|
||||
JetDeclaration.class,
|
||||
JetBlockExpression.class,
|
||||
// Only assignments
|
||||
JetBinaryExpression.class,
|
||||
JetCallExpression.class,
|
||||
JetExpression.class,
|
||||
JetWhenEntry.class,
|
||||
JetValueArgument.class,
|
||||
PsiComment.class
|
||||
@@ -45,7 +41,10 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
@NotNull
|
||||
@Override
|
||||
public Boolean invoke(PsiElement element) {
|
||||
return (!(element instanceof JetBinaryExpression) || JetPsiUtil.isAssignment(element));
|
||||
return (!(element instanceof JetExpression)
|
||||
|| element instanceof JetDeclaration
|
||||
|| element instanceof JetBlockExpression
|
||||
|| element.getParent() instanceof JetBlockExpression);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
<caret>1 + 2
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
<caret>1 + 2
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
<caret>2 + 3
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
<caret>2 + 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
val p = <caret>if (x) {
|
||||
0
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
val p = <caret>if (x) {
|
||||
0
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
val p = <caret>if (x) {
|
||||
0
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
if (x) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
val p = <caret>if (x) {
|
||||
0
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
<caret>if (x) {
|
||||
|
||||
}
|
||||
if (x) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
<caret>if (x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
<caret>if (x) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
<caret>if (x) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
<caret>x.let { printn(x) }
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
<caret>x.let { printn(x) }
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
<caret>x.let { printn(x) }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
<caret>x.let { printn(x) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
<caret>while (x) {
|
||||
|
||||
}
|
||||
if (x) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
<caret>while (x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
}
|
||||
<caret>while (x) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo(x: Boolean) {
|
||||
if (x) {
|
||||
|
||||
<caret>while (x) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -777,6 +777,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/codeInsight/moveUpDown/expressions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("binaryExpr1.kt")
|
||||
public void testBinaryExpr1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("binaryExpr2.kt")
|
||||
public void testBinaryExpr2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("closureBlockBoundary1.kt")
|
||||
public void testClosureBlockBoundary1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/closureBlockBoundary1.kt");
|
||||
@@ -867,6 +877,26 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/if4.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifExprToBlock1.kt")
|
||||
public void testIfExprToBlock1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifExprToBlock2.kt")
|
||||
public void testIfExprToBlock2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifToBlock1.kt")
|
||||
public void testIfToBlock1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifToBlock2.kt")
|
||||
public void testIfToBlock2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("insideExpression1.kt")
|
||||
public void testInsideExpression1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt");
|
||||
@@ -992,6 +1022,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfNestedClosureWithParams1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("qualifiedCall1.kt")
|
||||
public void testQualifiedCall1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("qualifiedCall2.kt")
|
||||
public void testQualifiedCall2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("when1.kt")
|
||||
public void testWhen1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/when1.kt");
|
||||
@@ -1042,6 +1082,16 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/while2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whileToBlock1.kt")
|
||||
public void testWhileToBlock1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whileToBlock2.kt")
|
||||
public void testWhileToBlock2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
|
||||
Reference in New Issue
Block a user