IDEA-75547 Groovy move statement moves method if a line comment is selected together with statements

This commit is contained in:
peter
2011-10-17 16:30:59 +02:00
parent be92524835
commit 41b005ce81
4 changed files with 32 additions and 0 deletions
@@ -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);
@@ -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<PsiElement>() {
@Override
@@ -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<String> data = TestUtils.readInput(getTestDataPath() + getTestName(true) + ".test");
@@ -0,0 +1,21 @@
def bar() {
}
private boolean function() {
println 'hi'
<selection> //foo
println 'hi3'<caret></selection>
println 'hi2'
}
-----
def bar() {
}
private boolean function() {
<selection> //foo
println 'hi3'<caret></selection>
println 'hi'
println 'hi2'
}