mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
drop "ignore in test code" checkbox and use "suppress for 'Tests' scope" quickfix
This commit is contained in:
+1
@@ -1672,6 +1672,7 @@ synchronization.on.local.variable.or.method.parameter.display.name=Synchronizati
|
||||
synchronization.on.local.variable.problem.descriptor=Synchronization on local variable <code>#ref</code> #loc
|
||||
synchronization.on.method.parameter.problem.descriptor=Synchronization on method parameter <code>#ref</code> #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()'
|
||||
|
||||
+4
-8
@@ -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<PsiClassType> thrownTypes = ExceptionUtils.calculateExceptionsThrown(tryBlock);
|
||||
final Set<PsiType> caughtTypes = new HashSet<PsiType>(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<PsiClass> findMaskedExceptions(Set<PsiClassType> thrownTypes, Set<PsiType> caughtTypes, PsiType caughtType) {
|
||||
|
||||
+7
-2
@@ -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
|
||||
|
||||
@@ -6,9 +6,7 @@ exceptions thrown by the corresponding <b>try</b> block.
|
||||
<p>
|
||||
Use the first checkbox below to have this inspection only warn on the most generic exceptions.
|
||||
<p>
|
||||
Use the second checkbox below to ignore overly broad <b>catch</b> blocks in test code.
|
||||
<p>
|
||||
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.
|
||||
<p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user