Merge remote-tracking branch 'origin/master'
Conflicts: build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java compiler/tests/org/jetbrains/jet/JetTestUtils.java compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java
This commit is contained in:
@@ -179,8 +179,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
@NotNull K2JVMCompilerArguments arguments) {
|
||||
super.configureEnvironment(configuration, arguments);
|
||||
|
||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
}
|
||||
|
||||
if (arguments.classpath != null) {
|
||||
|
||||
@@ -163,7 +163,7 @@ public class CompileEnvironmentUtil {
|
||||
scriptEnvironment.addSources(moduleScriptFile);
|
||||
|
||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
|
||||
if (generationState == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.cli.jvm.compiler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.core.JavaCoreEnvironment;
|
||||
import com.intellij.lang.java.JavaParserDefinition;
|
||||
import com.intellij.mock.MockApplication;
|
||||
@@ -39,44 +38,23 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
private final List<JetFile> sourceFiles = Lists.newArrayList();
|
||||
|
||||
private final List<JetFile> sourceFiles = new ArrayList<JetFile>();
|
||||
|
||||
@NotNull
|
||||
public static JetCoreEnvironment getCoreEnvironmentForJVM(@NotNull Disposable disposable,
|
||||
@NotNull CompilerDependencies compilerDependencies) {
|
||||
JetCoreEnvironment coreEnvironment = new JetCoreEnvironment(disposable);
|
||||
private final CompilerDependencies compilerDependencies;
|
||||
|
||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||
|
||||
coreEnvironment.addToClasspath(compilerDependencies.getJdkJar());
|
||||
|
||||
if (compilerSpecialMode.includeJdkHeaders()) {
|
||||
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
||||
coreEnvironment.addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
if (compilerSpecialMode.includeKotlinRuntime()) {
|
||||
for (VirtualFile root : compilerDependencies.getRuntimeRoots()) {
|
||||
coreEnvironment.addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
return coreEnvironment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetCoreEnvironment getCoreEnvironmentForJS(@NotNull Disposable disposable) {
|
||||
return new JetCoreEnvironment(disposable);
|
||||
}
|
||||
|
||||
private JetCoreEnvironment(Disposable parentDisposable) {
|
||||
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerDependencies compilerDependencies) {
|
||||
super(parentDisposable);
|
||||
|
||||
this.compilerDependencies = compilerDependencies;
|
||||
|
||||
registerFileType(JetFileType.INSTANCE, "kt");
|
||||
registerFileType(JetFileType.INSTANCE, "kts");
|
||||
registerFileType(JetFileType.INSTANCE, "ktm");
|
||||
@@ -90,6 +68,19 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||
.registerExtension(new JavaElementFinder(myProject));
|
||||
|
||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||
|
||||
addToClasspath(compilerDependencies.getJdkJar());
|
||||
|
||||
if (compilerSpecialMode.includeJdkHeaders()) {
|
||||
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
||||
addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
if (compilerSpecialMode.includeKotlinRuntime()) {
|
||||
addToClasspath(compilerDependencies.getRuntimeJar());
|
||||
}
|
||||
|
||||
JetStandardLibrary.initialize(getProject());
|
||||
}
|
||||
|
||||
@@ -98,7 +89,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
}
|
||||
|
||||
private void addSources(File file) {
|
||||
if (file.isDirectory()) {
|
||||
if(file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
if (files != null) {
|
||||
for (File child : files) {
|
||||
@@ -110,7 +101,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
VirtualFile fileByPath = getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||
if (fileByPath != null) {
|
||||
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(fileByPath);
|
||||
if (psiFile instanceof JetFile) {
|
||||
if(psiFile instanceof JetFile) {
|
||||
sourceFiles.add((JetFile)psiFile);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +109,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
}
|
||||
|
||||
public void addSources(VirtualFile vFile) {
|
||||
if (vFile.isDirectory()) {
|
||||
if (vFile.isDirectory()) {
|
||||
for (VirtualFile virtualFile : vFile.getChildren()) {
|
||||
addSources(virtualFile);
|
||||
}
|
||||
@@ -134,9 +125,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
}
|
||||
|
||||
public void addSources(String path) {
|
||||
if (path == null) {
|
||||
if(path == null)
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualFile vFile = getLocalFileSystem().findFileByPath(path);
|
||||
if (vFile == null) {
|
||||
@@ -155,17 +145,20 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
|
||||
public void addToClasspathFromClassLoader(ClassLoader loader) {
|
||||
ClassLoader parent = loader.getParent();
|
||||
if (parent != null) {
|
||||
if(parent != null)
|
||||
addToClasspathFromClassLoader(parent);
|
||||
}
|
||||
|
||||
if (loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader)loader).getURLs()) {
|
||||
if(loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader) loader).getURLs()) {
|
||||
File file = new File(url.getPath());
|
||||
if (file.exists() && (!file.isFile() || file.getPath().endsWith(".jar"))) {
|
||||
if(file.exists() && (!file.isFile() || file.getPath().endsWith(".jar")))
|
||||
addToClasspath(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompilerDependencies getCompilerDependencies() {
|
||||
return compilerDependencies;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -72,7 +72,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
|
||||
}
|
||||
|
||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
|
||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
|
||||
|
||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||
if (generationState == null) {
|
||||
@@ -93,9 +93,9 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
for (Module moduleBuilder : modules) {
|
||||
// TODO: this should be done only once for the environment
|
||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||
CompileEnvironmentUtil
|
||||
.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
||||
.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
}
|
||||
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
||||
if (moduleFactory == null) {
|
||||
@@ -132,7 +132,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
|
||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
|
||||
|
||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||
if (generationState == null) {
|
||||
@@ -198,7 +198,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@Nullable
|
||||
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
||||
return analyzeAndGenerate(configuration, configuration.getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
||||
return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -233,7 +233,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
|
||||
JetControlFlowDataTraceFactory.EMPTY,
|
||||
configuration.getCompilerDependencies());
|
||||
configuration.getEnvironment().getCompilerDependencies());
|
||||
}
|
||||
}, environment.getSourceFiles()
|
||||
);
|
||||
@@ -256,7 +256,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
};
|
||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
||||
exhaust, environment.getSourceFiles(),
|
||||
configuration.getCompilerDependencies().getCompilerSpecialMode());
|
||||
configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode());
|
||||
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
||||
|
||||
Reference in New Issue
Block a user