mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[java-completions] IDEA-332716 IJ-CR-115136 SmartEnter invoked on the 'switch' expression does not move caret inside
- added formatting for switch expression -simplify MissingSwitchBodyFixer GitOrigin-RevId: 4c77e10ce5dd83d9c4f5d08c0c9fe94eeca0d411
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4ddc5337dd
commit
a5d749d8ea
@@ -371,6 +371,9 @@ public abstract class AbstractBasicJavaSmartEnterProcessor extends SmartEnterPro
|
||||
BasicJavaAstTreeUtil.is(block.getTreeParent().getTreeParent(), BASIC_FOR_STATEMENT)) {
|
||||
reformat(block.getTreeParent().getTreeParent().getPsi());
|
||||
}
|
||||
if (block != null && BasicJavaAstTreeUtil.is(block.getTreeParent(), BASIC_SWITCH_EXPRESSION)) {
|
||||
reformat(block.getTreeParent().getPsi());
|
||||
}
|
||||
}
|
||||
|
||||
public void registerUnresolvedError(int offset) {
|
||||
|
||||
@@ -4,10 +4,6 @@ package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.SmartPointerManager;
|
||||
import com.intellij.psi.SmartPsiElementPointer;
|
||||
import com.intellij.psi.impl.source.BasicJavaAstTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -17,7 +13,8 @@ import static com.intellij.psi.impl.source.BasicJavaElementType.BASIC_SWITCH_STA
|
||||
|
||||
public class MissingSwitchBodyFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, AbstractBasicJavaSmartEnterProcessor processor, @NotNull ASTNode astNode) throws IncorrectOperationException {
|
||||
public void apply(Editor editor, AbstractBasicJavaSmartEnterProcessor processor, @NotNull ASTNode astNode)
|
||||
throws IncorrectOperationException {
|
||||
if (!(BasicJavaAstTreeUtil.is(astNode, BASIC_SWITCH_EXPRESSION, BASIC_SWITCH_STATEMENT))) return;
|
||||
|
||||
final ASTNode body = BasicJavaAstTreeUtil.getCodeBlock(astNode);
|
||||
@@ -28,19 +25,6 @@ public class MissingSwitchBodyFixer implements Fixer {
|
||||
|
||||
int offset = rParenth.getTextRange().getEndOffset();
|
||||
processor.insertBracesWithNewLine(editor, offset);
|
||||
if (BasicJavaAstTreeUtil.is(astNode, BASIC_SWITCH_EXPRESSION)) {
|
||||
Project project = editor.getProject();
|
||||
PsiElement psiElement = BasicJavaAstTreeUtil.toPsi(astNode);
|
||||
if (project != null && psiElement != null) {
|
||||
SmartPsiElementPointer<PsiElement> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
|
||||
processor.commit(editor);
|
||||
PsiElement reparsedSwitch = pointer.getElement();
|
||||
if (reparsedSwitch != null) {
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
processor.reformat(editor, pointer.getElement());
|
||||
processor.setSkipEnter(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user