IDEA-80097 "Redundant suppression" inspection ability to ignore "ALL"
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 11:23:21 +0000 (15:23 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 25 Jan 2012 11:26:12 +0000 (15:26 +0400)
java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java
java/java-tests/testData/inspection/redundantSuppress/defaultFile/expected.xml [new file with mode: 0644]
java/java-tests/testData/inspection/redundantSuppress/defaultFile/src/x/X.java [new file with mode: 0644]
java/java-tests/testData/inspection/redundantSuppress/suppressAll/expected.xml [new file with mode: 0644]
java/java-tests/testData/inspection/redundantSuppress/suppressAll/src/x/X.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java [new file with mode: 0644]

index 1139e1613e59f3f7ffdc364f9986466ebfa16292..f2e52e81a2031abd560ab5194a8bf1b24eb0713d 100644 (file)
@@ -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;
diff --git a/java/java-tests/testData/inspection/redundantSuppress/defaultFile/expected.xml b/java/java-tests/testData/inspection/redundantSuppress/defaultFile/expected.xml
new file mode 100644 (file)
index 0000000..6fd7f7a
--- /dev/null
@@ -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>
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/redundantSuppress/defaultFile/src/x/X.java b/java/java-tests/testData/inspection/redundantSuppress/defaultFile/src/x/X.java
new file mode 100644 (file)
index 0000000..95e1a63
--- /dev/null
@@ -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;}
+
+}
diff --git a/java/java-tests/testData/inspection/redundantSuppress/suppressAll/expected.xml b/java/java-tests/testData/inspection/redundantSuppress/suppressAll/expected.xml
new file mode 100644 (file)
index 0000000..5e93349
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+</problems>
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/redundantSuppress/suppressAll/src/x/X.java b/java/java-tests/testData/inspection/redundantSuppress/suppressAll/src/x/X.java
new file mode 100644 (file)
index 0000000..7645e60
--- /dev/null
@@ -0,0 +1,8 @@
+package x;
+
+public class S {
+  @SuppressWarnings("ALL")
+  public static void main(String[] args) {
+    System.out.println(args[0]);
+  }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java
new file mode 100644 (file)
index 0000000..148a9a8
--- /dev/null
@@ -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);
+  }
+}