All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.fir.session.KlibIcCacheBasedSymbolProvider.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.fir.session


import org.jetbrains.kotlin.fir.FirModuleData
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.deserialization.SingleModuleDataProvider
import org.jetbrains.kotlin.fir.scopes.FirKotlinScopeProvider
import org.jetbrains.kotlin.library.metadata.KlibDeserializedContainerSource
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
import org.jetbrains.kotlin.utils.SmartList

class KlibIcCacheBasedSymbolProvider(
    session: FirSession,
    moduleDataProvider: SingleModuleDataProvider,
    kotlinScopeProvider: FirKotlinScopeProvider,
    private val icData: KlibIcData,
    defaultDeserializationOrigin: FirDeclarationOrigin = FirDeclarationOrigin.Precompiled
) : MetadataLibraryBasedSymbolProvider(
    session,
    moduleDataProvider,
    kotlinScopeProvider,
    defaultDeserializationOrigin
) {
    override fun moduleData(library: KlibIcData): FirModuleData {
        return moduleDataProvider.allModuleData.single()
    }

    override val fragmentNamesInLibraries: Map> by lazy {
        buildMap> {
            for (fragmentName in icData.packageFragmentNameList) {
                getOrPut(fragmentName) { SmartList() }
                    .add(icData)
            }
        }
    }

    override val knownPackagesInLibraries: Set by lazy {
        buildSet {
            for (fragmentName in icData.packageFragmentNameList) {
                var curPackage = FqName(fragmentName)
                while (!curPackage.isRoot) {
                    add(curPackage)
                    curPackage = curPackage.parent()
                }
            }
        }
    }

    override fun createDeserializedContainerSource(resolvedLibrary: KlibIcData, packageFqName: FqName): DeserializedContainerSource {
        return KlibDeserializedContainerSource(false, "Package '$packageFqName'", false)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy