From d45c8a5da2bfc2ff4914b7254a897223402f4f87 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 17 Jun 2014 17:56:35 +0400 Subject: [PATCH] all inspections are suppressable by default; language suppressor is needed to provide non trivial implementation --- .../BaseJavaBatchLocalInspectionTool.java | 14 +------ .../BaseJavaLocalInspectionTool.java | 6 +-- .../GlobalJavaBatchInspectionTool.java | 12 +----- .../GlobalJavaInspectionTool.java | 8 ++-- .../UnusedSymbolLocalInspectionBase.java | 25 +----------- .../InspectionProfileEntry.java | 39 ++++++++++++++++++- .../codeInspection/LocalInspectionTool.java | 5 +++ .../daemon/impl/HighlightInfo.java | 28 +++++-------- .../codeInspection/SuppressionUtil.java | 20 +--------- .../ex/InspectionManagerEx.java | 17 ++++---- .../GroovySuppressableInspectionTool.java | 14 +------ .../rest/inspections/RestInspection.java | 11 +++--- .../inspections/PyDocstringInspection.java | 9 +++-- .../python/inspections/PyInspection.java | 18 ++++----- .../quickfix/PySuppressInspectionFix.java | 5 ++- .../inspections/SpellCheckingInspection.java | 11 ++---- .../XmlSuppressableInspectionTool.java | 13 +------ 17 files changed, 96 insertions(+), 159 deletions(-) diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java index 18f1c5128ab6..4b585c30cf83 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaBatchLocalInspectionTool.java @@ -26,18 +26,8 @@ import org.jetbrains.annotations.Nullable; * - work with PSI or document only and * - don't provide {@link com.intellij.codeInsight.intention.IntentionAction} for quick fixes/suppression, making do with {@link LocalQuickFix} only. */ -public abstract class BaseJavaBatchLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool implements BatchSuppressableTool { - @NotNull - @Override - public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { - return BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(HighlightDisplayKey.find(getShortName())); - } - - @Override - public boolean isSuppressedFor(@NotNull PsiElement element) { - return isSuppressedFor(element, this); - } - +public abstract class BaseJavaBatchLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool { + @Deprecated public static boolean isSuppressedFor(@NotNull PsiElement element, @NotNull LocalInspectionTool tool) { BatchSuppressManager manager = BatchSuppressManager.SERVICE.getInstance(); String alternativeId; diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java index ab807d608579..df0085fff6de 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/BaseJavaLocalInspectionTool.java @@ -42,11 +42,7 @@ public abstract class BaseJavaLocalInspectionTool extends AbstractBaseJavaLocalI return SuppressManager.getInstance().createSuppressActions(key); } - @Override - public boolean isSuppressedFor(@NotNull PsiElement element) { - return isSuppressedFor(element, this); - } - + @Deprecated public static boolean isSuppressedFor(@NotNull PsiElement element, @NotNull LocalInspectionTool tool) { return BaseJavaBatchLocalInspectionTool.isSuppressedFor(element, tool); } diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaBatchInspectionTool.java b/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaBatchInspectionTool.java index 8c2726e77bef..5ac743d212ce 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaBatchInspectionTool.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaBatchInspectionTool.java @@ -26,7 +26,7 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class GlobalJavaBatchInspectionTool extends GlobalInspectionTool implements BatchSuppressableTool { +public abstract class GlobalJavaBatchInspectionTool extends GlobalInspectionTool { @Override public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager, @NotNull final GlobalInspectionContext globalContext, @@ -38,14 +38,4 @@ public abstract class GlobalJavaBatchInspectionTool extends GlobalInspectionTool return false; } - @NotNull - @Override - public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { - return BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(HighlightDisplayKey.find(getShortName())); - } - - @Override - public boolean isSuppressedFor(@NotNull final PsiElement element) { - return BatchSuppressManager.SERVICE.getInstance().isSuppressedFor(element, getShortName()); - } } diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java b/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java index 1d9ff9c4a6cc..df596771a9c8 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/GlobalJavaInspectionTool.java @@ -26,7 +26,7 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class GlobalJavaInspectionTool extends GlobalInspectionTool implements CustomSuppressableInspectionTool { +public abstract class GlobalJavaInspectionTool extends GlobalInspectionTool { @Override public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager, @NotNull final GlobalInspectionContext globalContext, @@ -38,10 +38,10 @@ public abstract class GlobalJavaInspectionTool extends GlobalInspectionTool impl return false; } + @NotNull @Override - @Nullable - public SuppressIntentionAction[] getSuppressActions(final PsiElement element) { - return SuppressManager.getInstance().createSuppressActions(HighlightDisplayKey.find(getShortName())); + public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { + return BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(HighlightDisplayKey.find(getShortName())); } @Override diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspectionBase.java index dc28a7b340c0..14da43194fe7 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unusedSymbol/UnusedSymbolLocalInspectionBase.java @@ -15,14 +15,11 @@ */ package com.intellij.codeInspection.unusedSymbol; -import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.daemon.impl.HighlightInfoType; -import com.intellij.codeInspection.*; -import com.intellij.psi.PsiElement; +import com.intellij.codeInspection.BaseJavaLocalInspectionTool; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -public class UnusedSymbolLocalInspectionBase extends AbstractBaseJavaLocalInspectionTool implements CustomSuppressableInspectionTool { +public class UnusedSymbolLocalInspectionBase extends BaseJavaLocalInspectionTool { @NonNls public static final String SHORT_NAME = HighlightInfoType.UNUSED_SYMBOL_SHORT_NAME; @NonNls public static final String DISPLAY_NAME = HighlightInfoType.UNUSED_SYMBOL_DISPLAY_NAME; @NonNls public static final String UNUSED_PARAMETERS_SHORT_NAME = "UnusedParameters"; @@ -33,22 +30,4 @@ public class UnusedSymbolLocalInspectionBase extends AbstractBaseJavaLocalInspec public boolean CLASS = true; public boolean PARAMETER = true; public boolean REPORT_PARAMETER_FOR_PUBLIC_METHODS = true; - - @Override - public boolean isSuppressedFor(@NotNull PsiElement element) { - return isSuppressedFor(element, this); - } - public static boolean isSuppressedFor(@NotNull PsiElement element, @NotNull LocalInspectionTool tool) { - return BaseJavaBatchLocalInspectionTool.isSuppressedFor(element, tool); - } - @Override - public SuppressIntentionAction[] getSuppressActions(final PsiElement element) { - String shortName = getShortName(); - HighlightDisplayKey key = HighlightDisplayKey.find(shortName); - if (key == null) { - throw new AssertionError("HighlightDisplayKey.find(" + shortName + ") is null. Inspection: "+getClass()); - } - SuppressQuickFix[] batchSuppressActions = BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(key); - return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions); - } } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java index 0b8d36431d54..8b1bb2807750 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; import com.intellij.util.ResourceUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.SerializationFilter; @@ -46,7 +47,7 @@ import java.util.Set; * @since 28-Nov-2005 */ @SuppressWarnings("JavadocReference") -public abstract class InspectionProfileEntry { +public abstract class InspectionProfileEntry implements BatchSuppressableTool{ public static final String GENERAL_GROUP_NAME = InspectionsBundle.message("inspection.general.tools.group.name"); private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.InspectionProfileEntry"); @@ -56,6 +57,42 @@ public abstract class InspectionProfileEntry { private static final Object BLACK_LIST_LOCK = new Object(); private Boolean myUseNewSerializer = null; + @NonNls + @Nullable + public String getAlternativeID() { + return null; + } + + @Override + public boolean isSuppressedFor(@NotNull PsiElement element) { + InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage()); + if (suppressor != null) { + String toolId = getSuppressId(); + if (suppressor.isSuppressedFor(element, toolId)) { + return true; + } + final String alternativeId = getAlternativeID(); + return alternativeId != null && !alternativeId.equals(toolId) && suppressor.isSuppressedFor(element, alternativeId); + } + return false; + } + + protected String getSuppressId() { + return getShortName(); + } + + @NotNull + @Override + public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { + if (element != null) { + InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage()); + if (suppressor != null) { + return suppressor.getSuppressActions(element, getShortName()); + } + } + return SuppressQuickFix.EMPTY_ARRAY; + } + public void cleanup(Project project) { } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/LocalInspectionTool.java b/platform/analysis-api/src/com/intellij/codeInspection/LocalInspectionTool.java index db7d8c4bd806..b4cba852eba2 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/LocalInspectionTool.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/LocalInspectionTool.java @@ -71,6 +71,11 @@ public abstract class LocalInspectionTool extends InspectionProfileEntry { return getShortName(); } + @Override + protected String getSuppressId() { + return getID(); + } + @NonNls @Nullable public String getAlternativeID() { diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index a8fe5d27dd16..483f3c5b2839 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -830,33 +830,23 @@ public class HighlightInfo implements Segment { throw new AssertionError("unknown tool: " + toolWrapper+"; key: "+myKey); } - SuppressQuickFix[] suppressFixes = null; if (wrappedTool instanceof CustomSuppressableInspectionTool) { - suppressFixes = SuppressQuickFix.EMPTY_ARRAY; final IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool)wrappedTool).getSuppressActions(element); if (suppressActions != null) { ContainerUtil.addAll(newOptions, suppressActions); } - } - if (wrappedTool instanceof BatchSuppressableTool) { - suppressFixes = ((BatchSuppressableTool)wrappedTool).getBatchSuppressActions(element); - } - - if (suppressFixes == null) { - final InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage()); - if (suppressor != null) { - suppressFixes = suppressor.getSuppressActions(element, wrappedTool.getShortName()); + } else { + SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element); + if (suppressFixes.length > 0) { + ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressFixes, new Function() { + @Override + public IntentionAction fun(SuppressQuickFix fix) { + return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix); + } + })); } } - if (suppressFixes != null) { - ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressFixes, new Function() { - @Override - public IntentionAction fun(SuppressQuickFix fix) { - return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix); - } - })); - } } if (myProblemGroup instanceof SuppressableProblemGroup) { final IntentionAction[] suppressActions = ((SuppressableProblemGroup)myProblemGroup).getSuppressActions(element); diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java index 249696cd6c3f..4f1de6622a1f 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java @@ -194,24 +194,6 @@ public class SuppressionUtil extends SuppressionUtilCore { } public static boolean inspectionResultSuppressed(@NotNull PsiElement place, @NotNull LocalInspectionTool tool) { - if (tool instanceof CustomSuppressableInspectionTool) { - return ((CustomSuppressableInspectionTool)tool).isSuppressedFor(place); - } - if (tool instanceof BatchSuppressableTool) { - return ((BatchSuppressableTool)tool).isSuppressedFor(place); - } - - final InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(place.getLanguage()); - if (suppressor != null) { - return suppressor.isSuppressedFor(place, tool.getID()); - } - - String alternativeId; - String id; - - return isSuppressed(place, id = tool.getID()) || - (alternativeId = tool.getAlternativeID()) != null && - !alternativeId.equals(id) && - isSuppressed(place, alternativeId); + return tool.isSuppressedFor(place); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionManagerEx.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionManagerEx.java index 17aaee57d8f5..2c934d76bbd5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionManagerEx.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionManagerEx.java @@ -90,16 +90,13 @@ public class InspectionManagerEx extends InspectionManagerBase { if (tool instanceof CustomSuppressableInspectionTool) { return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null); } - if (tool instanceof BatchSuppressableTool) { - LocalQuickFix[] actions = ((BatchSuppressableTool)tool).getBatchSuppressActions(null); - return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function() { - @Override - public SuppressIntentionAction fun(final LocalQuickFix fix) { - return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix); - } - }); - } - return null; + LocalQuickFix[] actions = tool.getBatchSuppressActions(null); + return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function() { + @Override + public SuppressIntentionAction fun(final LocalQuickFix fix) { + return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix); + } + }); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GroovySuppressableInspectionTool.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GroovySuppressableInspectionTool.java index 184476b33a7a..b348c9cabefd 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GroovySuppressableInspectionTool.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GroovySuppressableInspectionTool.java @@ -44,14 +44,7 @@ import java.util.regex.Matcher; /** * @author peter */ -public abstract class GroovySuppressableInspectionTool extends LocalInspectionTool implements BatchSuppressableTool { - @NotNull - @Override - public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { - return getSuppressActions(getShortName()); - - } - +public abstract class GroovySuppressableInspectionTool extends LocalInspectionTool { public static SuppressQuickFix[] getSuppressActions(String name) { final HighlightDisplayKey displayKey = HighlightDisplayKey.find(name); return new SuppressQuickFix[] { @@ -61,11 +54,6 @@ public abstract class GroovySuppressableInspectionTool extends LocalInspectionTo }; } - @Override - public boolean isSuppressedFor(@NotNull final PsiElement element) { - return isElementToolSuppressedIn(element, getID()); - } - public static boolean isElementToolSuppressedIn(final PsiElement place, final String toolId) { return getElementToolSuppressedIn(place, toolId) != null; } diff --git a/python/python-rest/src/com/jetbrains/rest/inspections/RestInspection.java b/python/python-rest/src/com/jetbrains/rest/inspections/RestInspection.java index 0369198c3f3c..a22819d0cebd 100644 --- a/python/python-rest/src/com/jetbrains/rest/inspections/RestInspection.java +++ b/python/python-rest/src/com/jetbrains/rest/inspections/RestInspection.java @@ -15,9 +15,7 @@ */ package com.jetbrains.rest.inspections; -import com.intellij.codeInspection.CustomSuppressableInspectionTool; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.SuppressIntentionAction; +import com.intellij.codeInspection.*; import com.intellij.psi.PsiElement; import com.jetbrains.rest.RestBundle; import org.jetbrains.annotations.Nls; @@ -27,7 +25,7 @@ import org.jetbrains.annotations.Nullable; /** * User : catherine */ -public abstract class RestInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool { +public abstract class RestInspection extends LocalInspectionTool { @Nls @NotNull @Override @@ -46,9 +44,10 @@ public abstract class RestInspection extends LocalInspectionTool implements Cust return true; } + @NotNull @Override - public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) { - return null; + public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { + return SuppressQuickFix.EMPTY_ARRAY; } @Override diff --git a/python/src/com/jetbrains/python/inspections/PyDocstringInspection.java b/python/src/com/jetbrains/python/inspections/PyDocstringInspection.java index 5a7ac6ff9a30..ae47dbb6136e 100644 --- a/python/src/com/jetbrains/python/inspections/PyDocstringInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyDocstringInspection.java @@ -21,7 +21,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.intellij.codeInspection.LocalInspectionToolSession; import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.codeInspection.SuppressIntentionAction; +import com.intellij.codeInspection.SuppressQuickFix; import com.intellij.lang.ASTNode; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.TextRange; @@ -230,9 +230,10 @@ public class PyDocstringInspection extends PyInspection { } } + @NotNull @Override - public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) { - List result = new ArrayList(); + public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { + List result = new ArrayList(); if (element != null) { if (PsiTreeUtil.getParentOfType(element, PyFunction.class) != null) { result.add(new PySuppressInspectionFix(getShortName().replace("Inspection", ""), "Suppress for function", PyFunction.class)); @@ -241,6 +242,6 @@ public class PyDocstringInspection extends PyInspection { result.add(new PySuppressInspectionFix(getShortName().replace("Inspection", ""), "Suppress for class", PyClass.class)); } } - return result.toArray(new SuppressIntentionAction[result.size()]); + return result.toArray(new SuppressQuickFix[result.size()]); } } diff --git a/python/src/com/jetbrains/python/inspections/PyInspection.java b/python/src/com/jetbrains/python/inspections/PyInspection.java index 9227f1c7d1d1..a35e2c774b05 100644 --- a/python/src/com/jetbrains/python/inspections/PyInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyInspection.java @@ -15,10 +15,7 @@ */ package com.jetbrains.python.inspections; -import com.intellij.codeInspection.CustomSuppressableInspectionTool; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.SuppressIntentionAction; -import com.intellij.codeInspection.SuppressionUtil; +import com.intellij.codeInspection.*; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -41,7 +38,7 @@ import java.util.regex.Pattern; /** * @author yole */ -public abstract class PyInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool { +public abstract class PyInspection extends LocalInspectionTool { @Nls @NotNull @Override @@ -60,12 +57,13 @@ public abstract class PyInspection extends LocalInspectionTool implements Custom return true; } + @NotNull @Override - public SuppressIntentionAction[] getSuppressActions(@Nullable final PsiElement element) { - List result = new ArrayList(); + public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { + List result = new ArrayList(); result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for statement", PyStatement.class) { @Override - protected PsiElement getContainer(PsiElement context) { + public PsiElement getContainer(PsiElement context) { if (PsiTreeUtil.getParentOfType(context, PyStatementList.class, false, ScopeOwner.class) != null || PsiTreeUtil.getParentOfType(context, PyFunction.class, PyClass.class) == null) { return super.getContainer(context); @@ -75,7 +73,7 @@ public abstract class PyInspection extends LocalInspectionTool implements Custom }); result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for function", PyFunction.class)); result.add(new PySuppressInspectionFix(getSuppressId(), "Suppress for class", PyClass.class)); - return result.toArray(new SuppressIntentionAction[result.size()]); + return result.toArray(new SuppressQuickFix[result.size()]); } @Override @@ -131,7 +129,7 @@ public abstract class PyInspection extends LocalInspectionTool implements Custom return m.matches() && SuppressionUtil.isInspectionToolIdMentioned(m.group(1), getSuppressId()); } - private String getSuppressId() { + protected String getSuppressId() { return getShortName().replace("Inspection", ""); } } diff --git a/python/src/com/jetbrains/python/inspections/quickfix/PySuppressInspectionFix.java b/python/src/com/jetbrains/python/inspections/quickfix/PySuppressInspectionFix.java index 9addabf06a98..0e6a7d98b356 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/PySuppressInspectionFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/PySuppressInspectionFix.java @@ -15,6 +15,7 @@ */ package com.jetbrains.python.inspections.quickfix; +import com.intellij.codeInsight.daemon.impl.actions.AbstractBatchSuppressByNoInspectionCommentFix; import com.intellij.codeInsight.daemon.impl.actions.AbstractSuppressByNoInspectionCommentFix; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -23,7 +24,7 @@ import com.jetbrains.python.psi.PyElement; /** * @author yole */ -public class PySuppressInspectionFix extends AbstractSuppressByNoInspectionCommentFix { +public class PySuppressInspectionFix extends AbstractBatchSuppressByNoInspectionCommentFix { private final Class myContainerClass; public PySuppressInspectionFix(final String ID, final String text, final Class containerClass) { @@ -33,7 +34,7 @@ public class PySuppressInspectionFix extends AbstractSuppressByNoInspectionComme } @Override - protected PsiElement getContainer(PsiElement context) { + public PsiElement getContainer(PsiElement context) { return PsiTreeUtil.getParentOfType(context, myContainerClass); } } diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java b/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java index fefddce8dfb9..1f2244995f68 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java @@ -40,7 +40,7 @@ import java.awt.*; import java.util.Set; -public class SpellCheckingInspection extends LocalInspectionTool implements BatchSuppressableTool { +public class SpellCheckingInspection extends LocalInspectionTool { public static final String SPELL_CHECKING_INSPECTION_TOOL_NAME = "SpellCheckingInspection"; @Override @@ -66,12 +66,8 @@ public class SpellCheckingInspection extends LocalInspectionTool implements Batc if(strategy instanceof SuppressibleSpellcheckingStrategy) { return ((SuppressibleSpellcheckingStrategy)strategy).getSuppressActions(element, getShortName()); } - final InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(language); - if (suppressor != null) { - return suppressor.getSuppressActions(element, getShortName()); - } } - return SuppressQuickFix.EMPTY_ARRAY; + return super.getBatchSuppressActions(element); } private static SpellcheckingStrategy getSpellcheckingStrategy(@NotNull PsiElement element, @NotNull Language language) { @@ -90,8 +86,7 @@ public class SpellCheckingInspection extends LocalInspectionTool implements Batc if (strategy instanceof SuppressibleSpellcheckingStrategy) { return ((SuppressibleSpellcheckingStrategy)strategy).isSuppressedFor(element, getShortName()); } - final InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(language); - return suppressor != null && suppressor.isSuppressedFor(element, getShortName()); + return super.isSuppressedFor(element); } @Override diff --git a/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java b/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java index 9521814649e2..2a942b9f56af 100644 --- a/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java +++ b/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java @@ -26,25 +26,14 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class XmlSuppressableInspectionTool extends LocalInspectionTool implements BatchSuppressableTool { +public abstract class XmlSuppressableInspectionTool extends LocalInspectionTool { @NonNls static final String ALL = "ALL"; - @NotNull - @Override - public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { - return getSuppressFixes(getID()); - } - public static SuppressQuickFix[] getSuppressFixes(final String shortName) { final String id = HighlightDisplayKey.find(shortName).getID(); return new SuppressQuickFix[]{new SuppressTagStatic(id), new SuppressForFile(id), new SuppressAllForFile()}; } - @Override - public boolean isSuppressedFor(@NotNull final PsiElement element) { - return XmlSuppressionProvider.isSuppressed(element, getID()); - } - public class SuppressTag extends SuppressTagStatic { public SuppressTag() { super(getID());