mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert: Improve class loading in GroovyMethodInfo. (cf9bf0e)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.jetbrains.plugins.groovy.util;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -13,16 +15,34 @@ public class ClassInstanceCache {
|
||||
private ClassInstanceCache() {
|
||||
}
|
||||
|
||||
private static Object createInstance(@NotNull String className) {
|
||||
try {
|
||||
try {
|
||||
return Class.forName(className).newInstance();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
for (IdeaPluginDescriptor descriptor : PluginManager.getPlugins()) {
|
||||
try {
|
||||
return descriptor.getPluginClassLoader().loadClass(className).newInstance();
|
||||
}
|
||||
catch (ClassNotFoundException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Class not found: " + className);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getInstance(@NotNull String className, ClassLoader classLoader) {
|
||||
Object res = CACHE.get(className);
|
||||
if (res == null) {
|
||||
try {
|
||||
res = classLoader.loadClass(className).newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
res = createInstance(className);
|
||||
|
||||
Object oldValue = CACHE.putIfAbsent(className, res);
|
||||
if (oldValue != null) {
|
||||
@@ -32,4 +52,5 @@ public class ClassInstanceCache {
|
||||
|
||||
return (T)res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user