mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
IDEA-155309 Complete statement does not work for default in switch
This commit is contained in:
@@ -74,7 +74,7 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
|
||||
fixers.add(new WhileConditionFixer());
|
||||
fixers.add(new CatchDeclarationFixer());
|
||||
fixers.add(new SwitchExpressionFixer());
|
||||
fixers.add(new CaseColonFixer());
|
||||
fixers.add(new SwitchLabelColonFixer());
|
||||
fixers.add(new DoWhileConditionFixer());
|
||||
fixers.add(new BlockBraceFixer());
|
||||
fixers.add(new MissingIfBranchesFixer());
|
||||
|
||||
@@ -23,13 +23,14 @@ import com.intellij.util.IncorrectOperationException;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CaseColonFixer implements Fixer {
|
||||
public class SwitchLabelColonFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
if (psiElement instanceof PsiSwitchLabelStatement &&
|
||||
((PsiSwitchLabelStatement)psiElement).getCaseValue() != null &&
|
||||
!psiElement.getText().endsWith(":")) {
|
||||
editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), ":");
|
||||
if (psiElement instanceof PsiSwitchLabelStatement && !psiElement.getText().endsWith(":")) {
|
||||
PsiSwitchLabelStatement statement = (PsiSwitchLabelStatement)psiElement;
|
||||
if (statement.getCaseValue() != null || statement.isDefaultCase()) {
|
||||
editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
class Foo {
|
||||
void foo(String a) {
|
||||
switch (a) {
|
||||
default<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
class Foo {
|
||||
void foo(String a) {
|
||||
switch (a) {
|
||||
default:
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,7 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testSwitchKeywordWithCondition() throws Exception { doTest(); }
|
||||
public void testSwitchBraces() { doTest(); }
|
||||
public void testCaseColon() { doTest(); }
|
||||
public void testDefaultColon() { doTest(); }
|
||||
|
||||
public void testNewInParentheses() throws Exception { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user