[java-completion] Put a colon for multiple case labels

IDEA-296940

GitOrigin-RevId: cd5d256b6082d3dd6aa246a40cce6294f93f8fdd
This commit is contained in:
Andrey.Cherkasov
2022-06-29 19:19:10 +00:00
committed by intellij-monorepo-bot
parent 1bca314f04
commit 639652bd8d
4 changed files with 21 additions and 1 deletions
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.editorActions.smartEnter;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiCaseLabelElementList;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiSwitchLabelStatement;
import com.intellij.util.IncorrectOperationException;
@@ -28,7 +29,8 @@ public class SwitchLabelColonFixer implements Fixer {
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (psiElement instanceof PsiSwitchLabelStatement && !psiElement.getText().endsWith(":")) {
PsiSwitchLabelStatement statement = (PsiSwitchLabelStatement)psiElement;
if (statement.getCaseValue() != null || statement.isDefaultCase()) {
PsiCaseLabelElementList labelElementList = statement.getCaseLabelElementList();
if ((labelElementList != null && labelElementList.getElementCount() != 0) || statement.isDefaultCase()) {
editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), ":");
}
}
@@ -0,0 +1,8 @@
class Foo {
void foo(String a) {
switch (a) {
case "dzyolya", "izyayu<caret>"
}
}
}
@@ -0,0 +1,9 @@
class Foo {
void foo(String a) {
switch (a) {
case "dzyolya", "izyayu":
<caret>
}
}
}
@@ -139,6 +139,7 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testSwitchKeywordWithCondition() { doTest(); }
public void testSwitchBraces() { doTest(); }
public void testCaseColon() { doTest(); }
public void testMultipleCasesColon() { doTest(); }
public void testDefaultColon() { doTest(); }
public void testNewInParentheses() { doTest(); }
public void testIDEADEV20713() { doTest(); }