From e6f36e8dbc84b3eafe8f698cd7b9e352f3a0a735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Fri, 4 Mar 2016 12:39:42 +0100 Subject: [PATCH] IDEA-139173 DevKit: highlight unresolved icon references plugin.xml: action/group@icon --- .../inspections/PluginXmlDomInspection.java | 45 +++++++++++++++---- .../testData/codeInsight/iconAttribute.xml | 8 ++++ .../PluginXmlFunctionalTest.groovy | 3 ++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/plugins/devkit/src/inspections/PluginXmlDomInspection.java b/plugins/devkit/src/inspections/PluginXmlDomInspection.java index 7be52e2413dd..9bba54e95d26 100644 --- a/plugins/devkit/src/inspections/PluginXmlDomInspection.java +++ b/plugins/devkit/src/inspections/PluginXmlDomInspection.java @@ -79,6 +79,12 @@ public class PluginXmlDomInspection extends BasicDomElementsInspection iconAttribute = group.getIcon(); + if (DomUtil.hasXml(iconAttribute)) { + annotateResolveProblems(holder, iconAttribute); + } + } + + private static void annotateAction(Action action, DomElementAnnotationHolder holder) { + final GenericAttributeValue 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 diff --git a/plugins/devkit/testData/codeInsight/iconAttribute.xml b/plugins/devkit/testData/codeInsight/iconAttribute.xml index 081e34233920..4deefde84474 100644 --- a/plugins/devkit/testData/codeInsight/iconAttribute.xml +++ b/plugins/devkit/testData/codeInsight/iconAttribute.xml @@ -14,4 +14,12 @@ + + + + + MyIcons.INVALID_VALUE"/> + MyIcons.INVALID_VALUE"/> + + \ No newline at end of file diff --git a/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.groovy b/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.groovy index adb600aa93ee..4f69e47b3f5b 100644 --- a/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.groovy +++ b/plugins/devkit/testSources/codeInsight/PluginXmlFunctionalTest.groovy @@ -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; " +