Produciton code uses a shared application between many projects.
Tests always dispose the application together with JetCoreEnvironment
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.buildtools.core;
|
package org.jetbrains.jet.buildtools.core;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.io.FileUtilRt;
|
import com.intellij.openapi.util.io.FileUtilRt;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
@@ -65,7 +66,7 @@ public class BytecodeCompiler {
|
|||||||
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] sourceRoots) {
|
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] sourceRoots) {
|
||||||
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourceRoots);
|
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourceRoots);
|
||||||
|
|
||||||
return new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), configuration);
|
return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompilerConfiguration createConfiguration(String stdlib, String[] classpath, String[] sourceRoots) {
|
private CompilerConfiguration createConfiguration(String stdlib, String[] classpath, String[] sourceRoots) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
|
|
||||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(arguments.sourceFiles));
|
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(arguments.sourceFiles));
|
||||||
JetCoreEnvironment environmentForJS = new JetCoreEnvironment(rootDisposable, configuration);
|
JetCoreEnvironment environmentForJS = JetCoreEnvironment.createForProduction(rootDisposable, configuration);
|
||||||
|
|
||||||
Project project = environmentForJS.getProject();
|
Project project = environmentForJS.getProject();
|
||||||
|
|
||||||
|
|||||||
@@ -140,11 +140,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
}
|
}
|
||||||
else if (arguments.script) {
|
else if (arguments.script) {
|
||||||
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
|
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, configuration);
|
JetCoreEnvironment environment = JetCoreEnvironment.createForProduction(rootDisposable, configuration);
|
||||||
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(paths, environment, scriptArgs);
|
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(paths, environment, scriptArgs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, configuration);
|
JetCoreEnvironment environment = JetCoreEnvironment.createForProduction(rootDisposable, configuration);
|
||||||
KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class CompileEnvironmentUtil {
|
|||||||
|
|
||||||
List<Module> modules;
|
List<Module> modules;
|
||||||
try {
|
try {
|
||||||
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, configuration);
|
JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.createForProduction(disposable, configuration);
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(scriptEnvironment);
|
GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(scriptEnvironment);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " analyze failed:\n" +
|
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " analyze failed:\n" +
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.intellij.openapi.components.ServiceManager;
|
|||||||
import com.intellij.openapi.extensions.Extensions;
|
import com.intellij.openapi.extensions.Extensions;
|
||||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiElementFinder;
|
import com.intellij.psi.PsiElementFinder;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
@@ -36,6 +37,7 @@ import com.intellij.psi.PsiManager;
|
|||||||
import com.intellij.psi.impl.compiled.ClsCustomNavigationPolicy;
|
import com.intellij.psi.impl.compiled.ClsCustomNavigationPolicy;
|
||||||
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.jet.CompilerModeProvider;
|
import org.jetbrains.jet.CompilerModeProvider;
|
||||||
import org.jetbrains.jet.OperationModeProvider;
|
import org.jetbrains.jet.OperationModeProvider;
|
||||||
import org.jetbrains.jet.asJava.JavaElementFinder;
|
import org.jetbrains.jet.asJava.JavaElementFinder;
|
||||||
@@ -64,10 +66,50 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.WARN
|
|||||||
|
|
||||||
public class JetCoreEnvironment {
|
public class JetCoreEnvironment {
|
||||||
|
|
||||||
private final JavaCoreApplicationEnvironment applicationEnvironment;
|
private static final Object APPLICATION_LOCK = new Object();
|
||||||
|
private static JavaCoreApplicationEnvironment ourApplicationEnvironment;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JavaCoreApplicationEnvironment initApplication(@NotNull Disposable parentDisposable) {
|
public static JetCoreEnvironment createForProduction(@NotNull Disposable parentDisposable, @NotNull CompilerConfiguration configuration) {
|
||||||
|
return new JetCoreEnvironment(parentDisposable, getOrCreateApplicationEnvironmentForProduction(), configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
@NotNull
|
||||||
|
public static JetCoreEnvironment createForTests(@NotNull Disposable parentDisposable, @NotNull CompilerConfiguration configuration) {
|
||||||
|
return new JetCoreEnvironment(parentDisposable, createApplicationEnvironment(parentDisposable), configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static JavaCoreApplicationEnvironment getOrCreateApplicationEnvironmentForProduction() {
|
||||||
|
synchronized (APPLICATION_LOCK) {
|
||||||
|
if (ourApplicationEnvironment != null) return ourApplicationEnvironment;
|
||||||
|
|
||||||
|
Disposable parentDisposable = Disposer.newDisposable();
|
||||||
|
ourApplicationEnvironment = createApplicationEnvironment(parentDisposable);
|
||||||
|
Disposer.register(parentDisposable, new Disposable() {
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
synchronized (APPLICATION_LOCK) {
|
||||||
|
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||||
|
ourApplicationEnvironment = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ourApplicationEnvironment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disposeApplicationEnvironment() {
|
||||||
|
synchronized (APPLICATION_LOCK) {
|
||||||
|
if (ourApplicationEnvironment == null) return;
|
||||||
|
JavaCoreApplicationEnvironment environment = ourApplicationEnvironment;
|
||||||
|
ourApplicationEnvironment = null;
|
||||||
|
Disposer.dispose(environment.getParentDisposable());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JavaCoreApplicationEnvironment createApplicationEnvironment(Disposable parentDisposable) {
|
||||||
JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(parentDisposable);
|
JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(parentDisposable);
|
||||||
|
|
||||||
// ability to get text from annotations xml files
|
// ability to get text from annotations xml files
|
||||||
@@ -81,6 +123,7 @@ public class JetCoreEnvironment {
|
|||||||
applicationEnvironment.registerParserDefinition(new JetParserDefinition());
|
applicationEnvironment.registerParserDefinition(new JetParserDefinition());
|
||||||
|
|
||||||
applicationEnvironment.getApplication().registerService(OperationModeProvider.class, new CompilerModeProvider());
|
applicationEnvironment.getApplication().registerService(OperationModeProvider.class, new CompilerModeProvider());
|
||||||
|
|
||||||
return applicationEnvironment;
|
return applicationEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,12 +135,14 @@ public class JetCoreEnvironment {
|
|||||||
|
|
||||||
private final CompilerConfiguration configuration;
|
private final CompilerConfiguration configuration;
|
||||||
|
|
||||||
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerConfiguration configuration) {
|
private JetCoreEnvironment(
|
||||||
|
@NotNull Disposable parentDisposable,
|
||||||
|
@NotNull JavaCoreApplicationEnvironment applicationEnvironment,
|
||||||
|
@NotNull CompilerConfiguration configuration
|
||||||
|
) {
|
||||||
this.configuration = configuration.copy();
|
this.configuration = configuration.copy();
|
||||||
this.configuration.setReadOnly(true);
|
this.configuration.setReadOnly(true);
|
||||||
|
|
||||||
this.applicationEnvironment = initApplication(parentDisposable);
|
|
||||||
|
|
||||||
projectEnvironment = new JavaCoreProjectEnvironment(parentDisposable, applicationEnvironment);
|
projectEnvironment = new JavaCoreProjectEnvironment(parentDisposable, applicationEnvironment);
|
||||||
|
|
||||||
MockProject project = projectEnvironment.getProject();
|
MockProject project = projectEnvironment.getProject();
|
||||||
@@ -140,9 +185,14 @@ public class JetCoreEnvironment {
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CoreApplicationEnvironment getMyApplicationEnvironment() {
|
||||||
|
return projectEnvironment.getEnvironment();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public MockApplication getApplication() {
|
public MockApplication getApplication() {
|
||||||
return applicationEnvironment.getApplication();
|
return getMyApplicationEnvironment().getApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -168,7 +218,7 @@ public class JetCoreEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VirtualFile fileByPath = applicationEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
VirtualFile fileByPath = getMyApplicationEnvironment().getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||||
if (fileByPath != null) {
|
if (fileByPath != null) {
|
||||||
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(fileByPath);
|
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(fileByPath);
|
||||||
if (psiFile instanceof JetFile) {
|
if (psiFile instanceof JetFile) {
|
||||||
@@ -183,7 +233,7 @@ public class JetCoreEnvironment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile vFile = applicationEnvironment.getLocalFileSystem().findFileByPath(path);
|
VirtualFile vFile = getMyApplicationEnvironment().getLocalFileSystem().findFileByPath(path);
|
||||||
if (vFile == null) {
|
if (vFile == null) {
|
||||||
report(ERROR, "Source file or directory not found: " + path);
|
report(ERROR, "Source file or directory not found: " + path);
|
||||||
return;
|
return;
|
||||||
@@ -198,7 +248,7 @@ public class JetCoreEnvironment {
|
|||||||
|
|
||||||
private void addToClasspath(File path) {
|
private void addToClasspath(File path) {
|
||||||
if (path.isFile()) {
|
if (path.isFile()) {
|
||||||
VirtualFile jarFile = applicationEnvironment.getJarFileSystem().findFileByPath(path + "!/");
|
VirtualFile jarFile = getMyApplicationEnvironment().getJarFileSystem().findFileByPath(path + "!/");
|
||||||
if (jarFile == null) {
|
if (jarFile == null) {
|
||||||
report(WARNING, "Classpath entry points to a file that is not a JAR archive: " + path);
|
report(WARNING, "Classpath entry points to a file that is not a JAR archive: " + path);
|
||||||
return;
|
return;
|
||||||
@@ -207,7 +257,7 @@ public class JetCoreEnvironment {
|
|||||||
classPath.add(jarFile);
|
classPath.add(jarFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VirtualFile root = applicationEnvironment.getLocalFileSystem().findFileByPath(path.getAbsolutePath());
|
VirtualFile root = getMyApplicationEnvironment().getLocalFileSystem().findFileByPath(path.getAbsolutePath());
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
report(WARNING, "Classpath entry points to a non-existent location: " + path);
|
report(WARNING, "Classpath entry points to a non-existent location: " + path);
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-2
@@ -100,7 +100,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
Disposable parentDisposable = CompileEnvironmentUtil.createMockDisposable();
|
Disposable parentDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||||
JetCoreEnvironment moduleEnvironment = null;
|
JetCoreEnvironment moduleEnvironment = null;
|
||||||
try {
|
try {
|
||||||
moduleEnvironment = new JetCoreEnvironment(parentDisposable, compilerConfiguration);
|
moduleEnvironment = JetCoreEnvironment.createForProduction(parentDisposable, compilerConfiguration);
|
||||||
|
|
||||||
|
|
||||||
GenerationState generationState = analyzeAndGenerate(moduleEnvironment);
|
GenerationState generationState = analyzeAndGenerate(moduleEnvironment);
|
||||||
@@ -338,7 +338,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
scriptDefinitions != null ? scriptDefinitions : Collections.<JetScriptDefinition>emptyList());
|
scriptDefinitions != null ? scriptDefinitions : Collections.<JetScriptDefinition>emptyList());
|
||||||
compilerConfiguration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, scriptParameters);
|
compilerConfiguration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, scriptParameters);
|
||||||
|
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, compilerConfiguration);
|
JetCoreEnvironment environment = JetCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JetScriptDefinitionProvider.getInstance(environment.getProject()).markFileAsScript(environment.getSourceFiles().get(0));
|
JetScriptDefinitionProvider.getInstance(environment.getProject()).markFileAsScript(environment.getSourceFiles().get(0));
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class ReplInterpreter {
|
|||||||
private final ModuleDescriptorImpl module;
|
private final ModuleDescriptorImpl module;
|
||||||
|
|
||||||
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) {
|
public ReplInterpreter(@NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) {
|
||||||
jetCoreEnvironment = new JetCoreEnvironment(disposable, configuration);
|
jetCoreEnvironment = JetCoreEnvironment.createForProduction(disposable, configuration);
|
||||||
Project project = jetCoreEnvironment.getProject();
|
Project project = jetCoreEnvironment.getProject();
|
||||||
trace = new BindingTraceContext();
|
trace = new BindingTraceContext();
|
||||||
module = AnalyzerFacadeForJVM.createJavaModule("<repl>");
|
module = AnalyzerFacadeForJVM.createJavaModule("<repl>");
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import org.jetbrains.jet.lang.diagnostics.Severity;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||||
@@ -241,7 +240,7 @@ public class JetTestUtils {
|
|||||||
@NotNull ConfigurationKind configurationKind,
|
@NotNull ConfigurationKind configurationKind,
|
||||||
@NotNull TestJdkKind jdkKind
|
@NotNull TestJdkKind jdkKind
|
||||||
) {
|
) {
|
||||||
return new JetCoreEnvironment(disposable, compilerConfigurationForTests(
|
return JetCoreEnvironment.createForTests(disposable, compilerConfigurationForTests(
|
||||||
configurationKind, jdkKind, getAnnotationsJar(), getAnnotationsExtJar()));
|
configurationKind, jdkKind, getAnnotationsJar(), getAnnotationsExtJar()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public abstract class KotlinAsJavaTestBase extends KotlinTestWithEnvironment {
|
|||||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, root.getPath());
|
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, root.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<File> getKotlinSourceRoots();
|
protected abstract List<File> getKotlinSourceRoots();
|
||||||
|
|||||||
@@ -71,15 +71,12 @@ public abstract class AbstractJetDiagnosticsTest extends JetLiteFixture {
|
|||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw ExceptionUtils.rethrow(e);
|
throw ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
return new JetCoreEnvironment(
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
getTestRootDisposable(),
|
|
||||||
JetTestUtils.compilerConfigurationForTests(
|
|
||||||
ConfigurationKind.JDK_AND_ANNOTATIONS,
|
ConfigurationKind.JDK_AND_ANNOTATIONS,
|
||||||
TestJdkKind.MOCK_JDK,
|
TestJdkKind.MOCK_JDK,
|
||||||
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
||||||
Arrays.asList(javaFilesDir)
|
Arrays.asList(javaFilesDir)
|
||||||
)
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean writeJavaFile(@NotNull String fileName, @NotNull String content, @NotNull File javaFilesDir) {
|
private static boolean writeJavaFile(@NotNull String fileName, @NotNull String content, @NotNull File javaFilesDir) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
|||||||
assert !sourceFiles.isEmpty() : getTestName(true) + " should contains at least one .kt file";
|
assert !sourceFiles.isEmpty() : getTestName(true) + " should contains at least one .kt file";
|
||||||
Collections.sort(sourceFiles);
|
Collections.sort(sourceFiles);
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, Arrays.asList(JetTestUtils.getAnnotationsJar()), classPath));
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, Arrays.asList(JetTestUtils.getAnnotationsJar()), classPath));
|
||||||
|
|
||||||
loadFiles(sourceFiles.toArray(new String[sourceFiles.size()]));
|
loadFiles(sourceFiles.toArray(new String[sourceFiles.size()]));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ClassPathInParentClassLoaderTest extends CodegenTestCase {
|
|||||||
public void testKt2781() throws Exception {
|
public void testKt2781() throws Exception {
|
||||||
File javaClassesTempDirectory = compileJava("classPathInParentClassLoader/kt2781.java");
|
File javaClassesTempDirectory = compileJava("classPathInParentClassLoader/kt2781.java");
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||||
|
|
||||||
loadFile("classPathInParentClassLoader/kt2781.kt");
|
loadFile("classPathInParentClassLoader/kt2781.kt");
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions);
|
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, generateAssertions);
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions);
|
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, generateParamAssertions);
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestGenerateAssertions(boolean generateAssertions) throws Exception {
|
private void doTestGenerateAssertions(boolean generateAssertions) throws Exception {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class JUnitUsageGenTest extends CodegenTestCase {
|
|||||||
throw new AssertionError("JUnit jar wasn't found");
|
throw new AssertionError("JUnit jar wasn't found");
|
||||||
}
|
}
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, junitJar));
|
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, junitJar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetCoreEnvironment createEnvironment() {
|
private JetCoreEnvironment createEnvironment() {
|
||||||
return new JetCoreEnvironment(myTestRootDisposable, JetTestUtils
|
return JetCoreEnvironment.createForTests(myTestRootDisposable, JetTestUtils
|
||||||
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), tmpdir));
|
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), tmpdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class OuterClassGenTest extends CodegenTestCase {
|
|||||||
private void doTest(@NotNull String kotlinName, @NotNull String javaName) throws Exception {
|
private void doTest(@NotNull String kotlinName, @NotNull String javaName) throws Exception {
|
||||||
File javaClassesTempDirectory = compileJava("outerClassInfo/outerClassInfo.java");
|
File javaClassesTempDirectory = compileJava("outerClassInfo/outerClassInfo.java");
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||||
|
|
||||||
UrlClassLoader javaClassLoader = new UrlClassLoader(new URL[] {javaClassesTempDirectory.toURI().toURL()}, getClass().getClassLoader());
|
UrlClassLoader javaClassLoader = new UrlClassLoader(new URL[] {javaClassesTempDirectory.toURI().toURL()}, getClass().getClassLoader());
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class TestlibTest extends UsefulTestCase {
|
|||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
||||||
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||||
|
|
||||||
generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(myEnvironment);
|
generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(myEnvironment);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
|||||||
String ktFile = ktFileFullPath.substring("compiler/testData/codegen/".length());
|
String ktFile = ktFileFullPath.substring("compiler/testData/codegen/".length());
|
||||||
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||||
|
|
||||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||||
|
|
||||||
loadFile(ktFile);
|
loadFile(ktFile);
|
||||||
|
|||||||
+1
-1
@@ -78,7 +78,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
|
|||||||
private void compileB(@NotNull File ktBFile) throws IOException {
|
private void compileB(@NotNull File ktBFile) throws IOException {
|
||||||
CompilerConfiguration configurationWithADirInClasspath = JetTestUtils
|
CompilerConfiguration configurationWithADirInClasspath = JetTestUtils
|
||||||
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
|
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
|
||||||
compileKotlin(ktBFile, bDir, new JetCoreEnvironment(getTestRootDisposable(), configurationWithADirInClasspath),
|
compileKotlin(ktBFile, bDir, JetCoreEnvironment.createForTests(getTestRootDisposable(), configurationWithADirInClasspath),
|
||||||
getTestRootDisposable());
|
getTestRootDisposable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, tmpdir);
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, tmpdir);
|
||||||
configuration.put(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourcesDir.getAbsolutePath()));
|
configuration.put(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourcesDir.getAbsolutePath()));
|
||||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("compiler/tests")); // for @ExpectLoadError annotation
|
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("compiler/tests")); // for @ExpectLoadError annotation
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
JetCoreEnvironment environment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||||
|
|
||||||
// we need the same binding trace for resolve from Java and Kotlin
|
// we need the same binding trace for resolve from Java and Kotlin
|
||||||
BindingTrace trace = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).getTrace();
|
BindingTrace trace = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).getTrace();
|
||||||
|
|||||||
+4
-2
@@ -24,6 +24,7 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.MockLibraryUtil;
|
import org.jetbrains.jet.MockLibraryUtil;
|
||||||
import org.jetbrains.jet.TestJdkKind;
|
import org.jetbrains.jet.TestJdkKind;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptorForObject;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptorForObject;
|
||||||
@@ -92,8 +93,9 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
|||||||
extras.addAll(extraClassPath);
|
extras.addAll(extraClassPath);
|
||||||
extras.add(JetTestUtils.getAnnotationsJar());
|
extras.add(JetTestUtils.getAnnotationsJar());
|
||||||
|
|
||||||
return new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, extras.toArray(new File[extras.size()])));
|
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, extras.toArray(new File[extras.size()]));
|
||||||
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class JdkAnnotationsValidityTest extends UsefulTestCase {
|
|||||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar());
|
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar());
|
||||||
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File("ideaSDK/lib/jdkAnnotations.jar"));
|
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File("ideaSDK/lib/jdkAnnotations.jar"));
|
||||||
return new JetCoreEnvironment(parentDisposable, configuration);
|
return JetCoreEnvironment.createForTests(parentDisposable, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public final class LoadDescriptorUtil {
|
|||||||
javaRoot,
|
javaRoot,
|
||||||
new File("compiler/tests") // for @ExpectLoadError annotation
|
new File("compiler/tests") // for @ExpectLoadError annotation
|
||||||
);
|
);
|
||||||
JetCoreEnvironment jetCoreEnvironment = new JetCoreEnvironment(disposable, configuration);
|
JetCoreEnvironment jetCoreEnvironment = JetCoreEnvironment.createForTests(disposable, configuration);
|
||||||
BindingTraceContext trace = new BindingTraceContext();
|
BindingTraceContext trace = new BindingTraceContext();
|
||||||
InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver(jetCoreEnvironment.getProject(), trace);
|
InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver(jetCoreEnvironment.getProject(), trace);
|
||||||
NamespaceDescriptor namespaceDescriptor =
|
NamespaceDescriptor namespaceDescriptor =
|
||||||
|
|||||||
+2
-2
@@ -145,13 +145,13 @@ public class ResolveDescriptorsFromExternalLibraries {
|
|||||||
|
|
||||||
JetCoreEnvironment jetCoreEnvironment;
|
JetCoreEnvironment jetCoreEnvironment;
|
||||||
if (jar != null) {
|
if (jar != null) {
|
||||||
jetCoreEnvironment = new JetCoreEnvironment(junk, JetTestUtils.compilerConfigurationForTests(
|
jetCoreEnvironment = JetCoreEnvironment.createForTests(junk, JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), jar));
|
ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), jar));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CompilerConfiguration configuration =
|
CompilerConfiguration configuration =
|
||||||
JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
|
JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
|
||||||
jetCoreEnvironment = new JetCoreEnvironment(junk, configuration);
|
jetCoreEnvironment = JetCoreEnvironment.createForTests(junk, configuration);
|
||||||
if (!PathUtil.findRtJar().equals(jar)) {
|
if (!PathUtil.findRtJar().equals(jar)) {
|
||||||
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
|
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class JetPsiUtilTest extends JetLiteFixture {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JetCoreEnvironment createEnvironment() {
|
protected JetCoreEnvironment createEnvironment() {
|
||||||
return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration());
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImportPath getImportPathFromParsed(String text) {
|
private ImportPath getImportPathFromParsed(String text) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class BuiltInsSerializer {
|
|||||||
try {
|
try {
|
||||||
List<File> sourceFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.kt"), new File(BUILT_INS_SRC_DIR));
|
List<File> sourceFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.kt"), new File(BUILT_INS_SRC_DIR));
|
||||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(rootDisposable, configuration);
|
JetCoreEnvironment environment = JetCoreEnvironment.createForTests(rootDisposable, configuration);
|
||||||
List<JetFile> files = JetTestUtils.loadToJetFiles(environment, sourceFiles);
|
List<JetFile> files = JetTestUtils.loadToJetFiles(environment, sourceFiles);
|
||||||
|
|
||||||
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(files, environment, false);
|
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(files, environment, false);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class GenerateJavaToKotlinMethodMap {
|
|||||||
|
|
||||||
Disposable disposable = CompileEnvironmentUtil.createMockDisposable();
|
Disposable disposable = CompileEnvironmentUtil.createMockDisposable();
|
||||||
try {
|
try {
|
||||||
JetCoreEnvironment coreEnvironment = new JetCoreEnvironment(disposable, configuration);
|
JetCoreEnvironment coreEnvironment = JetCoreEnvironment.createForProduction(disposable, configuration);
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
Printer printer = new Printer(buf);
|
Printer printer = new Printer(buf);
|
||||||
|
|||||||
@@ -65,6 +65,6 @@ public abstract class AbstractJetPsiMatcherTest extends JetLiteFixture {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JetCoreEnvironment createEnvironment() {
|
protected JetCoreEnvironment createEnvironment() {
|
||||||
return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration());
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JetCoreEnvironment createEnvironment() {
|
protected JetCoreEnvironment createEnvironment() {
|
||||||
return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration());
|
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user