mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
InspectionMappingConsistency inspection
This commit is contained in:
@@ -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<TextRange,PsiElement> 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<TextRange,PsiElement> range = DomUtil.getProblemRange(element.getXmlTag());
|
||||
holder.registerProblem(range.second, range.first, "Bundle should be specified");
|
||||
}
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
foo=bar
|
||||
@@ -0,0 +1,18 @@
|
||||
<idea-plugin version="2">
|
||||
|
||||
<id>com.intellij</id>
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="localInspection"
|
||||
beanClass="com.intellij.codeInspection.LocalInspectionEP"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<<warning descr="Bundle should be specified">localInspection</warning> key="foo"/>
|
||||
<<warning descr="Bundle should be specified">localInspection</warning> groupKey="foo"/>
|
||||
<<warning descr="Bundle should be specified">localInspection</warning> key="foo" groupBundle="bundle"/>
|
||||
|
||||
<localInspection key="foo" bundle="bundle"/>
|
||||
<localInspection groupKey="foo" bundle="bundle"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user