Revert: Improve class loading in GroovyMethodInfo. (cf9bf0e)

This commit is contained in:
Sergey Evdokimov
2011-11-02 11:08:50 +03:00
parent 3fa3c88c85
commit 8be8400161
@@ -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;
}
}