mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SortContentAction: preserve comments in corner case
This commit is contained in:
@@ -503,9 +503,7 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
void generate(StringBuilder sb, boolean isLastInRow, boolean isLast) {
|
||||
sb.append(myExpression.getText());
|
||||
for (PsiElement element : myBeforeSeparator) {
|
||||
sb.append(element.getText());
|
||||
}
|
||||
handleElementsBeforeSeparator(sb, isLast);
|
||||
if (!isLast) {
|
||||
sb.append(",");
|
||||
}
|
||||
@@ -513,7 +511,7 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
|
||||
for (PsiComment comment : myAfterSeparator) {
|
||||
sb.append(" ")
|
||||
.append(comment.getText());
|
||||
if (comment.getText().contains("//")) {
|
||||
if (comment.getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
|
||||
sb.append("\n");
|
||||
newLineSet = true;
|
||||
}
|
||||
@@ -525,5 +523,22 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleElementsBeforeSeparator(StringBuilder sb, boolean isLast) {
|
||||
boolean newLineNeed = false;
|
||||
for (PsiElement element : myBeforeSeparator) {
|
||||
if (newLineNeed) {
|
||||
sb.append('\n');
|
||||
newLineNeed = false;
|
||||
}
|
||||
sb.append(element.getText());
|
||||
if (element instanceof PsiComment && ((PsiComment)element).getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
|
||||
newLineNeed = true;
|
||||
}
|
||||
}
|
||||
if (!isLast && newLineNeed) {
|
||||
sb.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Sort content" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static void foo(String a, String... vararg) {}
|
||||
|
||||
private void test() {
|
||||
foo(/*6*/"bar", // 1
|
||||
// 4
|
||||
"bar",
|
||||
|
||||
"baz"// 7
|
||||
// 8
|
||||
,
|
||||
"foo"/*3*/ // 2
|
||||
// 5
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Sort content" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static void foo(String a, String... vararg) {}
|
||||
|
||||
private void test() {
|
||||
foo(/*6*/"bar", // 1
|
||||
// 4
|
||||
"foo"/*3*/, // 2
|
||||
// 5
|
||||
<caret>"bar",
|
||||
"baz"// 7
|
||||
// 8
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user