split into declarations: preserve comments in normalizeDeclaration

This commit is contained in:
Anna.Kozlova
2017-11-27 18:05:19 +01:00
parent a326a4ca94
commit 6811b80a39
3 changed files with 18 additions and 1 deletions
@@ -181,7 +181,9 @@ public class PsiLocalVariableImpl extends CompositePsiElement implements PsiLoca
ASTNode comma = PsiImplUtil.skipWhitespaceAndCommentsBack(variable.getTreePrev());
if (comma != null && comma.getElementType() == JavaTokenType.COMMA) {
CodeEditUtil.removeChildren(statement, comma, variable.getTreePrev());
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);
}
CodeEditUtil.removeChild(statement, variable);
@@ -0,0 +1,8 @@
// "Split into separate declarations" "true"
class Test {
{
String foo = "foo";//c1
//c2
String bar = "bar";
}
}
@@ -0,0 +1,7 @@
// "Split into separate declarations" "true"
class Test {
{
String foo <caret>= "foo",//c1
bar = "bar";//c2
}
}