mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-139173 DevKit: highlight unresolved icon references
plugin.xml: action/group@icon
This commit is contained in:
@@ -79,6 +79,12 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
else if (element instanceof AddToGroup) {
|
||||
annotateAddToGroup((AddToGroup)element, holder);
|
||||
}
|
||||
else if (element instanceof Action) {
|
||||
annotateAction((Action)element, holder);
|
||||
}
|
||||
else if (element instanceof Group) {
|
||||
annotateGroup((Group)element, holder);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkJetBrainsPlugin(IdeaPlugin ideaPlugin, DomElementAnnotationHolder holder) {
|
||||
@@ -159,7 +165,9 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
if (vendor != null && PluginManagerMain.isDevelopedByJetBrains(vendor.getValue())) {
|
||||
LocalQuickFix fix = new RemoveDomElementQuickFix(extension);
|
||||
holder.createProblem(extension, ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
"Exceptions from plugins developed by JetBrains are reported via ITNReporter automatically, there is no need to specify it explicitly", null, fix).highlightWholeElement();
|
||||
"Exceptions from plugins developed by JetBrains are reported via ITNReporter automatically," +
|
||||
" there is no need to specify it explicitly",
|
||||
null, fix).highlightWholeElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,14 +180,7 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
|
||||
// IconsReferencesContributor
|
||||
if ("icon".equals(attributeDescription.getXmlElementName())) {
|
||||
final XmlAttributeValue value = attributeValue.getXmlAttributeValue();
|
||||
if (value != null) {
|
||||
for (PsiReference reference : value.getReferences()) {
|
||||
if (reference.resolve() == null) {
|
||||
holder.createResolveProblem(attributeValue, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
annotateResolveProblems(holder, attributeValue);
|
||||
}
|
||||
|
||||
final PsiElement declaration = attributeDescription.getDeclaration(extension.getManager().getProject());
|
||||
@@ -226,6 +227,32 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection<IdeaPlugi
|
||||
holder.createProblem(addToGroup.getAnchor(), "Must use '" + Anchor.after + "'|'" + Anchor.before + "' with 'relative-to-action'");
|
||||
}
|
||||
|
||||
private static void annotateGroup(Group group, DomElementAnnotationHolder holder) {
|
||||
final GenericAttributeValue<String> iconAttribute = group.getIcon();
|
||||
if (DomUtil.hasXml(iconAttribute)) {
|
||||
annotateResolveProblems(holder, iconAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateAction(Action action, DomElementAnnotationHolder holder) {
|
||||
final GenericAttributeValue<String> iconAttribute = action.getIcon();
|
||||
if (DomUtil.hasXml(iconAttribute)) {
|
||||
annotateResolveProblems(holder, iconAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotateResolveProblems(DomElementAnnotationHolder holder, GenericAttributeValue attributeValue) {
|
||||
final XmlAttributeValue value = attributeValue.getXmlAttributeValue();
|
||||
if (value != null) {
|
||||
for (PsiReference reference : value.getReferences()) {
|
||||
if (reference.resolve() == null) {
|
||||
holder.createResolveProblem(attributeValue, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class SpecifyJetBrainsAsVendorQuickFix implements LocalQuickFix {
|
||||
@Nls
|
||||
@NotNull
|
||||
|
||||
@@ -14,4 +14,12 @@
|
||||
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action id="validIcon" class="foo.FooAction" icon="MyIcons.MyCustomIcon"/>
|
||||
<group icon="MyIcons.MyCustomIcon"/>
|
||||
|
||||
<action id="invalidIcon" class="foo.FooAction" icon="<error descr="Cannot resolve symbol 'MyIcons.INVALID_VALUE'">MyIcons.INVALID_VALUE</error>"/>
|
||||
<group icon="<error descr="Cannot resolve symbol 'MyIcons.INVALID_VALUE'">MyIcons.INVALID_VALUE</error>"/>
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
||||
@@ -285,6 +285,9 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testIconAttribute() {
|
||||
myFixture.addClass("package com.intellij.openapi.actionSystem; public class AnAction { }");
|
||||
myFixture.addClass("package foo; public class FooAction extends com.intellij.openapi.actionSystem.AnAction { }");
|
||||
|
||||
myFixture.addClass("package icons; " +
|
||||
"public class MyIcons {" +
|
||||
" public static final javax.swing.Icon MyCustomIcon = null; " +
|
||||
|
||||
Reference in New Issue
Block a user