FIR: move getCallableNames/getClassifierNames from scope to FirContainingNamesAwareScope

This commit is contained in:
Ilya Kirillov
2020-08-07 13:00:43 +03:00
parent 36a161080f
commit f62204fff1
27 changed files with 247 additions and 146 deletions
@@ -70,7 +70,7 @@ class FirJavaModuleBasedSession private constructor(
}
class FirLibrarySession private constructor(
moduleInfo: ModuleInfo,
override val moduleInfo: ModuleInfo,
sessionProvider: FirProjectSessionProvider,
) : FirSession(sessionProvider) {
companion object {
@@ -105,6 +105,10 @@ class JavaClassMembersEnhancementScope(
return useSiteMemberScope.getCallableNames()
}
override fun getClassifierNames(): Set<Name> {
return useSiteMemberScope.getClassifierNames()
}
override fun mayContainName(name: Name): Boolean {
return useSiteMemberScope.mayContainName(name)
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.java.scopes
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.java.enhancement.FirSignatureEnhancement
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.name.Name
@@ -15,8 +16,8 @@ import org.jetbrains.kotlin.name.Name
class JavaClassStaticEnhancementScope(
session: FirSession,
owner: FirRegularClassSymbol,
private val useSiteStaticScope: FirScope,
) : FirScope() {
private val useSiteStaticScope: JavaClassStaticUseSiteScope,
) : FirScope(), FirContainingNamesAwareScope {
private val signatureEnhancement = FirSignatureEnhancement(owner.fir, session) {
emptyList()
}
@@ -53,6 +54,11 @@ class JavaClassStaticEnhancementScope(
return useSiteStaticScope.getCallableNames()
}
override fun getClassifierNames(): Set<Name> {
return useSiteStaticScope.getClassifierNames()
}
override fun mayContainName(name: Name): Boolean {
return useSiteStaticScope.mayContainName(name)
}
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.fir.java.scopes
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.getContainingCallableNamesIfPresent
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
@@ -21,7 +23,7 @@ class JavaClassStaticUseSiteScope internal constructor(
private val superClassScope: FirScope,
private val superTypesScopes: List<FirScope>,
javaTypeParameterStack: JavaTypeParameterStack,
) : FirScope() {
) : FirScope(), FirContainingNamesAwareScope {
private val functions = hashMapOf<Name, Collection<FirFunctionSymbol<*>>>()
private val properties = hashMapOf<Name, Collection<FirVariableSymbol<*>>>()
private val overrideChecker = JavaOverrideChecker(session, javaTypeParameterStack)
@@ -83,9 +85,19 @@ class JavaClassStaticUseSiteScope internal constructor(
@OptIn(ExperimentalStdlibApi::class)
override fun getCallableNames(): Set<Name> {
return buildSet {
addAll(declaredMemberScope.getCallableNames())
addAll(declaredMemberScope.getContainingCallableNamesIfPresent())
for (superTypesScope in superTypesScopes) {
addAll(superTypesScope.getCallableNames())
addAll(superTypesScope.getContainingCallableNamesIfPresent())
}
}
}
@OptIn(ExperimentalStdlibApi::class)
override fun getClassifierNames(): Set<Name> {
return buildSet {
addAll(declaredMemberScope.getContainingCallableNamesIfPresent())
for (superTypesScope in superTypesScopes) {
addAll(superTypesScope.getContainingCallableNamesIfPresent())
}
}
}
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.fir.java.declarations.*
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertiesScope
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.scopes.getContainingCallableNamesIfPresent
import org.jetbrains.kotlin.fir.scopes.getContainingClassifierNamesIfPresent
import org.jetbrains.kotlin.fir.scopes.impl.AbstractFirUseSiteMemberScope
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.impl.*
@@ -46,11 +48,11 @@ class JavaClassUseSiteMemberScope(
}
override fun getCallableNames(): Set<Name> {
return declaredMemberScope.getCallableNames() + superTypesScope.getCallableNames()
return declaredMemberScope.getContainingCallableNamesIfPresent() + superTypesScope.getCallableNames()
}
override fun getClassifierNames(): Set<Name> {
return declaredMemberScope.getClassifierNames() + superTypesScope.getClassifierNames()
return declaredMemberScope.getContainingClassifierNamesIfPresent() + superTypesScope.getClassifierNames()
}
private fun generateAccessorSymbol(