Search in sources :

Example 16 with KotlinCoreEnvironment

use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.

the class KotlinTestUtils method compileKotlinWithJava.

public static void compileKotlinWithJava(@NotNull List<File> javaFiles, @NotNull List<File> ktFiles, @NotNull File outDir, @NotNull Disposable disposable, @Nullable File javaErrorFile) throws IOException {
    if (!ktFiles.isEmpty()) {
        KotlinCoreEnvironment environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable);
        LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment);
    } else {
        boolean mkdirs = outDir.mkdirs();
        assert mkdirs : "Not created: " + outDir;
    }
    if (!javaFiles.isEmpty()) {
        compileJavaFiles(javaFiles, Arrays.asList("-classpath", outDir.getPath() + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(), "-d", outDir.getPath()), javaErrorFile);
    }
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)

Example 17 with KotlinCoreEnvironment

use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.

the class AbstractBlackBoxCodegenTest method doLightAnalysisModeTest.

private void doLightAnalysisModeTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) {
    if (SKIP_LIGHT_ANALYSIS_MODE_TESTS)
        return;
    File boxTestsDir = new File("compiler/testData/codegen/box");
    String relativePath = FilesKt.toRelativeString(wholeFile, boxTestsDir);
    // Do nothing if this test is not under codegen/box
    if (relativePath.startsWith(".."))
        return;
    String outDir = new File("compiler/testData/codegen/light-analysis", relativePath).getParent();
    File txtFile = new File(outDir, FilesKt.getNameWithoutExtension(wholeFile) + ".txt");
    AbstractBytecodeListingTest.doTest(getTestRootDisposable(), files, javaFilesDir, txtFile, ClassBuilderFactories.TEST_KAPT3, new Function1<KotlinCoreEnvironment, Unit>() {

        @Override
        public Unit invoke(KotlinCoreEnvironment environment) {
            AnalysisHandlerExtension.Companion.registerExtension(environment.getProject(), new PartialAnalysisHandlerExtension());
            return Unit.INSTANCE;
        }
    });
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) PartialAnalysisHandlerExtension(org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension) Unit(kotlin.Unit) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 18 with KotlinCoreEnvironment

use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.

the class AbstractCompileKotlinAgainstKotlinTest method compileA.

@NotNull
private ClassFileFactory compileA(@NotNull TestFile testFile, List<TestFile> files) throws IOException {
    Disposable compileDisposable = createDisposable("compileA");
    CompilerConfiguration configuration = createConfiguration(ConfigurationKind.ALL, getJdkKind(files), Collections.singletonList(KotlinTestUtils.getAnnotationsJar()), Collections.<File>emptyList(), Collections.singletonList(testFile));
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(compileDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    return compileKotlin(testFile.name, testFile.content, aDir, environment, compileDisposable);
}
Also used : Disposable(com.intellij.openapi.Disposable) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with KotlinCoreEnvironment

use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.

the class AbstractCompileKotlinAgainstKotlinTest method compileB.

@NotNull
private ClassFileFactory compileB(@NotNull TestFile testFile, List<TestFile> files) throws IOException {
    CompilerConfiguration configurationWithADirInClasspath = createConfiguration(ConfigurationKind.ALL, getJdkKind(files), Lists.newArrayList(KotlinTestUtils.getAnnotationsJar(), aDir), Collections.<File>emptyList(), Collections.singletonList(testFile));
    Disposable compileDisposable = createDisposable("compileB");
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(compileDisposable, configurationWithADirInClasspath, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    return compileKotlin(testFile.name, testFile.content, bDir, environment, compileDisposable);
}
Also used : Disposable(com.intellij.openapi.Disposable) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)19 File (java.io.File)12 KtFile (org.jetbrains.kotlin.psi.KtFile)11 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)8 NotNull (org.jetbrains.annotations.NotNull)6 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)6 Disposable (com.intellij.openapi.Disposable)4 PackageViewDescriptor (org.jetbrains.kotlin.descriptors.PackageViewDescriptor)3 ArrayList (java.util.ArrayList)2 OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)2 PrintingMessageCollector (org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)2 FqName (org.jetbrains.kotlin.name.FqName)2 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 Pair (kotlin.Pair)1