[java-inspections] SwitchStatementWithTooFewBranches: description updated, serialization fixed

GitOrigin-RevId: 456b695eebd902ca48cb6fb2102b1450d9aa7902
This commit is contained in:
Tagir Valeev
2022-04-07 07:55:33 +00:00
committed by intellij-monorepo-bot
parent 39a4c61fad
commit 83e613fa2f
2 changed files with 16 additions and 3 deletions
@@ -20,9 +20,7 @@ import com.intellij.codeInsight.daemon.impl.quickfix.UnwrapSwitchLabelFix;
import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.SetInspectionOptionFix;
import com.intellij.codeInspection.ui.InspectionOptionsPanel;
import com.intellij.codeInspection.ui.SingleIntegerFieldOptionsPanel;
import com.intellij.java.JavaBundle;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
@@ -33,7 +31,7 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.DelegatingFix;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.SwitchUtils;
import one.util.streamex.StreamEx;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -94,6 +92,12 @@ public class SwitchStatementWithTooFewBranchesInspection extends BaseInspection
return fixes.toArray(InspectionGadgetsFix.EMPTY_ARRAY);
}
@Override
public void writeSettings(@NotNull Element node) {
defaultWriteSettings(node, "ignorePatternSwitch");
writeBooleanOption(node, "ignorePatternSwitch", false);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new MinimumSwitchBranchesVisitor();
@@ -21,5 +21,14 @@ and
<!-- tooltip end -->
<p>Configure the inspection:</p>
<p>Use the <b>Minimum number of branches</b> field to specify the minimum expected number of <code>case</code> labels.</p>
<p>Use the <b>Do not report pattern switch statements</b> option to avoid reporting switch statements and expressions that
have pattern branches. E.g.:</p>
<pre><code>
String result = switch(obj) {
case String str -> str.trim();
default -> "none";
};
</code></pre>
<p>It might be preferred to keep the switch even with a single pattern branch, rather than using the <code>instanceof</code> statement.</p>
</body>
</html>