From b7323a76f923b8971152dad2d23a35fb0ee59b53 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 11 Oct 2011 13:42:46 +0400 Subject: [PATCH] InspectionMappingConsistency inspection --- ...nspectionMappingConsistencyInspection.java | 25 +++++++++++++------ .../testData/codeInsight/bundle.properties | 1 + .../codeInsight/inspectionMapping.xml | 18 +++++++++++++ .../codeInsight/PluginXmlFunctionalTest.java | 25 ++++++++++++++----- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 plugins/devkit/testData/codeInsight/bundle.properties create mode 100644 plugins/devkit/testData/codeInsight/inspectionMapping.xml diff --git a/plugins/devkit/src/inspections/InspectionMappingConsistencyInspection.java b/plugins/devkit/src/inspections/InspectionMappingConsistencyInspection.java index b601932ab5d7..2da0d036763d 100644 --- a/plugins/devkit/src/inspections/InspectionMappingConsistencyInspection.java +++ b/plugins/devkit/src/inspections/InspectionMappingConsistencyInspection.java @@ -49,14 +49,17 @@ public class InspectionMappingConsistencyInspection extends DevKitInspectionBase DomElement element = DomUtil.getDomElement(tag); if (element instanceof Extension) { ExtensionPoint target = ((Extension)element).getExtensionPoint(); - if (InheritanceUtil.isInheritor(target.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) { - if (tag.getAttribute("key") != null || tag.getAttribute("bundleKey") != null) { + if (target != null && InheritanceUtil.isInheritor(target.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) { + boolean key = tag.getAttribute("key") != null; + boolean groupKey = tag.getAttribute("groupKey") != null; + if (key) { + if (tag.getAttribute("bundle") == null) { + checkDefaultBundle(element, holder); + } + } + if (groupKey) { if (tag.getAttribute("bundle") == null && tag.getAttribute("groupBundle") == null) { - IdeaPlugin plugin = DomUtil.getParentOfType(element, IdeaPlugin.class, true); - if (plugin != null && plugin.getResourceBundles().isEmpty()) { - Pair range = DomUtil.getProblemRange(element.getXmlTag()); - holder.registerProblem(range.second, range.first, "Bundle should be specified"); - } + checkDefaultBundle(element, holder); } } } @@ -65,6 +68,14 @@ public class InspectionMappingConsistencyInspection extends DevKitInspectionBase }; } + private static void checkDefaultBundle(DomElement element, ProblemsHolder holder) { + IdeaPlugin plugin = DomUtil.getParentOfType(element, IdeaPlugin.class, true); + if (plugin != null && plugin.getResourceBundles().isEmpty()) { + Pair range = DomUtil.getProblemRange(element.getXmlTag()); + holder.registerProblem(range.second, range.first, "Bundle should be specified"); + } + } + @Nls @NotNull @Override diff --git a/plugins/devkit/testData/codeInsight/bundle.properties b/plugins/devkit/testData/codeInsight/bundle.properties new file mode 100644 index 000000000000..c9f0304f65e5 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/bundle.properties @@ -0,0 +1 @@ +foo=bar \ No newline at end of file diff --git a/plugins/devkit/testData/codeInsight/inspectionMapping.xml b/plugins/devkit/testData/codeInsight/inspectionMapping.xml new file mode 100644 index 000000000000..8fb30e4e1c29 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/inspectionMapping.xml @@ -0,0 +1,18 @@ + + + com.intellij + + + + + + + <localInspection key="foo"/> + <localInspection groupKey="foo"/> + <localInspection key="foo" groupBundle="bundle"/> + + + + + \ No newline at end of file diff --git a/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.java b/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.java index 92924032ab86..229aab4533fc 100644 --- a/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.java +++ b/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.java @@ -15,8 +15,8 @@ */ package org.jetbrains.idea.devkit.codeInsight; -import com.intellij.codeInsight.TargetElementUtil; import com.intellij.codeInsight.TargetElementUtilBase; +import com.intellij.codeInspection.LocalInspectionEP; import com.intellij.codeInspection.internal.InternalInspectionToolsProvider; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.application.Result; @@ -24,17 +24,16 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.psi.ElementDescriptionUtil; import com.intellij.psi.PsiElement; import com.intellij.testFramework.PsiTestUtil; +import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; import com.intellij.testFramework.fixtures.TempDirTestFixture; import com.intellij.usageView.UsageViewNodeTextLocation; import com.intellij.usageView.UsageViewTypeLocation; import com.intellij.util.ArrayUtil; +import com.intellij.util.PathUtil; import com.intellij.util.xml.DeprecatedClassUsageInspection; -import org.jetbrains.idea.devkit.inspections.ComponentNotRegisteredInspection; -import org.jetbrains.idea.devkit.inspections.InspectionDescriptionNotFoundInspection; -import org.jetbrains.idea.devkit.inspections.IntentionDescriptionNotFoundInspection; -import org.jetbrains.idea.devkit.inspections.PluginXmlDomInspection; +import org.jetbrains.idea.devkit.inspections.*; import java.io.IOException; @@ -160,16 +159,29 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase { public void testExtensionPointPresentation() { myFixture.configureByFile(getTestName(true) + ".xml"); final PsiElement element = - TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED); + TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED); + assert element != null; assertEquals("Extension Point", ElementDescriptionUtil.getElementDescription(element, UsageViewTypeLocation.INSTANCE)); assertEquals("Extension Point bar", ElementDescriptionUtil.getElementDescription(element, UsageViewNodeTextLocation.INSTANCE)); } + public void testInspectionMappingsWithApi() throws Throwable { + myFixture.testHighlighting("inspectionMapping.xml", "bundle.properties"); + } + public void testLoadForDefaultProject() throws Exception { configureByFile(); myFixture.testHighlighting(true, true, true); } + @Override + protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { + if (getName().endsWith("WithApi")) { + String pathForClass = PathUtil.getJarPathForClass(LocalInspectionEP.class); + moduleBuilder.addLibrary("lang-api", pathForClass); + } + } + public static Class[] getInspectionClasses() { Class[] result = { //RegistrationProblemsInspection.class, @@ -177,6 +189,7 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase { ComponentNotRegisteredInspection.class, InspectionDescriptionNotFoundInspection.class, IntentionDescriptionNotFoundInspection.class, + InspectionMappingConsistencyInspection.class }; return ArrayUtil.mergeArrays(result, InternalInspectionToolsProvider.getPublicClasses()); }