diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspectionBase.java similarity index 94% rename from plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java rename to plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspectionBase.java index 338992af87cb..6100a7c0615b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspectionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2012 Bas Leijdekkers + * Copyright 2010-2013 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,19 +27,18 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ExceptionUtils; import com.siyeh.ig.psiutils.LibraryUtil; -import com.siyeh.ig.psiutils.TestUtils; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.*; -public class TooBroadThrowsInspection extends BaseInspection { +public class TooBroadThrowsInspectionBase 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 ignoreLibraryOverrides = false; @@ -89,7 +88,6 @@ public class TooBroadThrowsInspection extends BaseInspection { public JComponent createOptionsPanel() { final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this); panel.addCheckbox(InspectionGadgetsBundle.message("too.broad.catch.option"), "onlyWarnOnRootExceptions"); - panel.addCheckbox(InspectionGadgetsBundle.message("ignore.exceptions.declared.in.tests.option"), "ignoreInTestCode"); panel.addCheckbox(InspectionGadgetsBundle.message("ignore.exceptions.declared.on.library.override.option"), "ignoreLibraryOverrides"); panel.addCheckbox(InspectionGadgetsBundle.message("overly.broad.throws.clause.ignore.thrown.option"), "ignoreThrown"); return panel; @@ -174,9 +172,6 @@ public class TooBroadThrowsInspection extends BaseInspection { if (body == null) { return; } - if (ignoreInTestCode && TestUtils.isInTestCode(method)) { - return; - } if (ignoreLibraryOverrides && LibraryUtil.isOverrideOfLibraryMethod(method)) { return; } @@ -206,7 +201,7 @@ public class TooBroadThrowsInspection extends BaseInspection { if (ignoreThrown && originalNeeded) { continue; } - registerError(throwsReference, exceptionsMasked, Boolean.valueOf(originalNeeded)); + registerError(throwsReference, exceptionsMasked, Boolean.valueOf(originalNeeded), throwsReference); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java new file mode 100644 index 000000000000..1e60632069d3 --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/TooBroadThrowsInspection.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.errorhandling; + +import com.intellij.psi.PsiElement; +import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.fixes.SuppressForTestsScopeFix; +import org.jetbrains.annotations.NotNull; + +/** + * @author Bas Leijdekkers + */ +public class TooBroadThrowsInspection extends TooBroadThrowsInspectionBase { + + @NotNull + @Override + protected InspectionGadgetsFix[] buildFixes(Object... infos) { + final PsiElement context = (PsiElement)infos[2]; + final SuppressForTestsScopeFix suppressFix = SuppressForTestsScopeFix.build(this, context); + if (suppressFix == null) { + return new InspectionGadgetsFix[] {buildFix(infos)}; + } + return new InspectionGadgetsFix[] {buildFix(infos), suppressFix}; + } +} diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadThrows.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadThrows.html index 0a0b0788dbbd..6c94af8ed00e 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadThrows.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/TooBroadThrows.html @@ -6,11 +6,9 @@ exceptions actually thrown by the method.

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 throws clauses in test code. +Use the second checkbox below to ignore overly broad throws clauses in methods which override a library method.

-Use the third checkbox below to ignore overly broad throws clauses in methods which override a library method. -

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

New in 10