[LL API] Replace 'FirScript.containingFileSymbol' with 'FirProvider' API

This commit is contained in:
Yan Zhulanow
2023-01-31 16:50:25 +09:00
committed by Space Team
parent f352f7d5ba
commit e8570826e6
12 changed files with 26 additions and 12 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.resolve.providers.FirProvider
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirScriptSymbol
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -24,6 +25,7 @@ class FirLibrarySessionProvider(
override fun getFirClassifierContainerFileIfAny(fqName: ClassId): FirFile? = null
override fun getFirCallableContainerFile(symbol: FirCallableSymbol<*>): FirFile? = null
override fun getFirScriptContainerFile(symbol: FirScriptSymbol): FirFile? = null
override fun getFirFilesByPackage(fqName: FqName): List<FirFile> = emptyList()
override fun getClassNamesInPackage(fqName: FqName): Set<Name> = shouldNotBeCalled()
@@ -38,6 +38,10 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: FirKotli
return state.callableContainerMap[symbol]
}
override fun getFirScriptContainerFile(symbol: FirScriptSymbol): FirFile? {
return state.scriptContainerMap[symbol]
}
override fun getFirClassifierContainerFile(fqName: ClassId): FirFile {
return state.classifierContainerFileMap[fqName] ?: error("Couldn't find container for $fqName")
}
@@ -184,6 +188,11 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: FirKotli
val symbol = enumEntry.symbol
data.state.callableContainerMap[symbol] = data.file
}
override fun visitScript(script: FirScript, data: FirRecorderData) {
val symbol = script.symbol
data.state.scriptContainerMap[symbol] = data.file
}
}
private val state = State()
@@ -199,6 +208,7 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: FirKotli
val propertyMap = mutableMapOf<CallableId, List<FirPropertySymbol>>()
val constructorMap = mutableMapOf<CallableId, List<FirConstructorSymbol>>()
val callableContainerMap = mutableMapOf<FirCallableSymbol<*>, FirFile>()
val scriptContainerMap = mutableMapOf<FirScriptSymbol, FirFile>()
fun setFrom(other: State) {
fileMap.clear()
@@ -209,6 +219,7 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: FirKotli
propertyMap.clear()
constructorMap.clear()
callableContainerMap.clear()
scriptContainerMap.clear()
fileMap.putAll(other.fileMap)
allSubPackages.addAll(other.allSubPackages)
@@ -218,6 +229,7 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: FirKotli
propertyMap.putAll(other.propertyMap)
constructorMap.putAll(other.constructorMap)
callableContainerMap.putAll(other.callableContainerMap)
scriptContainerMap.putAll(other.scriptContainerMap)
classesInPackage.putAll(other.classesInPackage)
classifierInPackage.putAll(other.classifierInPackage)
}