diff --git a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java index ccb794aa60d5..fafa4d00570c 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -832,6 +832,13 @@ public class PsiTreeUtil { return prevLeaf; } + @Nullable + public static PsiElement nextVisibleLeaf(@NotNull final PsiElement element) { + PsiElement nextLeaf = nextLeaf(element, true); + while (nextLeaf != null && StringUtil.isEmptyOrSpaces(nextLeaf.getText())) nextLeaf = nextLeaf(nextLeaf, true); + return nextLeaf; + } + @Nullable public static PsiElement nextLeaf(final PsiElement element, final boolean skipEmptyElements) { PsiElement nextLeaf = nextLeaf(element); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/actions/GroovyStatementMover.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/actions/GroovyStatementMover.java index 6ccfa5d320f9..6ed63fe64059 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/actions/GroovyStatementMover.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/actions/GroovyStatementMover.java @@ -113,6 +113,9 @@ public class GroovyStatementMover extends StatementUpDownMover { element = owner; } } + if (element instanceof PsiComment) { + element = PsiTreeUtil.nextVisibleLeaf(element); + } return (GroovyPsiElement)PsiTreeUtil.findFirstParent(element, new Condition() { @Override diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java index 3ab2dc8b98ab..452b3eb4bb31 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java @@ -99,6 +99,7 @@ public class GroovyMoveStatementTest extends LightCodeInsightFixtureTestCase { public void testStatementToEmptySpace3() throws Throwable { bothTest(); } public void testStatementsWithSemicolons() throws Throwable { bothTest(); } + public void testStatementsWithComments() throws Throwable { bothTest(); } private void bothTest() { final List data = TestUtils.readInput(getTestDataPath() + getTestName(true) + ".test"); diff --git a/plugins/groovy/testdata/groovy/actions/moveStatement/statementsWithComments.test b/plugins/groovy/testdata/groovy/actions/moveStatement/statementsWithComments.test new file mode 100644 index 000000000000..b274f755915a --- /dev/null +++ b/plugins/groovy/testdata/groovy/actions/moveStatement/statementsWithComments.test @@ -0,0 +1,21 @@ +def bar() { + +} + +private boolean function() { + println 'hi' + //foo + println 'hi3' + println 'hi2' +} +----- +def bar() { + +} + +private boolean function() { + //foo + println 'hi3' + println 'hi' + println 'hi2' +} \ No newline at end of file