Search in sources :

Example 6 with CompilerConfiguration

use of org.jetbrains.kotlin.config.CompilerConfiguration in project kotlin by JetBrains.

the class StdlibTest method createEnvironment.

@Override
protected KotlinCoreEnvironment createEnvironment() {
    @SuppressWarnings("deprecation") File[] runtimeClasspath = ForTestCompileRuntime.runtimeClassesForTests();
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_NO_RUNTIME, TestJdkKind.FULL_JDK, runtimeClasspath);
    JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.kotlinTestJarForTests());
    File junitJar = new File("libraries/lib/junit-4.11.jar");
    assertTrue(junitJar.exists());
    JvmContentRootsKt.addJvmClasspathRoot(configuration, junitJar);
    ContentRootsKt.addKotlinSourceRoot(configuration, KotlinTestUtils.getHomeDirectory() + "/libraries/stdlib/test");
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false));
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    ModuleVisibilityManager moduleVisibilityManager = ModuleVisibilityManager.SERVICE.getInstance(environment.getProject());
    for (File path : runtimeClasspath) {
        moduleVisibilityManager.addFriendPath(path.getPath());
    }
    return environment;
}
Also used : ModuleVisibilityManager(org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Example 7 with CompilerConfiguration

use of org.jetbrains.kotlin.config.CompilerConfiguration in project kotlin by JetBrains.

the class GenerateNotNullAssertionsTest method setUpEnvironment.

private void setUpEnvironment(boolean disableCallAssertions, boolean disableParamAssertions, File... extraClassPath) {
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath);
    configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, disableCallAssertions);
    configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, disableParamAssertions);
    myEnvironment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    myFiles = null;
}
Also used : CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration)

Example 8 with CompilerConfiguration

use of org.jetbrains.kotlin.config.CompilerConfiguration in project kotlin by JetBrains.

the class AbstractLoadJavaTest method doTestCompiledKotlin.

private void doTestCompiledKotlin(@NotNull String ktFileName, @NotNull ConfigurationKind configurationKind, boolean useTypeTableInSerializer) throws Exception {
    File ktFile = new File(ktFileName);
    File txtFile = new File(ktFileName.replaceFirst("\\.kt$", ".txt"));
    CompilerConfiguration configuration = newConfiguration(configurationKind, TestJdkKind.MOCK_JDK, getAnnotationsJar());
    if (useTypeTableInSerializer) {
        configuration.put(JVMConfigurationKeys.USE_TYPE_TABLE, true);
    }
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    ModuleDescriptor module = compileKotlinToDirAndGetModule(Collections.singletonList(ktFile), tmpdir, environment);
    PackageViewDescriptor packageFromSource = module.getPackage(TEST_PACKAGE_FQNAME);
    Assert.assertEquals("test", packageFromSource.getName().asString());
    PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(tmpdir, getTestRootDisposable(), getJdkKind(), configurationKind, true).first;
    for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(packageFromBinary.getMemberScope())) {
        if (descriptor instanceof ClassDescriptor) {
            assert descriptor instanceof DeserializedClassDescriptor : DescriptorUtils.getFqName(descriptor) + " is loaded as " + descriptor.getClass();
        }
    }
    DescriptorValidator.validate(errorTypesForbidden(), packageFromSource);
    DescriptorValidator.validate(new DeserializedScopeValidationVisitor(), packageFromBinary);
    Configuration comparatorConfiguration = COMPARATOR_CONFIGURATION.checkPrimaryConstructors(true).checkPropertyAccessors(true);
    compareDescriptors(packageFromSource, packageFromBinary, comparatorConfiguration, txtFile);
}
Also used : DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) DeserializedClassDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor)

Example 9 with CompilerConfiguration

use of org.jetbrains.kotlin.config.CompilerConfiguration in project kotlin by JetBrains.

the class LoadDescriptorUtil method loadTestPackageAndBindingContextFromJavaRoot.

@NotNull
public static Pair<PackageViewDescriptor, BindingContext> loadTestPackageAndBindingContextFromJavaRoot(@NotNull File javaRoot, @NotNull Disposable disposable, @NotNull TestJdkKind testJdkKind, @NotNull ConfigurationKind configurationKind, boolean isBinaryRoot) {
    List<File> javaBinaryRoots = new ArrayList<File>();
    javaBinaryRoots.add(KotlinTestUtils.getAnnotationsJar());
    List<File> javaSourceRoots = new ArrayList<File>();
    javaSourceRoots.add(new File("compiler/testData/loadJava/include"));
    if (isBinaryRoot) {
        javaBinaryRoots.add(javaRoot);
    } else {
        javaSourceRoots.add(javaRoot);
    }
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(configurationKind, testJdkKind, javaBinaryRoots, javaSourceRoots);
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
    PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
    return Pair.create(packageView, analysisResult.getBindingContext());
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) ArrayList(java.util.ArrayList) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with CompilerConfiguration

use of org.jetbrains.kotlin.config.CompilerConfiguration in project kotlin by JetBrains.

the class CodegenTestUtil method generateFiles.

@NotNull
public static ClassFileFactory generateFiles(@NotNull KotlinCoreEnvironment environment, @NotNull CodegenTestFiles files, @NotNull ClassBuilderFactory classBuilderFactory) {
    AnalysisResult analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(files.getPsiFiles(), environment);
    analysisResult.throwIfError();
    AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
    CompilerConfiguration configuration = environment.getConfiguration();
    GenerationState state = new GenerationState(environment.getProject(), classBuilderFactory, analysisResult.getModuleDescriptor(), analysisResult.getBindingContext(), files.getPsiFiles(), configuration);
    if (analysisResult.getShouldGenerateCode()) {
        KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
    }
    // For JVM-specific errors
    AnalyzingUtils.throwExceptionOnErrors(state.getCollectedExtraJvmDiagnostics());
    return state.getFactory();
}
Also used : CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)15 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)8 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)6 KtFile (org.jetbrains.kotlin.psi.KtFile)5 Disposable (com.intellij.openapi.Disposable)4 ArrayList (java.util.ArrayList)4 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)3 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 FqName (org.jetbrains.kotlin.name.FqName)2 NoDataException (com.intellij.debugger.NoDataException)1 PositionManager (com.intellij.debugger.PositionManager)1 Project (com.intellij.openapi.project.Project)1 ReferenceType (com.sun.jdi.ReferenceType)1 FileFilter (java.io.FileFilter)1 JarFile (java.util.jar.JarFile)1 ZipEntry (java.util.zip.ZipEntry)1 PrintingMessageCollector (org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)1 CliLightClassGenerationSupport (org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport)1