[java-inspections] SwitchStatementWithTooFewBranches: provide quick-fix "Unwrap 'switch'" in case default label element

IDEA-274278

GitOrigin-RevId: 97c04cf69e8bffbc1be2d2fd1f6dfae05bd6c986
This commit is contained in:
Andrey.Cherkasov
2022-07-07 20:36:03 +04:00
committed by intellij-monorepo-bot
parent 3a9a706530
commit c6016b645e
3 changed files with 15 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
// "Unwrap 'switch'" "true"
class Test {
void foo(Object obj) {
int answer = 42;
}
}

View File

@@ -0,0 +1,8 @@
// "Unwrap 'switch'" "true"
class Test {
void foo(Object obj) {
int answer = sw<caret>itch (obj) {
case default -> 42;
};
}
}

View File

@@ -147,7 +147,7 @@ public class SwitchStatementWithTooFewBranchesInspection extends BaseInspection
PsiStatement[] statements = body.getStatements();
if (statements.length == 1 && statements[0] instanceof PsiSwitchLabeledRuleStatement) {
PsiSwitchLabeledRuleStatement statement = (PsiSwitchLabeledRuleStatement)statements[0];
fixIsAvailable = statement.isDefaultCase() && statement.getBody() instanceof PsiExpressionStatement;
fixIsAvailable = SwitchUtils.isDefaultLabel(statement) && statement.getBody() instanceof PsiExpressionStatement;
}
else {
fixIsAvailable = false;