Search in sources :

Example 1 with PackageViewDescriptor

use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.

the class ResolveSessionUtils method getClassOrObjectDescriptorsByFqName.

@NotNull
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(@NotNull ModuleDescriptor module, @NotNull FqName fqName, @NotNull Predicate<ClassDescriptor> filter) {
    if (fqName.isRoot())
        return Collections.emptyList();
    Collection<ClassDescriptor> result = new ArrayList<ClassDescriptor>(1);
    FqName packageFqName = fqName.parent();
    while (true) {
        PackageViewDescriptor packageDescriptor = module.getPackage(packageFqName);
        if (!packageDescriptor.isEmpty()) {
            FqName relativeClassFqName = FqNamesUtilKt.tail(fqName, packageFqName);
            ClassDescriptor classDescriptor = findClassByRelativePath(packageDescriptor.getMemberScope(), relativeClassFqName);
            if (classDescriptor != null && filter.apply(classDescriptor)) {
                result.add(classDescriptor);
            }
        }
        if (packageFqName.isRoot()) {
            break;
        }
        packageFqName = packageFqName.parent();
    }
    return result;
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) ArrayList(java.util.ArrayList) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PackageViewDescriptor

use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method doTestWithTxt.

private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception {
    PackageViewDescriptor packageView = analyzeFileToPackageView(extraClassPath);
    RecursiveDescriptorComparator.Configuration comparator = AbstractLoadJavaTest.COMPARATOR_CONFIGURATION.withValidationStrategy(DescriptorValidator.ValidationVisitor.errorTypesAllowed());
    validateAndCompareDescriptorWithFile(packageView, comparator, getTestDataFileWithExtension("txt"));
}
Also used : RecursiveDescriptorComparator(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor)

Example 3 with PackageViewDescriptor

use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor 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 PackageViewDescriptor

use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.

the class AbstractCompileJavaAgainstKotlinTest method doTest.

protected void doTest(String ktFilePath) throws IOException {
    Assert.assertTrue(ktFilePath.endsWith(".kt"));
    File ktFile = new File(ktFilePath);
    File javaFile = new File(ktFilePath.replaceFirst("\\.kt$", ".java"));
    File expectedFile = new File(ktFilePath.replaceFirst("\\.kt$", ".txt"));
    File javaErrorFile = new File(ktFilePath.replaceFirst("\\.kt$", ".javaerr.txt"));
    File out = new File(tmpdir, "out");
    compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile), out, getTestRootDisposable(), javaErrorFile);
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, getAnnotationsJar(), out), EnvironmentConfigFiles.JVM_CONFIG_FILES);
    AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
    PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
    assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
    validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor)

Example 5 with PackageViewDescriptor

use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor 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)

Aggregations

PackageViewDescriptor (org.jetbrains.kotlin.descriptors.PackageViewDescriptor)6 File (java.io.File)3 NotNull (org.jetbrains.annotations.NotNull)3 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)3 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)3 ArrayList (java.util.ArrayList)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 RecursiveDescriptorComparator (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator)1 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)1