Search in sources :

Example 1 with KotlinCoreEnvironment

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);
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) IOException(java.io.IOException) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KotlinCoreEnvironment

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()));
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Example 3 with KotlinCoreEnvironment

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;
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with KotlinCoreEnvironment

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);
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) KtFile(org.jetbrains.kotlin.psi.KtFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 5 with KotlinCoreEnvironment

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);
}
Also used : CliLightClassGenerationSupport(org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JvmPackagePartProvider(org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) JvmPackagePartProvider(org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider) FileFilter(java.io.FileFilter) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

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