split if: skip comments inside (IDEA-95297)

they should be restored though
This commit is contained in:
anna
2012-11-19 16:20:42 +01:00
parent ed23e353b4
commit 130e95dbf8
4 changed files with 24 additions and 2 deletions

View File

@@ -125,8 +125,7 @@ public class SplitIfAction extends PsiElementBaseIntentionAction {
}
private static PsiExpression getROperands(PsiPolyadicExpression expression, PsiJavaToken separator) throws IncorrectOperationException {
PsiElement next = separator.getNextSibling();
if (next instanceof PsiWhiteSpace) next = next.getNextSibling();
PsiElement next = PsiTreeUtil.skipSiblingsForward(separator.getNextSibling(), PsiWhiteSpace.class, PsiComment.class);
if (next == null) {
throw new IncorrectOperationException("Unable to split '"+expression.getText()+"' at '"+separator+"' (offset "+separator.getStartOffsetInParent()+")");
}

View File

@@ -0,0 +1,9 @@
class C {
void foo() {
if (a) {
call();
} else if (b) {
call();
}
}
}

View File

@@ -0,0 +1,8 @@
class C {
void foo() {
if (a |<caret>| //comment
b) {
call();
}
}
}

View File

@@ -51,6 +51,12 @@ public class SplitIfActionTest extends LightCodeInsightTestCase {
checkResultByFile("/codeInsight/splitIfAction/afterOrParenthesis.java");
}
public void testComment() throws Exception {
configureByFile("/codeInsight/splitIfAction/beforeComment.java");
perform();
checkResultByFile("/codeInsight/splitIfAction/afterComment.java");
}
public void test8() throws Exception {
configureByFile("/codeInsight/splitIfAction/beforeOrAndMixed.java");
SplitIfAction action = new SplitIfAction();