diff --git a/java/java-analysis-api/src/com/intellij/codeInspection/SuppressManager.java b/java/java-analysis-api/src/com/intellij/codeInspection/SuppressManager.java index 2eaa94be3b03..5500f2430e72 100644 --- a/java/java-analysis-api/src/com/intellij/codeInspection/SuppressManager.java +++ b/java/java-analysis-api/src/com/intellij/codeInspection/SuppressManager.java @@ -29,7 +29,7 @@ import com.intellij.psi.PsiLiteralExpression; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; -public abstract class SuppressManager implements BatchSuppressManager { +public abstract class SuppressManager implements BatchSuppressManager, InspectionSuppressor { public static SuppressManager getInstance() { return ServiceManager.getService(SuppressManager.class); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java index 6136e01f85d8..5f8e43d24ef8 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java @@ -37,6 +37,11 @@ public class SuppressManagerImpl extends SuppressManager { return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions); } + @Override + public SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, String toolShortName) { + return createBatchSuppressActions(HighlightDisplayKey.find(toolShortName)); + } + @Override public boolean isSuppressedFor(@NotNull final PsiElement element, final String toolId) { return JavaSuppressionUtil.getElementToolSuppressedIn(element, toolId) != null; diff --git a/java/java-impl/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java b/java/java-impl/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java index ee198727ffa8..0086b72ea0b1 100644 --- a/java/java-impl/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java +++ b/java/java-impl/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java @@ -15,23 +15,20 @@ */ package com.intellij.spellchecker; -import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInspection.BatchSuppressManager; import com.intellij.codeInspection.SuppressManager; -import com.intellij.codeInspection.SuppressQuickFix; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLiteralExpression; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiNamedElement; import com.intellij.psi.javadoc.PsiDocComment; -import com.intellij.spellchecker.tokenizer.SuppressibleSpellcheckingStrategy; +import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; import com.intellij.spellchecker.tokenizer.Tokenizer; import org.jetbrains.annotations.NotNull; /** * @author shkate@jetbrains.com */ -public class JavaSpellcheckingStrategy extends SuppressibleSpellcheckingStrategy { +public class JavaSpellcheckingStrategy extends SpellcheckingStrategy { private final MethodNameTokenizerJava myMethodNameTokenizer = new MethodNameTokenizerJava(); private final DocCommentTokenizer myDocCommentTokenizer = new DocCommentTokenizer(); private final LiteralExpressionTokenizer myLiteralExpressionTokenizer = new LiteralExpressionTokenizer(); @@ -58,14 +55,4 @@ public class JavaSpellcheckingStrategy extends SuppressibleSpellcheckingStrategy return super.getTokenizer(element); } - - @Override - public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) { - return SuppressManager.getInstance().isSuppressedFor(element, name); - } - - @Override - public SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, @NotNull String name) { - return BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(HighlightDisplayKey.find(name)); - } } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionSuppressor.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionSuppressor.java new file mode 100644 index 000000000000..94cd5483b291 --- /dev/null +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionSuppressor.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +public interface InspectionSuppressor { + /** + * @see com.intellij.codeInspection.CustomSuppressableInspectionTool#isSuppressedFor(com.intellij.psi.PsiElement) + */ + boolean isSuppressedFor(@NotNull PsiElement element, String toolId); + + /** + * @see com.intellij.codeInspection.BatchSuppressableTool#getBatchSuppressActions(com.intellij.psi.PsiElement) + */ + SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, String toolShortName); +} diff --git a/platform/analysis-api/src/com/intellij/codeInspection/LanguageInspectionSuppressors.java b/platform/analysis-api/src/com/intellij/codeInspection/LanguageInspectionSuppressors.java new file mode 100644 index 000000000000..52772416dfca --- /dev/null +++ b/platform/analysis-api/src/com/intellij/codeInspection/LanguageInspectionSuppressors.java @@ -0,0 +1,12 @@ +package com.intellij.codeInspection; + +import com.intellij.lang.LanguageExtension; + +public class LanguageInspectionSuppressors extends LanguageExtension { + public static final LanguageInspectionSuppressors INSTANCE = new LanguageInspectionSuppressors(); + + private LanguageInspectionSuppressors() { + super("com.intellij.lang.inspectionSuppressor"); + } + +} \ No newline at end of file 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 aae907de0bc1..a8fe5d27dd16 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,15 +830,27 @@ 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) { - final SuppressQuickFix[] suppressActions = ((BatchSuppressableTool)wrappedTool).getBatchSuppressActions(element); - ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressActions, new Function() { + 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()); + } + } + + if (suppressFixes != null) { + ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressFixes, new Function() { @Override public IntentionAction fun(SuppressQuickFix fix) { return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix); diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java index 51ec4bbc2a1a..249696cd6c3f 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/SuppressionUtil.java @@ -200,6 +200,12 @@ public class SuppressionUtil extends SuppressionUtilCore { 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; diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index f25ff6b67232..609fb81d4523 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -147,6 +147,11 @@ + + + + diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index d79152d8c54e..9da1e3317e13 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -529,6 +529,7 @@ + diff --git a/plugins/groovy/groovy-psi/src/META-INF/GroovyPlugin.xml b/plugins/groovy/groovy-psi/src/META-INF/GroovyPlugin.xml index 9dadde4b464a..2aa34e020db2 100644 --- a/plugins/groovy/groovy-psi/src/META-INF/GroovyPlugin.xml +++ b/plugins/groovy/groovy-psi/src/META-INF/GroovyPlugin.xml @@ -283,6 +283,7 @@ + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionSuppressor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionSuppressor.java new file mode 100644 index 000000000000..df2288a5159b --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovyInspectionSuppressor.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.codeInspection; + +import com.intellij.codeInspection.InspectionSuppressor; +import com.intellij.codeInspection.SuppressQuickFix; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +public class GroovyInspectionSuppressor implements InspectionSuppressor { + @Override + public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) { + return GroovySuppressableInspectionTool.getElementToolSuppressedIn(element, name) != null; + } + + @Override + public SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, String toolShortName) { + return GroovySuppressableInspectionTool.getSuppressActions(toolShortName); + } +} + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/spellchecker/GroovySpellcheckingStrategy.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/spellchecker/GroovySpellcheckingStrategy.java index f252ee8869ef..9bc67a4355d0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/spellchecker/GroovySpellcheckingStrategy.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/spellchecker/GroovySpellcheckingStrategy.java @@ -15,16 +15,14 @@ */ package org.jetbrains.plugins.groovy.codeInspection.spellchecker; -import com.intellij.codeInspection.SuppressQuickFix; import com.intellij.psi.PsiElement; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.spellchecker.inspections.PlainTextSplitter; import com.intellij.spellchecker.tokenizer.EscapeSequenceTokenizer; -import com.intellij.spellchecker.tokenizer.SuppressibleSpellcheckingStrategy; +import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; import com.intellij.spellchecker.tokenizer.TokenConsumer; import com.intellij.spellchecker.tokenizer.Tokenizer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.codeInspection.GroovySuppressableInspectionTool; import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil; @@ -32,7 +30,7 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil; /** * @author peter */ -public class GroovySpellcheckingStrategy extends SuppressibleSpellcheckingStrategy { +public class GroovySpellcheckingStrategy extends SpellcheckingStrategy { private final GrDocCommentTokenizer myDocCommentTokenizer = new GrDocCommentTokenizer(); private final Tokenizer myStringTokenizer = new Tokenizer() { @Override @@ -66,14 +64,4 @@ public class GroovySpellcheckingStrategy extends SuppressibleSpellcheckingStrate //if (element instanceof GrLiteralImpl && ((GrLiteralImpl)element).isStringLiteral()) return myStringTokenizer; return super.getTokenizer(element); } - - @Override - public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) { - return GroovySuppressableInspectionTool.getElementToolSuppressedIn(element, name) != null; - } - - @Override - public SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, @NotNull String name) { - return GroovySuppressableInspectionTool.getSuppressActions(name); - } } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index b91a5e6f1683..4c8b217d526d 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -1516,6 +1516,7 @@ + diff --git a/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java b/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java index c27047c96308..fefddce8dfb9 100644 --- a/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java +++ b/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java @@ -61,10 +61,15 @@ public class SpellCheckingInspection extends LocalInspectionTool implements Batc @Override public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { if (element != null) { - SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, element.getLanguage()); + final Language language = element.getLanguage(); + SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, language); 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; } @@ -80,9 +85,13 @@ public class SpellCheckingInspection extends LocalInspectionTool implements Batc @Override public boolean isSuppressedFor(@NotNull PsiElement element) { - SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, element.getLanguage()); - return strategy instanceof SuppressibleSpellcheckingStrategy && - ((SuppressibleSpellcheckingStrategy)strategy).isSuppressedFor(element, getShortName()); + final Language language = element.getLanguage(); + SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, language); + if (strategy instanceof SuppressibleSpellcheckingStrategy) { + return ((SuppressibleSpellcheckingStrategy)strategy).isSuppressedFor(element, getShortName()); + } + final InspectionSuppressor suppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(language); + return suppressor != null && suppressor.isSuppressedFor(element, getShortName()); } @Override diff --git a/xml/xml-psi-api/src/com/intellij/codeInspection/XmlInspectionSuppressor.java b/xml/xml-psi-api/src/com/intellij/codeInspection/XmlInspectionSuppressor.java new file mode 100644 index 000000000000..1ddc7f667ab6 --- /dev/null +++ b/xml/xml-psi-api/src/com/intellij/codeInspection/XmlInspectionSuppressor.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +public class XmlInspectionSuppressor implements InspectionSuppressor{ + @Override + public boolean isSuppressedFor(@NotNull PsiElement element, String toolId) { + return XmlSuppressionProvider.isSuppressed(element, toolId); + } + + @Override + public SuppressQuickFix[] getSuppressActions(@NotNull PsiElement element, String toolShortName) { + return XmlSuppressableInspectionTool.getSuppressFixes(toolShortName); + } +} 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 5292a1ac6af1..9521814649e2 100644 --- a/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java +++ b/xml/xml-psi-api/src/com/intellij/codeInspection/XmlSuppressableInspectionTool.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection; +import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -31,7 +32,12 @@ public abstract class XmlSuppressableInspectionTool extends LocalInspectionTool @NotNull @Override public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) { - return new SuppressQuickFix[]{new SuppressTag(), new SuppressForFile(getID()), new SuppressAllForFile()}; + 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