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

org.jetbrains.kotlin.fir.declarations.ExpectActualAttributes.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2022 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.declarations

import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.ensureResolved
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
import java.util.*

private object ExpectForActualAttributeKey : FirDeclarationDataKey()
private object ActualForExpectAttributeKey : FirDeclarationDataKey()

typealias ExpectForActualData = Map>, List>>

@SymbolInternals
var FirDeclaration.expectForActual: ExpectForActualData? by FirDeclarationDataRegistry.data(ExpectForActualAttributeKey)
private var FirDeclaration.actualForExpectMap: WeakHashMap>? by FirDeclarationDataRegistry.data(ActualForExpectAttributeKey)

val FirBasedSymbol<*>.expectForActual: ExpectForActualData?
    get() {
        ensureResolved(FirResolvePhase.EXPECT_ACTUAL_MATCHING)
        return fir.expectForActual
    }

private fun FirDeclaration.getOrCreateActualForExpectMap(): WeakHashMap> {
    var map = actualForExpectMap
    if (map != null) return map
    synchronized(this) {
        map = actualForExpectMap
        if (map == null) {
            map = WeakHashMap()
            actualForExpectMap = map
        }
    }
    return map!!
}

@SymbolInternals
fun FirDeclaration.getActualForExpect(useSiteSession: FirSession): FirBasedSymbol<*>? {
    return actualForExpectMap?.get(useSiteSession)
}

fun FirBasedSymbol<*>.getActualForExpect(session: FirSession): FirBasedSymbol<*>? {
    ensureResolved(FirResolvePhase.EXPECT_ACTUAL_MATCHING)
    return fir.getActualForExpect(session)
}

@SymbolInternals
fun FirDeclaration.setActualForExpect(useSiteSession: FirSession, actualSymbol: FirBasedSymbol<*>) {
    val map = getOrCreateActualForExpectMap()
    map[useSiteSession] = actualSymbol
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy