diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java index b67c32ed376..a77085e063a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java @@ -350,6 +350,28 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover { } } + if (start == sibling && end == sibling) { + PsiElement comment = sibling; + while (true) { + int nextLine = getElementLine(comment, editor, !down) + (down ? 1 : -1); + comment = firstNonWhiteSibling(comment, down); + if (comment instanceof PsiComment && getElementLine(comment, editor, down) == nextLine) { + if (down) { + end = comment; + } else { + start = comment; + } + } + else break; + } + if (down && end instanceof PsiComment) { + PsiElement next = firstNonWhiteSibling(end, true); + if (getElementLine(next, editor, true) == getElementLine(end, editor, false) + 1) { + end = next; + } + } + } + return start != null && end != null ? new LineRange(start, end, editor.getDocument()) : null; } diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt b/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt new file mode 100644 index 00000000000..56a84003df0 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt @@ -0,0 +1,7 @@ +// MOVE: up +fun wrap() { + // comment1 + // comment2 + val b = 42 + fun nested() {} +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt.after new file mode 100644 index 00000000000..43d82c73683 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt.after @@ -0,0 +1,7 @@ +// MOVE: up +fun wrap() { + fun nested() {} + // comment1 + // comment2 + val b = 42 +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt b/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt new file mode 100644 index 00000000000..cf8701ef5e0 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt @@ -0,0 +1,9 @@ +// MOVE: up +fun wrap() { + /* + comment1 + comment2 + */ + val b = 42 + fun nested() {} +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt.after new file mode 100644 index 00000000000..f70f1380faf --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt.after @@ -0,0 +1,9 @@ +// MOVE: up +fun wrap() { + fun nested() {} + /* + comment1 + comment2 + */ + val b = 42 +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt b/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt new file mode 100644 index 00000000000..7b6441bd700 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt @@ -0,0 +1,7 @@ +// MOVE: down +fun wrap() { + fun nested() {} + // comment1 + // comment2 + val b = 42 +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt.after new file mode 100644 index 00000000000..f983389d047 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt.after @@ -0,0 +1,7 @@ +// MOVE: down +fun wrap() { + // comment1 + // comment2 + val b = 42 + fun nested() {} +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt b/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt new file mode 100644 index 00000000000..512c12ba5a7 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt @@ -0,0 +1,9 @@ +// MOVE: down +fun wrap() { + fun nested() {} + /* + comment1 + comment1 + */ + val b = 42 +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt.after new file mode 100644 index 00000000000..07ae42b0a74 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt.after @@ -0,0 +1,9 @@ +// MOVE: down +fun wrap() { + /* + comment1 + comment1 + */ + val b = 42 + fun nested() {} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java index 14eaadb962a..9465a983569 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java @@ -859,6 +859,26 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest { runTest("idea/testData/codeInsight/moveUpDown/expressions/declaration2.kt"); } + @TestMetadata("hasComment1.kt") + public void testHasComment1() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/hasComment1.kt"); + } + + @TestMetadata("hasComment2.kt") + public void testHasComment2() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/hasComment2.kt"); + } + + @TestMetadata("hasComment3.kt") + public void testHasComment3() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/hasComment3.kt"); + } + + @TestMetadata("hasComment4.kt") + public void testHasComment4() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/hasComment4.kt"); + } + @TestMetadata("If1.kt") public void testIf1() throws Exception { runTest("idea/testData/codeInsight/moveUpDown/expressions/If1.kt");