此类汇集了所有的插件扩展出的IconProvider, 然后进行遍历渲染.
自己的项目可以继承 IconProvider并在项目中声明(注意加order="first", 否则可能没有机会执行):
<iconProvider implementation="io.flutter.project.FlutterIconProvider" order="first"/>
package com.intellij.ide.projectView.impl; import com.intellij.icons.AllIcons; import com.intellij.ide.IconProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.intellij.ui.IconManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.Icon; /** * This class is intended to combine all providers for batch usages. */ public final class CompoundIconProvider extends IconProvider { private static final IconProvider INSTANCE = new CompoundIconProvider(); private static final Logger LOG = Logger.getInstance(CompoundIconProvider.class); @Nullable @Override public Icon getIcon(@NotNull PsiElement element, int flags) { if (element.isValid()) { for (IconProvider provider : EXTENSION_POINT_NAME.getExtensions()) { ProgressManager.checkCanceled(); try { Icon icon = provider.getIcon(element, flags); if (icon != null) { LOG.debug("icon found in ", provider); return icon; } } catch (IndexNotReadyException exception) { throw new ProcessCanceledException(exception); } catch (ProcessCanceledException exception) { throw exception; } catch (Exception exception) { LOG.warn("unexpected error in " + provider, exception); } } return element.getIcon(flags); } return null; } @Nullable public static Icon findIcon(@Nullable PsiElement element, int flags) { return element == null ? null : INSTANCE.getIcon(element, flags); } }