use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.
the class AbstractLineNumberTest method createPsiFile.
@NotNull
private Pair<KtFile, KotlinCoreEnvironment> createPsiFile(@NotNull String filename) {
File file = new File(filename);
KotlinCoreEnvironment environment = createEnvironment();
String text;
try {
text = FileUtil.loadFile(file, true);
} catch (IOException e) {
throw ExceptionUtilsKt.rethrow(e);
}
return new Pair<KtFile, KotlinCoreEnvironment>(KotlinTestUtils.createFile(file.getName(), text, environment.getProject()), environment);
}
use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method testNoWarningsOnJavaKotlinInheritance.
public void testNoWarningsOnJavaKotlinInheritance() throws Exception {
// This test checks that there are no PARAMETER_NAME_CHANGED_ON_OVERRIDE or DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES
// warnings when subclassing in Kotlin from Java binaries (in case when no parameter names are available for Java classes)
KotlinTestUtils.compileJavaFiles(Collections.singletonList(getTestDataFileWithExtension("java")), Arrays.asList("-d", tmpdir.getPath()));
KotlinCoreEnvironment environment = createEnvironment(Collections.singletonList(tmpdir));
AnalysisResult result = JvmResolveUtil.analyze(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
result.throwIfError();
BindingContext bindingContext = result.getBindingContext();
AnalyzerWithCompilerReport.Companion.reportDiagnostics(bindingContext.getDiagnostics(), new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false));
assertEquals("There should be no diagnostics", 0, Iterables.size(bindingContext.getDiagnostics()));
}
use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method analyzeFileToPackageView.
@NotNull
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
KotlinCoreEnvironment environment = createEnvironment(Arrays.asList(extraClassPath));
AnalysisResult result = JvmResolveUtil.analyzeAndCheckForErrors(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
assertFalse("Failed to find package: " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
return packageView;
}
use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.
the class AbstractLoadJavaTest method doTestKotlinAgainstCompiledJavaWithKotlin.
// TODO: add more tests on inherited parameter names, but currently impossible because of KT-4509
protected void doTestKotlinAgainstCompiledJavaWithKotlin(@NotNull String expectedFileName) throws Exception {
File kotlinSrc = new File(expectedFileName);
File librarySrc = new File(expectedFileName.replaceFirst("\\.kt$", ""));
File expectedFile = new File(expectedFileName.replaceFirst("\\.kt$", ".txt"));
File libraryOut = new File(tmpdir, "libraryOut");
compileKotlinWithJava(FileUtil.findFilesByMask(Pattern.compile(".+\\.java$"), librarySrc), FileUtil.findFilesByMask(Pattern.compile(".+\\.kt$"), librarySrc), libraryOut, getTestRootDisposable(), null);
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), newConfiguration(ConfigurationKind.JDK_ONLY, getJdkKind(), getAnnotationsJar(), libraryOut), EnvironmentConfigFiles.JVM_CONFIG_FILES);
KtFile ktFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
ModuleDescriptor module = JvmResolveUtil.analyzeAndCheckForErrors(Collections.singleton(ktFile), environment).getModuleDescriptor();
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
assertFalse(packageView.isEmpty());
validateAndCompareDescriptorWithFile(packageView, COMPARATOR_CONFIGURATION.withValidationStrategy(new DeserializedScopeValidationVisitor()), expectedFile);
}
use of org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment in project kotlin by JetBrains.
the class AbstractLoadJavaTest method doTestJavaAgainstKotlin.
protected void doTestJavaAgainstKotlin(String expectedFileName) throws Exception {
File expectedFile = new File(expectedFileName);
File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", ""));
FileUtil.copyDir(sourcesDir, new File(tmpdir, "test"), new FileFilter() {
@Override
public boolean accept(@NotNull File pathname) {
return pathname.getName().endsWith(".java");
}
});
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, getJdkKind());
ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath());
JvmContentRootsKt.addJavaSourceRoot(configuration, new File("compiler/testData/loadJava/include"));
JvmContentRootsKt.addJavaSourceRoot(configuration, tmpdir);
final KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
AnalysisResult result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(environment.getProject(), environment.getSourceFiles(), new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), configuration, new Function1<GlobalSearchScope, PackagePartProvider>() {
@Override
public PackagePartProvider invoke(GlobalSearchScope scope) {
return new JvmPackagePartProvider(environment, scope);
}
});
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
checkJavaPackage(expectedFile, packageView, result.getBindingContext(), COMPARATOR_CONFIGURATION);
}
Aggregations