mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Don't offer the action "Replace with old-style switch" on empty 'switch' statement (IDEA-208270)
This commit is contained in:
+8
-3
@@ -5,10 +5,10 @@ import com.intellij.codeInsight.BlockUtils;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import com.siyeh.ig.psiutils.SwitchUtils;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -35,7 +35,7 @@ public class EnhancedSwitchBackwardMigrationInspection extends AbstractBaseJavaL
|
||||
return new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitSwitchExpression(PsiSwitchExpression expression) {
|
||||
if (!SwitchUtils.isRuleFormatSwitch(expression)) return;
|
||||
if (!isNonemptyRuleFormatSwitch(expression)) return;
|
||||
if (findReplacer(expression) == null) return;
|
||||
String message = InspectionsBundle.message("inspection.switch.expression.backward.expression.migration.inspection.name");
|
||||
holder.registerProblem(expression.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix());
|
||||
@@ -43,11 +43,16 @@ public class EnhancedSwitchBackwardMigrationInspection extends AbstractBaseJavaL
|
||||
|
||||
@Override
|
||||
public void visitSwitchStatement(PsiSwitchStatement statement) {
|
||||
if (!SwitchUtils.isRuleFormatSwitch(statement)) return;
|
||||
if (!isNonemptyRuleFormatSwitch(statement)) return;
|
||||
if (findReplacer(statement) == null) return;
|
||||
String message = InspectionsBundle.message("inspection.switch.expression.backward.statement.migration.inspection.name");
|
||||
holder.registerProblem(statement.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix());
|
||||
}
|
||||
|
||||
private boolean isNonemptyRuleFormatSwitch(PsiSwitchBlock block) {
|
||||
PsiSwitchLabelStatementBase label = PsiTreeUtil.getChildOfType(block.getBody(), PsiSwitchLabelStatementBase.class);
|
||||
return label instanceof PsiSwitchLabeledRuleStatement;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace with old style 'switch' statement" "false"
|
||||
import java.util.*;
|
||||
|
||||
class SwitchExpressionMigration {
|
||||
void foo(int n) {
|
||||
<caret>switch (n) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user