SortContentAction: fix \n placement in presence of comments: IDEA-199734

This commit is contained in:
Roman.Ivanov
2018-10-02 12:08:47 +07:00
parent 136a8ea0c5
commit 19b4764435
4 changed files with 35 additions and 7 deletions
@@ -658,7 +658,10 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
@Override
String generateReplacementText(@NotNull SortableList list, @NotNull PsiArrayInitializerMemberValue elementToSort) {
StringBuilder sb = new StringBuilder();
list.generate(sb);
boolean newLineRequired = list.generate(sb);
if (newLineRequired) {
sb.append("\n");
}
sb.append("}");
return sb.toString();
}
@@ -795,11 +798,8 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
sb.append(child.getText());
child = child.getNextSibling();
}
sortableList.generate(sb);
List<SortableEntry> entries = sortableList.myEntries;
SortableEntry last = entries.get(entries.size() - 1);
if (!last.myBeforeSeparator.isEmpty()) {
boolean newLineRequired = sortableList.generate(sb);
if (newLineRequired) {
sb.append("\n");
}
sb.append(")");
@@ -0,0 +1,15 @@
// "Sort content" "true"
class X {
public void x() {
doTest("1 ",
"T", "and", "between", "div", "eq", "false", "ge", "gt",
"instanceof", "le", "lt", "matches", "mod", "ne", "new", "not", "null", "or",
"true" //comment
);
}
private void doTest(String... s) {
}
}
@@ -16,7 +16,6 @@ public class Main {
"foo" /*3*/ // 2
// 5
);
}
}
@@ -0,0 +1,14 @@
// "Sort content" "true"
class X {
public void x() {
doTest("1 <caret>",
"and", "between", "div", "eq", "false", "ge", "gt", "instanceof",
"le", "lt", "matches", "mod", "ne", "new", "not", "null", "or", "true", //comment
"T");
}
private void doTest(String... s) {
}
}