From 756937e0ffcd85bce64d94a956204ad4c53aad83 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 28 Nov 2013 21:09:45 +0100 Subject: [PATCH] drop "ignore in test code" checkbox and use "suppress for 'Tests' scope" quickfix --- .../src/com/siyeh/InspectionGadgetsBundle.properties | 1 + .../errorhandling/TooBroadCatchInspectionBase.java | 12 ++++-------- .../ig/errorhandling/TooBroadCatchInspection.java | 9 +++++++-- .../src/inspectionDescriptions/TooBroadCatch.html | 4 +--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 9768eb889e25..5888e04cd6b7 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1672,6 +1672,7 @@ synchronization.on.local.variable.or.method.parameter.display.name=Synchronizati synchronization.on.local.variable.problem.descriptor=Synchronization on local variable #ref #loc synchronization.on.method.parameter.problem.descriptor=Synchronization on method parameter #ref #loc too.broad.catch.quickfix=Add ''catch'' clause for ''{0}'' +replace.with.catch.clause.for.runtime.exception.quickfix=Replace with 'catch' clause for 'RuntimeException' too.broad.catch.option=&Only warn on RuntimeException, Exception, Error or Throwable unnecessary.call.to.string.valueof.display.name=Unnecessary call to 'String.valueOf()' unnecessary.tostring.call.display.name=Unnecessary call to 'toString()' diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadCatchInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadCatchInspectionBase.java index eb292f4f644f..d225e64f225a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadCatchInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadCatchInspectionBase.java @@ -21,7 +21,6 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.ClassUtils; import com.siyeh.ig.psiutils.ExceptionUtils; -import com.siyeh.ig.psiutils.TestUtils; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -29,8 +28,8 @@ import java.util.*; public class TooBroadCatchInspectionBase extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean onlyWarnOnRootExceptions = false; - @SuppressWarnings("PublicField") - public boolean ignoreInTestCode = false; + @SuppressWarnings({"PublicField", "UnusedDeclaration"}) + public boolean ignoreInTestCode = false; // keep for compatibility @SuppressWarnings("PublicField") public boolean ignoreThrown = false; @@ -80,9 +79,6 @@ public class TooBroadCatchInspectionBase extends BaseInspection { if (tryBlock == null) { return; } - if (ignoreInTestCode && TestUtils.isInTestCode(statement)) { - return; - } final Set thrownTypes = ExceptionUtils.calculateExceptionsThrown(tryBlock); final Set caughtTypes = new HashSet(thrownTypes.size()); final PsiCatchSection[] catchSections = statement.getCatchSections(); @@ -107,7 +103,7 @@ public class TooBroadCatchInspectionBase extends BaseInspection { continue; } final PsiClass runtimeExceptionClass = ClassUtils.findClass(CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION, parameter); - registerError(typeElement, Collections.singletonList(runtimeExceptionClass)); + registerError(typeElement, Collections.singletonList(runtimeExceptionClass), typeElement); } } else { @@ -126,7 +122,7 @@ public class TooBroadCatchInspectionBase extends BaseInspection { if (typeElement == null) { return; } - registerError(typeElement, maskedExceptions); + registerError(typeElement, maskedExceptions, typeElement); } private List findMaskedExceptions(Set thrownTypes, Set caughtTypes, PsiType caughtType) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadCatchInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadCatchInspection.java index 8528570172bc..f3155471ee5a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadCatchInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadCatchInspection.java @@ -29,6 +29,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.SuppressForTestsScopeFix; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -50,6 +51,11 @@ public class TooBroadCatchInspection extends TooBroadCatchInspectionBase { fixes.add(new AddCatchSectionFix(thrown)); } } + final PsiElement context = (PsiElement)infos[1]; + final InspectionGadgetsFix fix = SuppressForTestsScopeFix.build(this, context); + if (fix != null) { + fixes.add(fix); + } return fixes.toArray(new InspectionGadgetsFix[fixes.size()]); } @@ -57,7 +63,6 @@ public class TooBroadCatchInspection extends TooBroadCatchInspectionBase { public JComponent createOptionsPanel() { final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this); panel.addCheckbox(InspectionGadgetsBundle.message("too.broad.catch.option"), "onlyWarnOnRootExceptions"); - panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode"); panel.addCheckbox(InspectionGadgetsBundle.message("overly.broad.throws.clause.ignore.thrown.option"), "ignoreThrown"); return panel; } @@ -66,7 +71,7 @@ public class TooBroadCatchInspection extends TooBroadCatchInspectionBase { @NotNull @Override public String getName() { - return "Replace with 'catch' clause for 'RuntimeException'"; + return InspectionGadgetsBundle.message("replace.with.catch.clause.for.runtime.exception.quickfix"); } @NotNull diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadCatch.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadCatch.html index 14b73fafbbd1..ccdf0fe47c0c 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadCatch.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadCatch.html @@ -6,9 +6,7 @@ exceptions thrown by the corresponding try block.

Use the first checkbox below to have this inspection only warn on the most generic exceptions.

-Use the second checkbox below to ignore overly broad catch blocks in test code. -

-Use the third checkbox below to ignore any exceptions which hide other exceptions, but which may be thrown and thus +Use the second checkbox below to ignore any exceptions which hide other exceptions, but which may be thrown and thus are technically not overly broad.