Passing class loader instead of factory to compiler.

This commit is contained in:
Evgeny Gerashchenko
2014-08-12 21:24:34 +04:00
parent e419c1a604
commit 3233317316
6 changed files with 19 additions and 80 deletions
@@ -19,7 +19,6 @@ package org.jetbrains.jet.compiler.runner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.preloading.ClassLoaderFactory;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.PathUtil;
@@ -35,7 +34,7 @@ public final class CompilerEnvironment {
public static CompilerEnvironment getEnvironmentFor(
@NotNull KotlinPaths kotlinPaths,
@Nullable File outputDir,
@Nullable ClassLoaderFactory parentFactory,
@Nullable ClassLoader parentClassLoader,
@NotNull Object... serviceImplementations
) {
Map<Class, Object> servicesMap = new HashMap<Class, Object>();
@@ -44,7 +43,7 @@ public final class CompilerEnvironment {
servicesMap.put(serviceInterface, serviceImplementation);
}
}
return new CompilerEnvironment(kotlinPaths, outputDir, parentFactory, servicesMap);
return new CompilerEnvironment(kotlinPaths, outputDir, parentClassLoader, servicesMap);
}
@NotNull
@@ -52,19 +51,19 @@ public final class CompilerEnvironment {
@Nullable
private final File output;
@Nullable
private final ClassLoaderFactory parentFactory;
private final ClassLoader parentClassLoader;
@NotNull
private final Map<Class, Object> services;
private CompilerEnvironment(
@NotNull KotlinPaths kotlinPaths,
@Nullable File output,
@Nullable ClassLoaderFactory parentFactory,
@Nullable ClassLoader parentClassLoader,
@NotNull Map<Class, Object> services
) {
this.kotlinPaths = kotlinPaths;
this.output = output;
this.parentFactory = parentFactory;
this.parentClassLoader = parentClassLoader;
this.services = services;
}
@@ -84,8 +83,8 @@ public final class CompilerEnvironment {
}
@Nullable
public ClassLoaderFactory getParentFactory() {
return parentFactory;
public ClassLoader getParentClassLoader() {
return parentClassLoader;
}
public void reportErrorsTo(@NotNull MessageCollector messageCollector) {
@@ -20,7 +20,6 @@ import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.preloading.ClassLoaderFactory;
import org.jetbrains.jet.preloading.ClassPreloadingUtils;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -60,14 +59,14 @@ public class CompilerRunnerUtil {
@NotNull
public static ClassLoader getOrCreatePreloader(
@NotNull KotlinPaths paths,
@Nullable ClassLoaderFactory parentFactory,
@Nullable ClassLoader parentClassLoader,
@NotNull MessageCollector messageCollector
) {
ClassLoader answer = ourClassLoaderRef.get();
if (answer == null) {
try {
int estimatedClassNumber = 4096;
answer = ClassPreloadingUtils.preloadClasses(kompilerClasspath(paths, messageCollector), estimatedClassNumber, parentFactory);
answer = ClassPreloadingUtils.preloadClasses(kompilerClasspath(paths, messageCollector), estimatedClassNumber, parentClassLoader);
}
catch (IOException e) {
throw new RuntimeException(e);
@@ -120,7 +119,7 @@ public class CompilerRunnerUtil {
MessageCollector messageCollector, PrintStream out, boolean usePreloader
) throws Exception {
ClassLoader loader = usePreloader
? getOrCreatePreloader(environment.getKotlinPaths(), environment.getParentFactory(), messageCollector)
? getOrCreatePreloader(environment.getKotlinPaths(), environment.getParentClassLoader(), messageCollector)
: getOrCreateClassLoader(environment.getKotlinPaths(), messageCollector);
Class<?> kompiler = Class.forName(compilerClassName, true, loader);