Ability to use Icon path patchers by 3rd party plugins

This commit is contained in:
Konstantin Bulenkov
2016-09-11 02:34:04 +02:00
parent e50eaf4ea0
commit 65c7695c14
2 changed files with 27 additions and 9 deletions
@@ -184,9 +184,13 @@ public final class IconLoader {
}
@Nullable
public static Icon findIcon(@NotNull String path, @NotNull final Class aClass, boolean computeNow, boolean strict) {
public static Icon findIcon(@NotNull String path, @NotNull Class aClass, boolean computeNow, boolean strict) {
String originalPath = path;
path = patchPath(path);
Pair<String, Class> patchedPath = patchPath(path);
path = patchedPath.first;
if (patchedPath.second != null) {
aClass = patchedPath.second;
}
if (isReflectivePath(path)) return getReflectiveIcon(path, aClass.getClassLoader());
URL myURL = aClass.getResource(path);
@@ -202,14 +206,15 @@ public final class IconLoader {
return icon;
}
private static String patchPath(@NotNull String path) {
@NotNull
private static Pair<String, Class> patchPath(@NotNull String path) {
for (IconPathPatcher patcher : ourPatchers) {
String newPath = patcher.patchPath(path);
if (newPath != null) {
path = newPath;
return Pair.create(newPath, patcher.getContextClass(path));
}
}
return path;
return Pair.create(path, null);
}
private static boolean isReflectivePath(@NotNull String path) {
@@ -240,7 +245,11 @@ public final class IconLoader {
@Nullable
public static Icon findIcon(@NotNull String path, @NotNull ClassLoader classLoader) {
String originalPath = path;
path = patchPath(path);
Pair<String, Class> patchedPath = patchPath(path);
path = patchedPath.first;
if (patchedPath.second != null) {
classLoader = patchedPath.second.getClassLoader();
}
if (isReflectivePath(path)) return getReflectiveIcon(path, classLoader);
if (!StringUtil.startsWithChar(path, '/')) return null;
@@ -389,8 +398,12 @@ public final class IconLoader {
myScaledIconsCache.clear();
if (numberOfPatchers != ourPatchers.size()) {
numberOfPatchers = ourPatchers.size();
String path = myOriginalPath == null ? null : patchPath(myOriginalPath);
if (myClassLoader != null&& path != null && path.startsWith("/")) {
Pair<String, Class> patchedPath = patchPath(myOriginalPath);
String path = myOriginalPath == null ? null : patchedPath.first;
if (patchedPath.second != null) {
myClassLoader = patchedPath.second.getClassLoader();
}
if (myClassLoader != null && path != null && path.startsWith("/")) {
path = path.substring(1);
final URL url = myClassLoader.getResource(path);
if (url != null) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 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.
@@ -28,4 +28,9 @@ public abstract class IconPathPatcher {
*/
@Nullable
public abstract String patchPath(String path);
@Nullable
public Class getContextClass(String path) {
return null;
}
}