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;
}
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;
}
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);
}
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());
}
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();
}
Aggregations