From 77750d58e608b9e61e82c3966c724558d8d09bdd Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 20 Jun 2008 14:09:00 +0400 Subject: [PATCH] IDEADEV-15934 --- .../com/siyeh/InspectionGadgetsBundle.properties | 2 +- .../UnusedCatchParameterInspection.java | 29 ++++++++++++++-------- .../UnusedCatchParameter.html | 5 ++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 6e2d84dcc5..d62f03a941 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -923,6 +923,7 @@ non.thread.safe.lazy.initialization.problem.descriptor=Lazy initialization of st catch.generic.class.problem.descriptor=catch of generic #ref class should be replaced with more precise exception #loc empty.catch.block.problem.descriptor=Empty #ref block #loc unused.catch.parameter.problem.descriptor=Unused catch parameter #ref #loc +used.catch.parameter.named.ignore.problem.descriptor=Catch parameter named #ref is used #loc empty.finally.block.problem.descriptor=Empty #ref block #loc finally.block.cannot.complete.normally.problem.descriptor=#ref block can not complete normally #loc empty.try.block.problem.descriptor=Empty #ref block #loc @@ -1201,7 +1202,6 @@ too.broad.catch.problem.descriptor=Catch of #ref is too broad, mask too.broad.catch.problem.descriptor1=Catch of #ref is too broad, masking exceptions ''{0}'' and ''{1}'' #loc unused.catch.parameter.ignore.catch.option=Ignore for catch blocks containing comments unused.catch.parameter.ignore.empty.option=Ignore unused catch parameters in JUnit test cases -unused.catch.parameter.ignore.name.option=Ignore for catch parameters named 'ignore' or 'ignored' add.serialversionuidfield.quickfix=Add 'serialVersionUID' field delete.import.quickfix=Delete unnecessary import encapsulate.variable.quickfix=Encapsulate variable diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/UnusedCatchParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/UnusedCatchParameterInspection.java index a020f1e407..36886336c0 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/UnusedCatchParameterInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/UnusedCatchParameterInspection.java @@ -37,8 +37,6 @@ public class UnusedCatchParameterInspection extends BaseInspection { public boolean m_ignoreCatchBlocksWithComments = false; /** @noinspection PublicField */ public boolean m_ignoreTestCases = false; - /** @noinspection PublicField */ - public boolean m_ignoreIgnoreParameter = true; @NotNull public String getDisplayName() { @@ -55,20 +53,27 @@ public class UnusedCatchParameterInspection extends BaseInspection { optionsPanel.addCheckbox(InspectionGadgetsBundle.message( "unused.catch.parameter.ignore.empty.option"), "m_ignoreTestCases"); - optionsPanel.addCheckbox(InspectionGadgetsBundle.message( - "unused.catch.parameter.ignore.name.option"), - "m_ignoreIgnoreParameter"); return optionsPanel; } @NotNull protected String buildErrorString(Object... infos) { + final boolean namedIgnoreButUsed = ((Boolean) infos[0]).booleanValue(); + if (namedIgnoreButUsed) { + return InspectionGadgetsBundle.message( + "used.catch.parameter.named.ignore.problem.descriptor" + ); + } return InspectionGadgetsBundle.message( "unused.catch.parameter.problem.descriptor"); } @Nullable protected InspectionGadgetsFix buildFix(Object... infos) { + final boolean namedIgnoreButUsed = ((Boolean) infos[0]).booleanValue(); + if (namedIgnoreButUsed) { + return null; + } return new UnusedCatchParameterFix(); } @@ -121,11 +126,8 @@ public class UnusedCatchParameterInspection extends BaseInspection { return; } @NonNls final String parametername = parameter.getName(); - if (m_ignoreIgnoreParameter && - ("ignore".equals(parametername) || - "ignored".equals(parametername))) { - return; - } + final boolean namedIgnore = "ignore".equals(parametername) || + "ignored".equals(parametername); final PsiCodeBlock block = section.getCatchBlock(); if (block == null) { return; @@ -142,9 +144,14 @@ public class UnusedCatchParameterInspection extends BaseInspection { new CatchParameterUsedVisitor(parameter); block.accept(visitor); if (visitor.isUsed()) { + if (namedIgnore) { + registerVariableError(parameter, Boolean.valueOf(true)); + } + return; + } else if (namedIgnore) { return; } - registerVariableError(parameter); + registerVariableError(parameter, Boolean.valueOf(false)); } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UnusedCatchParameter.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UnusedCatchParameter.html index 621f434f18..177fb5a9e4 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/UnusedCatchParameter.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UnusedCatchParameter.html @@ -3,10 +3,11 @@ This inspection reports any catch parameters that are unused in their corresponding blocks. This inspection will not report any catch parameters -named "ignore" or "ignored". +named "ignore" or "ignored". Conversely this inspection will warn on any +catch parameters named "ignore" or "ignored" that are actually used.

Use the checkboxes below to disable this inspection for catch -blocks with comments, catch blocks in test code, or for catch parameters named 'ignore' or 'ignored'. +blocks with comments, catch blocks in test code.

Powered by InspectionGadgets \ No newline at end of file -- 2.11.4.GIT