From 91f63083c7042ab3f48f3aea93367923e491eb9b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 5 May 2014 15:38:47 +0400 Subject: [PATCH] redundant suppressions: take into account alternative ids (IDEA-124690) --- .../RedundantSuppressInspectionBase.java | 15 ++++++++------- .../redundantSuppress/alternativeIds/expected.xml | 2 ++ .../redundantSuppress/alternativeIds/src/x/X.java | 9 +++++++++ .../codeInspection/RedundantSuppressTest.java | 9 ++++++++- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 java/java-tests/testData/inspection/redundantSuppress/alternativeIds/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantSuppress/alternativeIds/src/x/X.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java index f35609aabd5d..507c60b6d251 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java @@ -31,7 +31,6 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.containers.BidirectionalMap; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashMap; -import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -160,25 +159,27 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { if (suppressedScopes.values().isEmpty()) return null; // have to visit all file from scratch since inspections can be written in any perversive way including checkFile() overriding - Collection suppressedTools = new THashSet(); + Map suppressedTools = new THashMap(); InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager); for (Collection ids : suppressedScopes.values()) { for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) { final String shortName = iterator.next().trim(); for (InspectionToolWrapper toolWrapper : toolWrappers) { - if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName)) { + if (toolWrapper instanceof LocalInspectionToolWrapper && + (((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName) || + shortName.equals(((LocalInspectionToolWrapper)toolWrapper).getTool().getAlternativeID()))) { if (((LocalInspectionToolWrapper)toolWrapper).isUnfair()) { iterator.remove(); break; } else { - suppressedTools.add(toolWrapper); + suppressedTools.put(toolWrapper, shortName); } } else if (toolWrapper.getShortName().equals(shortName)) { //ignore global unused as it won't be checked anyway if (toolWrapper instanceof LocalInspectionToolWrapper || toolWrapper instanceof GlobalInspectionToolWrapper) { - suppressedTools.add(toolWrapper); + suppressedTools.put(toolWrapper, shortName); } else { iterator.remove(); @@ -199,8 +200,8 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { final List result; try { result = new ArrayList(); - for (InspectionToolWrapper toolWrapper : suppressedTools) { - String toolId = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getID() : toolWrapper.getShortName(); + for (InspectionToolWrapper toolWrapper : suppressedTools.keySet()) { + String toolId = suppressedTools.get(toolWrapper); toolWrapper.initialize(globalContext); final Collection descriptors; if (toolWrapper instanceof LocalInspectionToolWrapper) { diff --git a/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/expected.xml b/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/src/x/X.java b/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/src/x/X.java new file mode 100644 index 000000000000..d424cb57ce95 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantSuppress/alternativeIds/src/x/X.java @@ -0,0 +1,9 @@ +package x; + +class S { + @SuppressWarnings("rawtypes") + public String get(final Class cls) + { + return ""; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java index 1d00526eacf7..39f83d4f7796 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantSuppressTest.java @@ -5,6 +5,7 @@ import com.intellij.codeInspection.ex.*; import com.intellij.codeInspection.i18n.I18nInspection; import com.intellij.psi.PsiElement; import com.intellij.testFramework.InspectionTestCase; +import com.siyeh.ig.migration.RawUseOfParameterizedTypeInspection; import org.jetbrains.annotations.NotNull; public class RedundantSuppressTest extends InspectionTestCase { @@ -15,7 +16,9 @@ public class RedundantSuppressTest extends InspectionTestCase { protected void setUp() throws Exception { super.setUp(); InspectionToolRegistrar.getInstance().ensureInitialized(); - myInspectionToolWrappers = new InspectionToolWrapper[]{new LocalInspectionToolWrapper(new I18nInspection()), + myInspectionToolWrappers = new InspectionToolWrapper[]{ + new LocalInspectionToolWrapper(new I18nInspection()), + new LocalInspectionToolWrapper(new RawUseOfParameterizedTypeInspection()), new GlobalInspectionToolWrapper(new EmptyMethodInspection())}; myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() { @@ -30,6 +33,10 @@ public class RedundantSuppressTest extends InspectionTestCase { doTest(); } + public void testAlternativeIds() throws Exception { + doTest(); + } + public void testSuppressAll() throws Exception { try { ((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = true;