SortContentAction: fix EOL comment capturing another elements while codegen

This commit is contained in:
Roman.Ivanov
2018-08-30 11:31:17 +07:00
parent 40ba62d4d8
commit a816ff3861
3 changed files with 44 additions and 0 deletions
@@ -7,6 +7,7 @@ import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
@@ -199,6 +200,17 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
handleElementsBeforeSeparator(sb, isLastInList);
if (!isLastInList) {
sb.append(",");
} else {
// last position, when before separator EOL comments and after separator some element present, we should place \n between then
// to avoid accidental commenting
if (!myBeforeSeparator.isEmpty()) {
PsiComment maybeComment = myBeforeSeparator.get(myBeforeSeparator.size() - 1);
if (maybeComment.getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
if (!myAfterSeparator.isEmpty()) {
sb.append("\n");
}
}
}
}
boolean newLineSet = false;
for (PsiComment comment : myAfterSeparator) {
@@ -0,0 +1,17 @@
// "Sort content" "true"
public class Test {
static final String[] SPECIFICATIONS = new String[]{
"1",
"1",
"1..900",
"100",
"100+10",
"100+3..999",
"100..999"//simple end comment
//simple end comment
};
}
@@ -0,0 +1,15 @@
// "Sort content" "true"
public class Test {
static final String[] SPECIFICATIONS = new String[]{
"1",
"100",<caret>
"100+10",
"100..999"//simple end comment
,
//simple end comment
"100+3..999",
"1",
"1..900",
};
}