Search in sources :

Example 1 with JvmPackagePartProvider

use of org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider 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

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)1 CliLightClassGenerationSupport (org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport)1 JvmPackagePartProvider (org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider)1 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)1 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1