JetCoreEnvironment for JS and JVM are separated.
This commit is contained in:
@@ -51,7 +51,7 @@ public class BytecodeCompiler {
|
||||
*/
|
||||
private CompileEnvironmentConfiguration env( String stdlib, String[] classpath ) {
|
||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
||||
CompileEnvironmentConfiguration env = new CompileEnvironmentConfiguration(environment, dependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||
|
||||
if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
PrintingMessageCollector messageCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
||||
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, dependencies);
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies);
|
||||
CompileEnvironmentConfiguration configuration =
|
||||
new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Processor;
|
||||
import jet.modules.AllModules;
|
||||
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.codegen.ClassFileFactory;
|
||||
@@ -157,7 +158,7 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
};
|
||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
||||
JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.getCoreEnvironmentForJVM(disposable, dependencies);
|
||||
ensureRuntime(scriptEnvironment, dependencies);
|
||||
scriptEnvironment.addSources(moduleScriptFile);
|
||||
|
||||
@@ -337,4 +338,21 @@ public class CompileEnvironmentUtil {
|
||||
addToClasspath(environment, new File(path));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSourcesFromModuleToEnvironment(@NotNull JetCoreEnvironment environment,
|
||||
@NotNull Module module,
|
||||
@NotNull File moduleDirectory) {
|
||||
for (String sourceFile : module.getSourceFiles()) {
|
||||
File source = new File(sourceFile);
|
||||
if (!source.isAbsolute()) {
|
||||
source = new File(moduleDirectory, sourceFile);
|
||||
}
|
||||
|
||||
if (!source.exists()) {
|
||||
throw new CompileEnvironmentException("'" + source + "' does not exist");
|
||||
}
|
||||
|
||||
environment.addSources(source.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
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;
|
||||
@@ -38,16 +39,43 @@ 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 = new ArrayList<JetFile>();
|
||||
private final List<JetFile> sourceFiles = Lists.newArrayList();
|
||||
|
||||
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerDependencies compilerDependencies) {
|
||||
|
||||
@NotNull
|
||||
public static JetCoreEnvironment getCoreEnvironmentForJVM(@NotNull Disposable disposable,
|
||||
@NotNull CompilerDependencies compilerDependencies) {
|
||||
JetCoreEnvironment coreEnvironment = new JetCoreEnvironment(disposable);
|
||||
|
||||
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) {
|
||||
super(parentDisposable);
|
||||
registerFileType(JetFileType.INSTANCE, "kt");
|
||||
registerFileType(JetFileType.INSTANCE, "kts");
|
||||
@@ -62,21 +90,6 @@ 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()) {
|
||||
for (VirtualFile root : compilerDependencies.getRuntimeRoots()) {
|
||||
addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
|
||||
JetStandardLibrary.initialize(getProject());
|
||||
}
|
||||
|
||||
@@ -85,7 +98,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) {
|
||||
@@ -97,7 +110,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);
|
||||
}
|
||||
}
|
||||
@@ -105,7 +118,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
}
|
||||
|
||||
public void addSources(VirtualFile vFile) {
|
||||
if (vFile.isDirectory()) {
|
||||
if (vFile.isDirectory()) {
|
||||
for (VirtualFile virtualFile : vFile.getChildren()) {
|
||||
addSources(virtualFile);
|
||||
}
|
||||
@@ -121,8 +134,9 @@ 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) {
|
||||
@@ -141,14 +155,16 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-12
@@ -67,18 +67,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
throw new CompileEnvironmentException("No source files where defined");
|
||||
}
|
||||
|
||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||
File source = new File(sourceFile);
|
||||
if (!source.isAbsolute()) {
|
||||
source = new File(directory, sourceFile);
|
||||
}
|
||||
|
||||
if (!source.exists()) {
|
||||
throw new CompileEnvironmentException("'" + source + "' does not exist");
|
||||
}
|
||||
|
||||
configuration.getEnvironment().addSources(source.getPath());
|
||||
}
|
||||
CompileEnvironmentUtil.addSourcesFromModuleToEnvironment(configuration.getEnvironment(), moduleBuilder, directory);
|
||||
for (String classpathRoot : moduleBuilder.getClasspathRoots()) {
|
||||
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -163,7 +163,9 @@ public class JetTestUtils {
|
||||
|
||||
public static AnalyzeExhaust analyzeFile(@NotNull JetFile namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(namespace, flowDataTraceFactory,
|
||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, true));
|
||||
CompileCompilerDependenciesTest
|
||||
.compilerDependenciesForTests(CompilerSpecialMode.REGULAR,
|
||||
true));
|
||||
}
|
||||
|
||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
||||
@@ -171,7 +173,8 @@ public class JetTestUtils {
|
||||
}
|
||||
|
||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable, @NotNull CompilerSpecialMode compilerSpecialMode) {
|
||||
return new JetCoreEnvironment(disposable, CompileCompilerDependenciesTest.compilerDependenciesForTests(compilerSpecialMode, true));
|
||||
return JetCoreEnvironment.getCoreEnvironmentForJVM(disposable, CompileCompilerDependenciesTest
|
||||
.compilerDependenciesForTests(compilerSpecialMode, true));
|
||||
}
|
||||
|
||||
public static File findMockJdkRtJar() {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class CompileTextTest extends CodegenTestCase {
|
||||
public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()";
|
||||
CompilerDependencies dependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false);
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
||||
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||
configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader());
|
||||
ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text);
|
||||
|
||||
Reference in New Issue
Block a user