[devkit] IJPL-115197 Provide distinct icon for V2 plugin.xml

GitOrigin-RevId: 400aaa59a3f796dc275171c10b48271bf6438d7e
This commit is contained in:
Yann Cébron
2024-06-25 10:35:21 +00:00
committed by intellij-monorepo-bot
parent 2221c4c6a8
commit 3782dc0da3
5 changed files with 66 additions and 8 deletions
@@ -27,6 +27,12 @@ public interface IdeaPlugin extends DomElement {
return pluginId != null && !pluginId.equals(PluginManagerCore.CORE_PLUGIN_ID);
}
default boolean isV2Descriptor() {
return DomUtil.hasXml(getPackage()) ||
DomUtil.hasXml(getContent()) ||
DomUtil.hasXml(getDependencies());
}
@SubTag("product-descriptor")
@NotNull ProductDescriptor getProductDescriptor();
@@ -1,10 +1,15 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.devkit.dom.impl;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.Iconable;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.xml.DomFileDescription;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.DevKitIcons;
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
import org.jetbrains.idea.devkit.util.DescriptorUtil;
import javax.swing.*;
@@ -15,8 +20,14 @@ final class PluginDescriptorDomFileDescription extends DomFileDescription<IdeaPl
}
@Override
public Icon getFileIcon(@Iconable.IconFlags int flags) {
public @Nullable Icon getFileIcon(@NotNull XmlFile file, @Iconable.IconFlags int flags) {
IdeaPlugin ideaPlugin = DescriptorUtil.getIdeaPlugin(file);
if (ideaPlugin == null) return null;
if (ideaPlugin.isV2Descriptor()) {
return DevKitIcons.PluginV2;
}
return AllIcons.Nodes.Plugin;
}
}
@@ -0,0 +1,34 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.devkit.descriptor
import com.intellij.icons.AllIcons
import com.intellij.psi.PsiElement
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.ui.IconTestUtil
import com.intellij.util.PsiIconUtil
import org.jetbrains.idea.devkit.DevKitIcons
import javax.swing.Icon
internal class PluginDescriptorTest : LightJavaCodeInsightFixtureTestCase() {
fun testPluginDescriptorFileIcon() {
val pluginXml = myFixture.configureByText("plugin.xml", "<idea-plugin></idea-plugin>")
assertPsiIcon(pluginXml, AllIcons.Nodes.Plugin)
val v2PluginXmlPackage = myFixture.configureByText("plugin_v2.xml", "<idea-plugin package=\"dummy\"></idea-plugin>")
assertPsiIcon(v2PluginXmlPackage, DevKitIcons.PluginV2)
val v2PluginXmlContent = myFixture.configureByText("plugin_v2.xml", "<idea-plugin><content/></idea-plugin>")
assertPsiIcon(v2PluginXmlContent, DevKitIcons.PluginV2)
val v2PluginXmlDependencies = myFixture.configureByText("plugin_v2.xml", "<idea-plugin><dependencies/></idea-plugin>")
assertPsiIcon(v2PluginXmlDependencies, DevKitIcons.PluginV2)
}
private fun assertPsiIcon(psiElement: PsiElement, expectedIcon: Icon) {
val iconFromProviders = PsiIconUtil.getIconFromProviders(psiElement, 0)
assertNotNull(iconFromProviders)
val unwrapIcon = IconTestUtil.unwrapIcon(iconFromProviders!!)
assertEquals(expectedIcon, unwrapIcon)
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.xml;
import com.intellij.ide.IconProvider;
@@ -57,8 +57,8 @@ final class DomFileIconProvider extends IconProvider {
@Override
public Icon getIcon(@NotNull PsiElement element, int flags) {
if (element instanceof XmlFile) {
DomTag tag = DOM_FILE_DESCRIPTION.getFileData((PsiFile)element);
if (element instanceof XmlFile xmlFile) {
DomTag tag = DOM_FILE_DESCRIPTION.getFileData(xmlFile);
if (tag == null) return null;
DomFileDescription<?> restored = restoreDomFileDescription(tag);
@@ -66,7 +66,7 @@ final class DomFileIconProvider extends IconProvider {
return null;
}
Icon fileIcon = restored.getFileIcon(flags);
Icon fileIcon = restored.getFileIcon(xmlFile, flags);
if (fileIcon != null) {
return IconManager.getInstance().createLayeredIcon(element, fileIcon, ElementBase.transformFlags(element, flags));
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.xml;
import com.intellij.openapi.extensions.ExtensionPointName;
@@ -130,10 +130,17 @@ public class DomFileDescription<T> {
return true;
}
/**
* @see #getFileIcon(XmlFile, int)
*/
public @Nullable Icon getFileIcon(@Iconable.IconFlags int flags) {
return null;
}
public @Nullable Icon getFileIcon(@NotNull XmlFile file, @Iconable.IconFlags int flags) {
return getFileIcon(flags);
}
/**
* The right place to call
* <ul>