Search in sources :

Example 1 with PackageFragmentDescriptor

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

the class BuiltInsReferenceResolverTest method getAllStandardDescriptors.

private static Collection<DeclarationDescriptor> getAllStandardDescriptors() {
    final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
    PackageFragmentDescriptor builtinsPackageFragment = DefaultBuiltIns.getInstance().getBuiltInsPackageFragment();
    for (DeclarationDescriptor packageMember : DescriptorUtils.getAllDescriptors(builtinsPackageFragment.getMemberScope())) {
        packageMember.acceptVoid(new DeclarationDescriptorVisitorEmptyBodies<Void, Void>() {

            @Override
            public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
                descriptors.add(descriptor);
                for (DeclarationDescriptor classMember : DescriptorUtils.getAllDescriptors(descriptor.getDefaultType().getMemberScope())) {
                    classMember.acceptVoid(this);
                }
                return null;
            }

            @Override
            public Void visitDeclarationDescriptor(DeclarationDescriptor descriptor, Void data) {
                descriptors.add(descriptor);
                return null;
            }
        });
    }
    return descriptors;
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) ArrayList(java.util.ArrayList) PackageFragmentDescriptor(org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor)

Example 2 with PackageFragmentDescriptor

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

the class LoadBuiltinsTest method testBuiltIns.

public void testBuiltIns() throws Exception {
    RecursiveDescriptorComparator.Configuration configuration = RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(DescriptorRenderer.Companion.withOptions(new Function1<DescriptorRendererOptions, Unit>() {

        @Override
        public Unit invoke(DescriptorRendererOptions options) {
            options.setWithDefinedIn(false);
            options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
            options.setVerbose(true);
            options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
            options.setModifiers(DescriptorRendererModifier.ALL);
            return Unit.INSTANCE;
        }
    }));
    PackageFragmentProvider packageFragmentProvider = createBuiltInsPackageFragmentProvider();
    List<KtFile> files = KotlinTestUtils.loadToJetFiles(getEnvironment(), ContainerUtil.concat(allFilesUnder("core/builtins/native"), allFilesUnder("core/builtins/src")));
    ModuleDescriptor module = LazyResolveTestUtilsKt.createResolveSessionForFiles(getEnvironment().getProject(), files, false).getModuleDescriptor();
    for (FqName packageFqName : CollectionsKt.listOf(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME)) {
        PackageFragmentDescriptor fromLazyResolve = CollectionsKt.single(module.getPackage(packageFqName).getFragments());
        if (fromLazyResolve instanceof LazyPackageDescriptor) {
            PackageFragmentDescriptor deserialized = CollectionsKt.single(packageFragmentProvider.getPackageFragments(packageFqName));
            RecursiveDescriptorComparator.validateAndCompareDescriptors(fromLazyResolve, deserialized, configuration, new File("compiler/testData/builtin-classes/default/" + packageFqName.asString().replace('.', '-') + ".txt"));
        }
    }
}
Also used : RecursiveDescriptorComparator(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator) ModuleDescriptor(org.jetbrains.kotlin.descriptors.ModuleDescriptor) PackageFragmentProvider(org.jetbrains.kotlin.descriptors.PackageFragmentProvider) BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider) FqName(org.jetbrains.kotlin.name.FqName) Function1(kotlin.jvm.functions.Function1) LazyPackageDescriptor(org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) PackageFragmentDescriptor(org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Aggregations

PackageFragmentDescriptor (org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Function1 (kotlin.jvm.functions.Function1)1 BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider (org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 PackageFragmentProvider (org.jetbrains.kotlin.descriptors.PackageFragmentProvider)1 FqName (org.jetbrains.kotlin.name.FqName)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 LazyPackageDescriptor (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor)1 RecursiveDescriptorComparator (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator)1