diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 305537fbd9b8..6143ad8ae174 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1229,7 +1229,7 @@ string.format.class.method.name=Additional formatter methods exception.class.column.name=Exception class bad.exception.thrown.problem.descriptor=Prohibited exception ''{0}'' thrown #loc empty.catch.block.comments.option=Comments count as content -empty.catch.block.ignore.ignore.option=Ignore for 'catch' parameters named 'ignore' or 'ignored' +empty.catch.block.ignore.ignore.option=Ignore when 'catch' parameter is named 'ignore' or 'ignored' too.broad.catch.problem.descriptor=''catch'' of #ref is too broad, masking exception ''{0}'' #loc 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 diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionBase.java similarity index 94% rename from plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java rename to plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionBase.java index fa50fb44cc21..628853e6412c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionBase.java @@ -19,12 +19,12 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.util.FileTypeUtils; import com.intellij.psi.util.PsiUtil; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.intellij.psi.util.FileTypeUtils; import com.siyeh.ig.psiutils.TestUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -public class EmptyCatchBlockInspection extends BaseInspection { +public class EmptyCatchBlockInspectionBase extends BaseInspection { /** * @noinspection PublicField @@ -41,7 +41,7 @@ public class EmptyCatchBlockInspection extends BaseInspection { /** * @noinspection PublicField */ - public boolean m_ignoreTestCases = true; + public boolean m_ignoreTestCases = true; // keep for compatibility /** * @noinspection PublicField */ @@ -68,7 +68,6 @@ public class EmptyCatchBlockInspection extends BaseInspection { public JComponent createOptionsPanel() { final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this); optionsPanel.addCheckbox(InspectionGadgetsBundle.message("empty.catch.block.comments.option"), "m_includeComments"); - optionsPanel.addCheckbox(InspectionGadgetsBundle.message("empty.catch.block.ignore.option"), "m_ignoreTestCases"); optionsPanel.addCheckbox(InspectionGadgetsBundle.message("empty.catch.block.ignore.ignore.option"), "m_ignoreIgnoreParameter"); return optionsPanel; } @@ -127,9 +126,6 @@ public class EmptyCatchBlockInspection extends BaseInspection { if (FileTypeUtils.isInServerPageFile(statement.getContainingFile())) { return; } - if (m_ignoreTestCases && TestUtils.isInTestCode(statement)) { - return; - } final PsiCatchSection[] catchSections = statement.getCatchSections(); for (final PsiCatchSection section : catchSections) { checkCatchSection(section); @@ -157,7 +153,7 @@ public class EmptyCatchBlockInspection extends BaseInspection { if (catchToken == null) { return; } - registerError(catchToken); + registerError(catchToken, catchToken); } private boolean isEmpty(PsiElement element) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java new file mode 100644 index 000000000000..354f3210e6ec --- /dev/null +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.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 EmptyCatchBlockInspection extends EmptyCatchBlockInspectionBase { + + @NotNull + @Override + protected InspectionGadgetsFix[] buildFixes(Object... infos) { + final PsiElement context = (PsiElement)infos[0]; + final SuppressForTestsScopeFix fix = SuppressForTestsScopeFix.build(this, context); + if (fix == null) { + return new InspectionGadgetsFix[] {buildFix(infos)}; + } + return new InspectionGadgetsFix[] {buildFix(infos), fix}; + } +} diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyCatchBlock.html b/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyCatchBlock.html index 63b28489c34b..4e07694f28b5 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyCatchBlock.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyCatchBlock.html @@ -1,14 +1,13 @@ -Reports empty catch blocks. While occasionally intended, this +Reports empty catch blocks. While occasionally intended, empty catch blocks can make debugging extremely difficult.

At present, this inspection is disabled in JSP files.

-Use the controls below to indicate whether catch blocks containing only comments, -empty catch blocks in JUnit tests should be reported and whether to ignore empty -catch blocks if the parameter is named 'ignore' or 'ignored'. +Use the controls below to indicate whether catch blocks containing only comments should be reported, +and whether to ignore empty catch blocks if the parameter is named 'ignore' or 'ignored'.

diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionTest.java index 5648d5733e31..7e64784ce666 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/errorhandling/EmptyCatchBlockInspectionTest.java @@ -70,7 +70,7 @@ public class EmptyCatchBlockInspectionTest extends LightInspectionTestCase { public void testTest() { doTest("import junit.framework.TestCase;\n" + "class C extends TestCase {\n" + - " void m() {\n" + + " public void testM() {\n" + " try {\n" + " throw new Exception();\n" + " } catch (Exception e) {}\n" +