mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161489 InspectionDescriptionInfo incorrectly defines shortName if inspection is registered in XML with custom shortName
This commit is contained in:
@@ -159,6 +159,6 @@ no.idea.sdk.version.found=Failed to detect JDK version required for IntelliJ Pla
|
||||
group.PluginDeployActions.text=Plugin Deployment Actions
|
||||
|
||||
error.cannot.resolve.plugin=Cannot resolve plugin {0}
|
||||
create.description.file=Create Description File
|
||||
create.description.file=Create description file {0}
|
||||
select.target.location.of.description=Select target location of {0}
|
||||
serialization.only.member.used.explicitly=Serialization-only member used explicitly
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -15,13 +15,26 @@
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.LocalInspectionEP;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xml.DomFileElement;
|
||||
import com.intellij.util.xml.DomService;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.devkit.dom.Extensions;
|
||||
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
|
||||
import org.jetbrains.idea.devkit.inspections.quickfix.PluginDescriptorChooser;
|
||||
import org.jetbrains.idea.devkit.util.PsiUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InspectionDescriptionInfo {
|
||||
|
||||
private final String myFilename;
|
||||
@@ -40,14 +53,63 @@ public class InspectionDescriptionInfo {
|
||||
DescriptionType.INSPECTION.getClassName().equals(method.getContainingClass().getQualifiedName())) {
|
||||
method = null;
|
||||
}
|
||||
final String filename = method == null ?
|
||||
InspectionProfileEntry.getShortName(psiClass.getName()) :
|
||||
PsiUtil.getReturnedLiteral(method, psiClass);
|
||||
String filename = null;
|
||||
if (method == null) {
|
||||
String className = psiClass.getQualifiedName();
|
||||
if(className != null) {
|
||||
XmlTag tag = findExtensionTag(module, className);
|
||||
if(tag != null) {
|
||||
filename = tag.getAttributeValue("shortName");
|
||||
}
|
||||
}
|
||||
if(filename == null) {
|
||||
filename = InspectionProfileEntry.getShortName(psiClass.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
filename = PsiUtil.getReturnedLiteral(method, psiClass);
|
||||
}
|
||||
|
||||
PsiFile descriptionFile = resolveInspectionDescriptionFile(module, filename);
|
||||
return new InspectionDescriptionInfo(filename, method, descriptionFile);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static XmlTag findExtensionTag(Module module, final String className) {
|
||||
List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, module.getProject(),
|
||||
GlobalSearchScope.projectScope(module.getProject()));
|
||||
elements = ContainerUtil.filter(elements, element -> {
|
||||
VirtualFile virtualFile = element.getFile().getVirtualFile();
|
||||
return virtualFile != null && ProjectRootManager.getInstance(module.getProject()).getFileIndex().isInContent(virtualFile);
|
||||
});
|
||||
|
||||
elements = PluginDescriptorChooser.findAppropriateIntelliJModule(module.getName(), elements);
|
||||
for (DomFileElement<IdeaPlugin> element : elements) {
|
||||
IdeaPlugin ideaPlugin = element.getRootElement();
|
||||
List<Extensions> extensionsList = ideaPlugin.getExtensions();
|
||||
for (Extensions extensions : extensionsList) {
|
||||
String epPrefix = extensions.getEpPrefix();
|
||||
if (epPrefix.equals("com.intellij.")) {
|
||||
XmlTag[] result = {null};
|
||||
extensions.getXmlTag().acceptChildren(new XmlElementVisitor() {
|
||||
@Override
|
||||
public void visitXmlTag(XmlTag tag) {
|
||||
if (className.equals(tag.getAttributeValue("implementationClass")) &&
|
||||
((epPrefix + tag.getName()).equals(InspectionEP.GLOBAL_INSPECTION.getName()) ||
|
||||
(epPrefix + tag.getName()).equals(LocalInspectionEP.LOCAL_INSPECTION.getName()))) {
|
||||
result[0] = tag;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (result[0] != null) {
|
||||
return result[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiFile resolveInspectionDescriptionFile(Module module, @Nullable String filename) {
|
||||
if (filename == null) return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -100,7 +100,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return DevKitBundle.message("create.description.file");
|
||||
return DevKitBundle.message("create.description.file", myFilename);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -61,6 +61,7 @@ public class PluginDescriptorChooser {
|
||||
.put("vcs-impl", "VcsExtensions.xml")
|
||||
.put("openapi", "IdeaPlugin.xml")
|
||||
.put("java-impl", "IdeaPlugin.xml")
|
||||
.put("java-analysis-impl", "IdeaPlugin.xml")
|
||||
.build();
|
||||
|
||||
public static void show(final Project project,
|
||||
@@ -152,14 +153,14 @@ public class PluginDescriptorChooser {
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(currentModule.getProject());
|
||||
final String[] groupPath = moduleManager.getModuleGroupPath(currentModule);
|
||||
|
||||
Collections.sort(elements, (o1, o2) -> {
|
||||
elements.sort((o1, o2) -> {
|
||||
// current module = first group
|
||||
final Module module1 = o1.getModule();
|
||||
final Module module2 = o2.getModule();
|
||||
|
||||
if (currentModule.equals(module1)) return -1;
|
||||
if (currentModule.equals(module2)) return 1;
|
||||
|
||||
|
||||
if (module1 != null && module2 != null) {
|
||||
int groupComparison = Comparing.compare(groupMatchLevel(groupPath, moduleManager.getModuleGroupPath(module2)),
|
||||
groupMatchLevel(groupPath, moduleManager.getModuleGroupPath(module1)));
|
||||
@@ -169,7 +170,7 @@ public class PluginDescriptorChooser {
|
||||
}
|
||||
return ModulesAlphaComparator.INSTANCE.compare(module1, module2);
|
||||
});
|
||||
Collections.sort(elements, (o1, o2) -> {
|
||||
elements.sort((o1, o2) -> {
|
||||
if (!Comparing.equal(o1.getModule(), o2.getModule())) return 0;
|
||||
String pluginId1 = o1.getRootElement().getPluginId();
|
||||
String pluginId2 = o2.getRootElement().getPluginId();
|
||||
@@ -207,7 +208,7 @@ public class PluginDescriptorChooser {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static List<DomFileElement<IdeaPlugin>> findAppropriateIntelliJModule(String moduleName,
|
||||
public static List<DomFileElement<IdeaPlugin>> findAppropriateIntelliJModule(String moduleName,
|
||||
List<DomFileElement<IdeaPlugin>> elements) {
|
||||
String extensionsFile = INTELLIJ_MODULES.get(moduleName);
|
||||
if (extensionsFile != null) {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
|
||||
public class MyRegisteredCorrectlyInspection extends InspectionProfileEntry {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
|
||||
public class <warning descr="Inspection does not have a description">MyRegisteredInspection</warning> extends InspectionProfileEntry {
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
from MyRegisteredInspection
|
||||
+1
@@ -0,0 +1 @@
|
||||
from MyRegisteredCorrectlyInspection
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<idea-plugin version="2">
|
||||
<id>com.intellij.example</id>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MyRegisteredCustomShortName" displayName="Example inspection"
|
||||
groupKey="group.names.probable.bugs" groupBundle="messages.InspectionsBundle" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="MyRegisteredInspection" />
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MyRegisteredCustomName" displayName="Example inspection"
|
||||
groupKey="group.names.probable.bugs" groupBundle="messages.InspectionsBundle" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="MyRegisteredCorrectlyInspection" />
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
+14
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -66,9 +66,21 @@ public class InspectionDescriptionNotFoundInspectionTest extends JavaCodeInsight
|
||||
myFixture.testHighlighting("MyWithDescriptionCustomShortNameInspection.java");
|
||||
}
|
||||
|
||||
public void testWithDescriptionXmlRegisteredNotFound() {
|
||||
myFixture.copyDirectoryToProject("inspectionDescriptions", "inspectionDescriptions");
|
||||
myFixture.copyDirectoryToProject("resources", "resources");
|
||||
myFixture.testHighlighting("MyRegisteredInspection.java");
|
||||
}
|
||||
|
||||
public void testWithDescriptionXmlRegisteredOk() {
|
||||
myFixture.copyDirectoryToProject("inspectionDescriptions", "inspectionDescriptions");
|
||||
myFixture.copyDirectoryToProject("resources", "resources");
|
||||
myFixture.testHighlighting("MyRegisteredCorrectlyInspection.java");
|
||||
}
|
||||
|
||||
public void testQuickFix() {
|
||||
myFixture.configureByFile("MyQuickFixInspection.java");
|
||||
IntentionAction item = myFixture.findSingleIntention("Create Description File");
|
||||
IntentionAction item = myFixture.findSingleIntention("Create description file MyQuickFix.html");
|
||||
myFixture.launchAction(item);
|
||||
|
||||
VirtualFile path = myFixture.findFileInTempDir("inspectionDescriptions/MyQuickFix.html");
|
||||
|
||||
Reference in New Issue
Block a user