Got rid of using CompilerDependencies in JetCoreEnvironment. CompilerConfiguration is passed instead.

This commit is contained in:
Evgeny Gerashchenko
2012-07-04 16:25:42 +04:00
parent 044d489c15
commit 6e82ab70bc
13 changed files with 132 additions and 114 deletions
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.cli.jvm;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author Evgeny Gerashchenko
* @since 7/4/12
*/
public class CompilerConfigurationUtl {
// TODO merge with similar K2JVMCompiler method
public static CompilerConfiguration getDefaultConfiguration(@NotNull CompilerSpecialMode compilerSpecialMode) {
List<File> classpath = new ArrayList<File>();
if (compilerSpecialMode.includeJdk()) {
classpath.add(PathUtil.findRtJar());
}
if (compilerSpecialMode.includeKotlinRuntime()) {
classpath.add(PathUtil.getDefaultRuntimePath());
}
File[] annotationsPath = new File[0];
if (compilerSpecialMode.includeJdkAnnotations()) {
annotationsPath = new File[]{PathUtil.getJdkAnnotationsPath()};
}
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, classpath.toArray(new File[classpath.size()]));
configuration.putUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, annotationsPath);
return configuration;
}
}
@@ -55,36 +55,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
@Override
@NotNull
protected ExitCode doExecute(K2JVMCompilerArguments arguments, PrintingMessageCollector messageCollector, Disposable rootDisposable) {
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
File jdkAnnotationsJar;
if (mode.includeJdkAnnotations()) {
if (arguments.jdkAnnotations != null) {
jdkAnnotationsJar = new File(arguments.jdkAnnotations);
}
else {
jdkAnnotationsJar = PathUtil.getJdkAnnotationsPath();
}
}
else {
jdkAnnotationsJar = null;
}
File runtimeJar;
if (mode.includeKotlinRuntime()) {
if (arguments.stdlib != null) {
runtimeJar = new File(arguments.stdlib);
}
else {
runtimeJar = PathUtil.getDefaultRuntimePath();
}
}
else {
runtimeJar = null;
}
// will be ignored later
CompilerDependencies dependencies = new CompilerDependencies(mode, PathUtil.findRtJar(), jdkAnnotationsJar, runtimeJar);
CompilerConfiguration compilerConfiguration = createCompilerConfiguration(arguments);
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
if (!arguments.script &&
@@ -93,12 +65,13 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
arguments.freeArgs.isEmpty() &&
(argumentsSourceDirs == null || argumentsSourceDirs.size() == 0)) {
ReplFromTerminal.run(rootDisposable, dependencies, createCompilerConfiguration(arguments));
ReplFromTerminal.run(rootDisposable, compilerConfiguration, mode);
return ExitCode.OK;
}
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, dependencies);
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(environment, messageCollector, arguments.script);
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, compilerConfiguration, mode);
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(environment, messageCollector,
arguments.script);
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
CompilerMessageLocation.NO_LOCATION);
@@ -27,13 +27,14 @@ import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.CompilerConfigurationUtl;
import org.jetbrains.jet.codegen.ClassFileFactory;
import org.jetbrains.jet.codegen.GeneratedClassLoader;
import org.jetbrains.jet.codegen.GenerationState;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
@@ -139,8 +140,8 @@ public class CompileEnvironmentUtil {
}
};
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(disposable, dependencies);
CompilerConfiguration configuration = CompilerConfigurationUtl.getDefaultConfiguration(CompilerSpecialMode.REGULAR);
JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(disposable, configuration, CompilerSpecialMode.REGULAR);
scriptEnvironment.addSources(moduleScriptFile);
GenerationState generationState = KotlinToJVMBytecodeCompiler
@@ -32,7 +32,6 @@ import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.parsing.JetParser;
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import org.jetbrains.jet.lang.resolve.java.extAnnotations.CoreAnnotationsProvider;
@@ -56,21 +55,23 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
@NotNull
public static JetCoreEnvironment createCoreEnvironmentForJS(Disposable disposable) {
return new JetCoreEnvironment(disposable, CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.JS));
return new JetCoreEnvironment(disposable, new CompilerConfiguration(), CompilerSpecialMode.JS);
}
@NotNull
public static JetCoreEnvironment createCoreEnvironmentForJVM(Disposable disposable, @NotNull CompilerDependencies dependencies) {
return new JetCoreEnvironment(disposable, dependencies);
public static JetCoreEnvironment createCoreEnvironmentForJVM(Disposable disposable, @NotNull CompilerConfiguration configuration,
@NotNull CompilerSpecialMode compilerSpecialMode) {
return new JetCoreEnvironment(disposable, configuration, compilerSpecialMode);
}
@NotNull
private final CompilerSpecialMode compilerSpecialMode;
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerDependencies compilerDependencies) {
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerConfiguration configuration,
@NotNull CompilerSpecialMode compilerSpecialMode) {
super(parentDisposable);
this.compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
this.compilerSpecialMode = compilerSpecialMode;
registerFileType(JetFileType.INSTANCE, "kt");
registerFileType(JetFileType.INSTANCE, "kts");
@@ -86,24 +87,10 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
.getExtensionPoint(PsiElementFinder.EP_NAME)
.registerExtension(new JavaElementFinder(myProject));
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
if (compilerSpecialMode.includeJdk()) {
addToClasspath(compilerDependencies.getJdkJar());
}
annotationsProvider = new CoreAnnotationsProvider();
if (compilerSpecialMode.includeJdkAnnotations()) {
for (VirtualFile root : compilerDependencies.getJdkAnnotationsRoots()) {
annotationsProvider.addExternalAnnotationsRoot(root);
}
}
myProject.registerService(ExternalAnnotationsProvider.class, annotationsProvider);
if (compilerSpecialMode.includeKotlinRuntime()) {
addToClasspath(compilerDependencies.getRuntimeJar());
}
configure(configuration);
JetStandardLibrary.initialize(getProject());
}
@@ -196,12 +183,15 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
public void configure(@NotNull CompilerConfiguration compilerConfiguration) {
File[] classpath = compilerConfiguration.getUserData(JVMConfigurationKeys.CLASSPATH_KEY);
File[] annotationsPath = compilerConfiguration.getUserData(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY);
assert classpath != null && annotationsPath != null;
for (File path : classpath) {
addToClasspath(path);
if (classpath != null) {
for (File path : classpath) {
addToClasspath(path);
}
}
for (File path : annotationsPath) {
addExternalAnnotationsRoot(PathUtil.jarFileOrDirectoryToVirtualFile(path));
if (annotationsPath != null) {
for (File path : annotationsPath) {
addExternalAnnotationsRoot(PathUtil.jarFileOrDirectoryToVirtualFile(path));
}
}
}
}
@@ -23,6 +23,7 @@ import jline.console.history.FileHistory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.utils.ExceptionUtils;
import java.io.File;
@@ -43,13 +44,13 @@ public class ReplFromTerminal {
public ReplFromTerminal(
@NotNull final Disposable disposable,
@NotNull final CompilerDependencies compilerDependencies,
@NotNull final CompilerConfiguration compilerConfiguration) {
@NotNull final CompilerConfiguration compilerConfiguration,
@NotNull final CompilerSpecialMode mode) {
new Thread("initialize-repl") {
@Override
public void run() {
try {
replInterpreter = new ReplInterpreter(disposable, compilerDependencies, compilerConfiguration);
replInterpreter = new ReplInterpreter(disposable, compilerConfiguration, mode);
} catch (Throwable e) {
replInitializationFailed = e;
}
@@ -195,9 +196,9 @@ public class ReplFromTerminal {
return Arrays.asList(command.split(" "));
}
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies,
@NotNull CompilerConfiguration compilerConfiguration) {
new ReplFromTerminal(disposable, compilerDependencies, compilerConfiguration).doRun();
public static void run(@NotNull Disposable disposable, @NotNull CompilerConfiguration configuration,
@NotNull CompilerSpecialMode mode) {
new ReplFromTerminal(disposable, configuration, mode).doRun();
}
}
@@ -45,13 +45,8 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.NamespaceLikeBuilderDummy;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.ScriptHeaderResolver;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -94,9 +89,8 @@ public class ReplInterpreter {
@NotNull
private final ModuleDescriptor module;
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies,
@NotNull CompilerConfiguration configuration) {
jetCoreEnvironment = new JetCoreEnvironment(disposable, compilerDependencies);
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerConfiguration configuration, @NotNull CompilerSpecialMode mode) {
jetCoreEnvironment = new JetCoreEnvironment(disposable, configuration, mode);
jetCoreEnvironment.configure(configuration);
Project project = jetCoreEnvironment.getProject();
trace = new BindingTraceContext();
@@ -106,8 +100,7 @@ public class ReplInterpreter {
false,
true,
Collections.<AnalyzerScriptParameter>emptyList());
injector = new InjectorForTopDownAnalyzerForJvm(project, topDownAnalysisParameters, trace, module,
compilerDependencies.getCompilerSpecialMode());
injector = new InjectorForTopDownAnalyzerForJvm(project, topDownAnalysisParameters, trace, module, mode);
List<URL> classpath = Lists.newArrayList();