mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 17:03:12 +07:00
IDEA-65653 (Inspection: if/else can be converted to switch)
This commit is contained in:
@@ -1847,3 +1847,6 @@ choose.super.class.to.ignore=Choose class
|
||||
ignore.anonymous.inner.classes=Ignore anonymous inner classes
|
||||
try.with.identical.catches.display.name=Identical 'catch' branches in 'try' statement
|
||||
try.with.identical.catches.problem.descriptor=Identical 'catch' branches in 'try' statement #loc
|
||||
if.can.be.switch.display.name='if' replaceable with 'switch'
|
||||
if.can.be.switch.problem.descriptor=<code>#ref</code> statement replaceable with 'switch' statement
|
||||
if.can.be.switch.quickfix=Replace with 'switch'
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
@@ -41,13 +42,14 @@ public class IfCanBeSwitchInspection extends BaseInspection {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "'if' replaceable with 'switch'";
|
||||
return InspectionGadgetsBundle.message("if.can.be.switch.display.name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return "<code>#ref</code> statement replaceable with 'switch' statement";
|
||||
return InspectionGadgetsBundle.message(
|
||||
"if.can.be.switch.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,13 +67,13 @@ public class IfCanBeSwitchInspection extends BaseInspection {
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return "Replace with 'switch'";
|
||||
return InspectionGadgetsBundle.message("if.can.be.switch.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
final PsiElement element = descriptor.getPsiElement().getParent();
|
||||
if (!(element instanceof PsiIfStatement)) {
|
||||
return;
|
||||
}
|
||||
@@ -155,8 +157,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
|
||||
new StringBuilder();
|
||||
switchStatementText.append("switch(");
|
||||
switchStatementText.append(switchExpression.getText());
|
||||
switchStatementText.append(')');
|
||||
switchStatementText.append('{');
|
||||
switchStatementText.append("){");
|
||||
for (IfStatementBranch branch : branches) {
|
||||
boolean hasConflicts = false;
|
||||
for (IfStatementBranch testBranch : branches) {
|
||||
@@ -210,7 +211,6 @@ public class IfCanBeSwitchInspection extends BaseInspection {
|
||||
switchStatementText.toString(), element);
|
||||
statementToReplace.replace(newStatement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user