normalize declaration: don't include tree next after space

This commit is contained in:
Anna.Kozlova
2017-11-29 12:12:54 +01:00
parent c082f34ded
commit 64364640a9
3 changed files with 17 additions and 5 deletions
@@ -181,9 +181,17 @@ public class PsiLocalVariableImpl extends CompositePsiElement implements PsiLoca
ASTNode comma = PsiImplUtil.skipWhitespaceAndCommentsBack(variable.getTreePrev());
if (comma != null && comma.getElementType() == JavaTokenType.COMMA) {
PsiElement commaPsi = comma.getPsi();
PsiElement lastWhitespaceAfterComma = commaPsi != null && commaPsi.getNextSibling() instanceof PsiWhiteSpace ? PsiTreeUtil.skipWhitespacesForward(commaPsi) : null;
CodeEditUtil.removeChildren(statement, comma, lastWhitespaceAfterComma != null ? lastWhitespaceAfterComma.getNode() : comma);
PsiElement lastWhitespaceAfterComma = comma.getPsi();
while (true) {
PsiElement nextSibling = lastWhitespaceAfterComma.getNextSibling();
if (nextSibling instanceof PsiWhiteSpace) {
lastWhitespaceAfterComma = nextSibling;
}
else {
break;
}
}
CodeEditUtil.removeChildren(statement, comma, lastWhitespaceAfterComma.getNode());
}
CodeEditUtil.removeChild(statement, variable);
@@ -3,6 +3,8 @@ class Test {
{
String foo = "foo";//c1
//c2
//c3
String bar = "bar";
String baz = "baz";
}
}
@@ -1,7 +1,9 @@
// "Split into separate declarations" "true"
class Test {
{
String foo <caret>= "foo",//c1
bar = "bar";//c2
String foo <caret>= "foo",
//c1
bar = "bar",//c2
baz = "baz"; //c3
}
}