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 d3132cc729d..ee2b1fd7969 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java @@ -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); } }; diff --git a/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt new file mode 100644 index 00000000000..0f6a02d279c --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt @@ -0,0 +1,11 @@ +// MOVE: down + +fun foo(x: Boolean) { + 1 + 2 + if (x) { + + } + else { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt.after new file mode 100644 index 00000000000..b32819f49ea --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr1.kt.after @@ -0,0 +1,11 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + 1 + 2 + + } + else { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt new file mode 100644 index 00000000000..c707eebee16 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt @@ -0,0 +1,11 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + else { + + } + 2 + 3 +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt.after new file mode 100644 index 00000000000..e449e1ef5ca --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/binaryExpr2.kt.after @@ -0,0 +1,11 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + else { + + 2 + 3 + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt new file mode 100644 index 00000000000..3ac11ac5b82 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt @@ -0,0 +1,13 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + val p = if (x) { + 0 + } + else { + 1 + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt.after new file mode 100644 index 00000000000..117171acc7e --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock1.kt.after @@ -0,0 +1,13 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + val p = if (x) { + 0 + } + else { + 1 + } + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt new file mode 100644 index 00000000000..58bb85fdc9a --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt @@ -0,0 +1,13 @@ +// MOVE: down + +fun foo(x: Boolean) { + val p = if (x) { + 0 + } + else { + 1 + } + if (x) { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt.after new file mode 100644 index 00000000000..9a404f25313 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifExprToBlock2.kt.after @@ -0,0 +1,13 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + val p = if (x) { + 0 + } + else { + 1 + } + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt new file mode 100644 index 00000000000..479ff946eac --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt @@ -0,0 +1,10 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + + } + if (x) { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt.after new file mode 100644 index 00000000000..384b443ceaf --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock1.kt.after @@ -0,0 +1,10 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + if (x) { + + } + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt new file mode 100644 index 00000000000..0a948543a59 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt @@ -0,0 +1,10 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + if (x) { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt.after new file mode 100644 index 00000000000..e01407e56e8 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/ifToBlock2.kt.after @@ -0,0 +1,10 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + if (x) { + + } + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt new file mode 100644 index 00000000000..55738923d81 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt @@ -0,0 +1,11 @@ +// MOVE: down + +fun foo(x: Boolean) { + x.let { printn(x) } + if (x) { + + } + else { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt.after new file mode 100644 index 00000000000..8a42545dcce --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall1.kt.after @@ -0,0 +1,11 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + x.let { printn(x) } + + } + else { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt new file mode 100644 index 00000000000..0f09914726c --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt @@ -0,0 +1,11 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + else { + + } + x.let { printn(x) } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt.after new file mode 100644 index 00000000000..1e6f36fc978 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/qualifiedCall2.kt.after @@ -0,0 +1,11 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + else { + + x.let { printn(x) } + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt new file mode 100644 index 00000000000..f90252329d1 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt @@ -0,0 +1,10 @@ +// MOVE: down + +fun foo(x: Boolean) { + while (x) { + + } + if (x) { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt.after new file mode 100644 index 00000000000..34bcc24347e --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock1.kt.after @@ -0,0 +1,10 @@ +// MOVE: down + +fun foo(x: Boolean) { + if (x) { + while (x) { + + } + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt new file mode 100644 index 00000000000..cee8ffbd1a6 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt @@ -0,0 +1,10 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + } + while (x) { + + } +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt.after new file mode 100644 index 00000000000..0cccd1e9692 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/whileToBlock2.kt.after @@ -0,0 +1,10 @@ +// MOVE: up + +fun foo(x: Boolean) { + if (x) { + + while (x) { + + } + } +} 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 aab27b7dda6..92f48b11242 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java @@ -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() {