Search in sources :

Example 1 with PackageFragmentProvider

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

the class JsConfig method createModuleDescriptor.

private JsModuleDescriptor<ModuleDescriptorImpl> createModuleDescriptor(KotlinJavascriptMetadata metadata) {
    assert metadata.getVersion().isCompatible() : "Expected JS metadata version " + JsMetadataVersion.INSTANCE + ", but actual metadata version is " + metadata.getVersion();
    ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(Name.special("<" + metadata.getModuleName() + ">"), storageManager, JsPlatform.INSTANCE.getBuiltIns());
    JsModuleDescriptor<PackageFragmentProvider> rawDescriptor = KotlinJavascriptSerializationUtil.readModule(metadata.getBody(), storageManager, moduleDescriptor, new CompilerDeserializationConfiguration(CommonConfigurationKeysKt.getLanguageVersionSettings(configuration)));
    PackageFragmentProvider provider = rawDescriptor.getData();
    moduleDescriptor.initialize(provider != null ? provider : PackageFragmentProvider.Empty.INSTANCE);
    return rawDescriptor.copy(moduleDescriptor);
}
Also used : CompilerDeserializationConfiguration(org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration) PackageFragmentProvider(org.jetbrains.kotlin.descriptors.PackageFragmentProvider) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)

Example 2 with PackageFragmentProvider

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

the class LoadBuiltinsTest method createBuiltInsPackageFragmentProvider.

@NotNull
private static PackageFragmentProvider createBuiltInsPackageFragmentProvider() {
    LockBasedStorageManager storageManager = new LockBasedStorageManager();
    ModuleDescriptorImpl builtInsModule = new ModuleDescriptorImpl(KotlinBuiltIns.BUILTINS_MODULE_NAME, storageManager, DefaultBuiltIns.getInstance());
    PackageFragmentProvider packageFragmentProvider = createBuiltInPackageFragmentProvider(storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES, Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)), PlatformDependentDeclarationFilter.All.INSTANCE, AdditionalClassPartsProvider.None.INSTANCE, new Function1<String, InputStream>() {

        @Override
        public InputStream invoke(String path) {
            return ForTestCompileRuntime.runtimeJarClassLoader().getResourceAsStream(path);
        }
    });
    builtInsModule.initialize(packageFragmentProvider);
    builtInsModule.setDependencies(builtInsModule);
    return packageFragmentProvider;
}
Also used : BuiltInFictitiousFunctionClassFactory(org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory) PackageFragmentProvider(org.jetbrains.kotlin.descriptors.PackageFragmentProvider) BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider) InputStream(java.io.InputStream) LockBasedStorageManager(org.jetbrains.kotlin.storage.LockBasedStorageManager) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PackageFragmentProvider

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

PackageFragmentProvider (org.jetbrains.kotlin.descriptors.PackageFragmentProvider)3 BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider (org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider)2 ModuleDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Function1 (kotlin.jvm.functions.Function1)1 NotNull (org.jetbrains.annotations.NotNull)1 BuiltInFictitiousFunctionClassFactory (org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 PackageFragmentDescriptor (org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 CompilerDeserializationConfiguration (org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration)1 LazyPackageDescriptor (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor)1 LockBasedStorageManager (org.jetbrains.kotlin.storage.LockBasedStorageManager)1 RecursiveDescriptorComparator (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator)1