Store containers per symbol, not per callable id

This commit is contained in:
Simon Ogorodnik
2019-03-20 22:11:02 +03:00
committed by Denis Zharkov
parent 48f0790785
commit 49a0b29129
3 changed files with 12 additions and 12 deletions
@@ -30,7 +30,7 @@ interface FirProvider : FirSymbolProvider {
fun getFirClassifierContainerFile(fqName: ClassId): FirFile fun getFirClassifierContainerFile(fqName: ClassId): FirFile
fun getFirCallableContainerFile(callableId: CallableId): FirFile? fun getFirCallableContainerFile(symbol: ConeCallableSymbol): FirFile?
companion object { companion object {
fun getInstance(session: FirSession): FirProvider = session.service() fun getInstance(session: FirSession): FirProvider = session.service()
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
class FirProviderImpl(val session: FirSession) : FirProvider { class FirProviderImpl(val session: FirSession) : FirProvider {
override fun getFirCallableContainerFile(callableId: CallableId): FirFile? { override fun getFirCallableContainerFile(symbol: ConeCallableSymbol): FirFile? {
return callableContainerMap[callableId] return callableContainerMap[symbol]
} }
override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? { override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? {
@@ -30,8 +30,6 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> { override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
return (callableMap[CallableId(packageFqName, null, name)] ?: emptyList()) return (callableMap[CallableId(packageFqName, null, name)] ?: emptyList())
.filterIsInstance<FirSymbolOwner<*>>()
.mapNotNull { it.symbol as? ConeCallableSymbol }
} }
override fun getClassDeclaredMemberScope(classId: ClassId) = override fun getClassDeclaredMemberScope(classId: ClassId) =
@@ -69,9 +67,10 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
} }
override fun visitCallableMemberDeclaration(callableMemberDeclaration: FirCallableMemberDeclaration) { override fun visitCallableMemberDeclaration(callableMemberDeclaration: FirCallableMemberDeclaration) {
val callableId = (callableMemberDeclaration.symbol as ConeCallableSymbol).callableId val symbol = callableMemberDeclaration.symbol as ConeCallableSymbol
callableMap.merge(callableId, listOf(callableMemberDeclaration)) { a, b -> a + b } val callableId = symbol.callableId
callableContainerMap[callableId] = file callableMap.merge(callableId, listOf(symbol)) { a, b -> a + b }
callableContainerMap[symbol] = file
} }
override fun visitConstructor(constructor: FirConstructor) { override fun visitConstructor(constructor: FirConstructor) {
@@ -91,8 +90,8 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
private val fileMap = mutableMapOf<FqName, List<FirFile>>() private val fileMap = mutableMapOf<FqName, List<FirFile>>()
private val classifierMap = mutableMapOf<ClassId, FirClassLikeDeclaration>() private val classifierMap = mutableMapOf<ClassId, FirClassLikeDeclaration>()
private val classifierContainerFileMap = mutableMapOf<ClassId, FirFile>() private val classifierContainerFileMap = mutableMapOf<ClassId, FirFile>()
private val callableMap = mutableMapOf<CallableId, List<FirNamedDeclaration>>() private val callableMap = mutableMapOf<CallableId, List<ConeCallableSymbol>>()
private val callableContainerMap = mutableMapOf<CallableId, FirFile>() private val callableContainerMap = mutableMapOf<ConeCallableSymbol, FirFile>()
override fun getFirFilesByPackage(fqName: FqName): List<FirFile> { override fun getFirFilesByPackage(fqName: FqName): List<FirFile> {
return fileMap[fqName].orEmpty() return fileMap[fqName].orEmpty()
@@ -460,11 +460,12 @@ class ReturnTypeCalculatorWithJump(val session: FirSession) : ReturnTypeCalculat
require(declaration is FirCallableMemberDeclaration) { "${declaration::class}: ${declaration.render()}" } require(declaration is FirCallableMemberDeclaration) { "${declaration::class}: ${declaration.render()}" }
val id = (declaration.symbol as ConeCallableSymbol).callableId val symbol = declaration.symbol as ConeCallableSymbol
val id = symbol.callableId
val provider = session.service<FirProvider>() val provider = session.service<FirProvider>()
val file = provider.getFirCallableContainerFile(id) val file = provider.getFirCallableContainerFile(symbol)
val outerClasses = generateSequence(id.classId) { classId -> val outerClasses = generateSequence(id.classId) { classId ->
classId.outerClassId classId.outerClassId