mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-80097 "Redundant suppression" inspection ability to ignore "ALL"
This commit is contained in:
@@ -23,8 +23,10 @@ import com.intellij.codeInspection.reference.RefClass;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefJavaVisitor;
|
||||
import com.intellij.codeInspection.reference.RefManagerImpl;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.*;
|
||||
@@ -32,10 +34,12 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.BidirectionalMap;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -47,6 +51,8 @@ import java.util.Map;
|
||||
public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
private BidirectionalMap<String, QuickFix> myQuickFixes = null;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.RedundantSuppressInspection");
|
||||
|
||||
public boolean IGNORE_ALL = false;
|
||||
|
||||
@NotNull
|
||||
public String getGroupDisplayName() {
|
||||
@@ -64,6 +70,17 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
return "RedundantSuppression";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel("Ignore @SuppressWarning(\"ALL\")", this, "IGNORE_ALL");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSettings(Element node) throws WriteExternalException {
|
||||
if (IGNORE_ALL) {
|
||||
super.writeSettings(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void runInspection(final AnalysisScope scope,
|
||||
final InspectionManager manager,
|
||||
@@ -123,6 +140,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
String idsString = SuppressManager.getInstance().getSuppressedInspectionIdsIn(owner);
|
||||
if (idsString != null && idsString.length() != 0) {
|
||||
List<String> ids = StringUtil.split(idsString, ",");
|
||||
if (IGNORE_ALL && ids.contains(SuppressionUtil.ALL)) return;
|
||||
Collection<String> suppressed = suppressedScopes.get(owner);
|
||||
if (suppressed == null) {
|
||||
suppressed = ids;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>4</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="method" FQNAME="x.S void f()" />
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>42</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="method" FQNAME="x.S void j()" />
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>53</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="field" FQNAME="x.S$3ss s" />
|
||||
</problem>
|
||||
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>19</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="method" FQNAME="x.S void h()" />
|
||||
</problem>
|
||||
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>30</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="class" FQNAME="x.S$1ss" />
|
||||
</problem>
|
||||
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>11</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="method" FQNAME="x.S void g()" />
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>X.java</file>
|
||||
<line>67</line>
|
||||
<problem_class>Redundant suppression</problem_class>
|
||||
<description>Redundant suppression</description>
|
||||
<entry_point TYPE="method" FQNAME="x.S void foo1()" />
|
||||
</problem>
|
||||
|
||||
</problems>
|
||||
@@ -0,0 +1,69 @@
|
||||
package x;
|
||||
|
||||
class S {
|
||||
public void f() {
|
||||
//noinspection HardCodedStringLiteral
|
||||
String s=null;
|
||||
//noinspection HardCodedStringLiteral
|
||||
String s2="sssssss";
|
||||
}
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
void g() {
|
||||
String s = null;
|
||||
}
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
void g2() {
|
||||
String s = "sssssss";
|
||||
}
|
||||
|
||||
void h() {
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
String s = null;
|
||||
}
|
||||
void h2() {
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
String s = "sssssss";
|
||||
}
|
||||
|
||||
void i() {
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
class ss {
|
||||
String s = null;
|
||||
}
|
||||
}
|
||||
void i2() {
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
class ss {
|
||||
String s = "sssssss";
|
||||
}
|
||||
}
|
||||
|
||||
/** @noinspection HardCodedStringLiteral */
|
||||
void j() {
|
||||
String s = null;
|
||||
}
|
||||
/** @noinspection HardCodedStringLiteral */
|
||||
void j2() {
|
||||
String s = "sssssss";
|
||||
}
|
||||
|
||||
void k() {
|
||||
class ss {
|
||||
/** @noinspection HardCodedStringLiteral */
|
||||
String s = null;
|
||||
}
|
||||
}
|
||||
void k2() {
|
||||
class ss {
|
||||
/** @noinspection HardCodedStringLiteral */
|
||||
String s = "sssssss";
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"EmptyMethod"})
|
||||
void foo() {}
|
||||
|
||||
@SuppressWarnings({"EmptyMethod"})
|
||||
void foo1() {String f;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
@@ -0,0 +1,8 @@
|
||||
package x;
|
||||
|
||||
public class S {
|
||||
@SuppressWarnings("ALL")
|
||||
public static void main(String[] args) {
|
||||
System.out.println(args[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.testFramework.InspectionTestCase;
|
||||
|
||||
public class RedundantSuppressTest extends InspectionTestCase {
|
||||
private GlobalInspectionToolWrapper myWrapper;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
InspectionToolRegistrar.getInstance().ensureInitialized();
|
||||
myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection());
|
||||
}
|
||||
|
||||
public void testDefaultFile() throws Exception {
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = true;
|
||||
doTest();
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = false;
|
||||
}
|
||||
|
||||
public void testSuppressAll() throws Exception {
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = true;
|
||||
try {
|
||||
((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = true;
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = false;
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest("redundantSuppress/" + getTestName(true), myWrapper,"java 1.5",true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user