IDEA-155309 Complete statement does not work for default in switch

This commit is contained in:
peter
2016-05-01 16:37:31 +02:00
parent a19579a8d1
commit b7623be04f
5 changed files with 25 additions and 6 deletions

View File

@@ -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());

View File

@@ -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(), ":");
}
}
}
}

View File

@@ -0,0 +1,8 @@
class Foo {
void foo(String a) {
switch (a) {
default<caret>
}
}
}

View File

@@ -0,0 +1,9 @@
class Foo {
void foo(String a) {
switch (a) {
default:
<caret>
}
}
}

View File

@@ -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(); }