mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
preserve comments for create switch intention
This commit is contained in:
+2
-3
@@ -24,6 +24,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -36,10 +37,8 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction imp
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiExpressionStatement expressionStatement = PsiTreeUtil.getParentOfType(element, PsiExpressionStatement.class, false);
|
||||
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
String valueToSwitch = expressionStatement.getExpression().getText();
|
||||
PsiSwitchStatement switchStatement = (PsiSwitchStatement)elementFactory.createStatementFromText("switch (" + valueToSwitch + ") {}", null);
|
||||
switchStatement = (PsiSwitchStatement)expressionStatement.replace(switchStatement);
|
||||
PsiSwitchStatement switchStatement = (PsiSwitchStatement)new CommentTracker().replaceAndRestoreComments(expressionStatement, "switch (" + valueToSwitch + ") {}");
|
||||
CodeStyleManager.getInstance(project).reformat(switchStatement);
|
||||
|
||||
PsiJavaToken lBrace = switchStatement.getBody().getLBrace();
|
||||
|
||||
@@ -3,7 +3,7 @@ class X {
|
||||
void m() {
|
||||
|
||||
String s = getStr();
|
||||
s<caret>
|
||||
s<caret>//keep me
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ class X {
|
||||
void m() {
|
||||
|
||||
String s = getStr();
|
||||
switch (s) {<caret>
|
||||
//keep me
|
||||
switch (s) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user