Replace FirSymbolProvider::getCallableSymbols with two methods
Requesting content of classes seems to be reasonable and at the same time more easy to implement in Composite providers: they should find just the first class' result instead of flatmapping all of them
This commit is contained in:
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.fir.java
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
|
||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaConstructor
|
||||
@@ -17,6 +15,8 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
|
||||
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade
|
||||
|
||||
class JavaSymbolProvider(
|
||||
@@ -41,30 +42,12 @@ class JavaSymbolProvider(
|
||||
|
||||
private fun findClass(classId: ClassId): JavaClass? = facade.findClass(JavaClassFinder.Request(classId), searchScope)
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
return callableCache.lookupCacheOrCalculate(callableId) {
|
||||
val classId = callableId.classId ?: return@lookupCacheOrCalculate emptyList()
|
||||
val classSymbol = getClassLikeSymbolByFqName(classId) as? FirClassSymbol
|
||||
?: return@lookupCacheOrCalculate emptyList()
|
||||
val firClass = classSymbol.fir
|
||||
val callableSymbols = mutableListOf<ConeCallableSymbol>()
|
||||
for (declaration in firClass.declarations) {
|
||||
val declarationId = when (declaration) {
|
||||
is FirConstructor -> {
|
||||
CallableId(callableId.packageName, callableId.className, firClass.name)
|
||||
}
|
||||
is FirCallableMemberDeclaration -> {
|
||||
CallableId(callableId.packageName, callableId.className, declaration.name)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
if (declarationId == callableId) {
|
||||
val symbol = (declaration as FirCallableMemberDeclaration).symbol as ConeCallableSymbol
|
||||
callableSymbols += symbol
|
||||
}
|
||||
}
|
||||
callableSymbols
|
||||
}.orEmpty()
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> =
|
||||
emptyList()
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId): FirScope? {
|
||||
val classSymbol = getClassLikeSymbolByFqName(classId) as? FirClassSymbol ?: return null
|
||||
return FirClassDeclaredMemberScope(classSymbol.fir)
|
||||
}
|
||||
|
||||
override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? {
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||
import org.jetbrains.kotlin.fir.resolve.getClassDeclaredCallableSymbols
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
@@ -237,8 +237,8 @@ private fun JavaAnnotationArgument.toFirExpression(session: FirSession): FirExpr
|
||||
val classId = this@toFirExpression.enumClassId
|
||||
val entryName = this@toFirExpression.entryName
|
||||
val calleeReference = if (classId != null && entryName != null) {
|
||||
val callableSymbol = session.service<FirSymbolProvider>().getCallableSymbols(
|
||||
CallableId(classId.packageFqName, classId.relativeClassName, entryName)
|
||||
val callableSymbol = session.service<FirSymbolProvider>().getClassDeclaredCallableSymbols(
|
||||
classId, entryName
|
||||
).firstOrNull()
|
||||
callableSymbol?.let {
|
||||
FirResolvedCallableReferenceImpl(session, null, entryName, it)
|
||||
|
||||
@@ -57,7 +57,7 @@ class FirJavaClass(
|
||||
|
||||
private fun buildJavaUseSiteScope(regularClass: FirRegularClass, useSiteSession: FirSession): JavaClassUseSiteScope {
|
||||
val superTypeEnhancementScope = FirCompositeScope(mutableListOf())
|
||||
val declaredScope = FirClassDeclaredMemberScope(regularClass, useSiteSession)
|
||||
val declaredScope = FirClassDeclaredMemberScope(regularClass)
|
||||
lookupSuperTypes(regularClass, lookupInterfaces = true, deep = false, useSiteSession = useSiteSession)
|
||||
.mapNotNullTo(superTypeEnhancementScope.scopes) { useSiteSuperType ->
|
||||
if (useSiteSuperType is ConeClassErrorType) return@mapNotNullTo null
|
||||
@@ -77,4 +77,4 @@ class FirJavaClass(
|
||||
superTypeRefs.addAll(newSupertypes)
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-15
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.java.deserialization
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
@@ -15,7 +14,7 @@ import org.jetbrains.kotlin.fir.deserialization.FirDeserializationContext
|
||||
import org.jetbrains.kotlin.fir.deserialization.deserializeClassToSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.getOrPut
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
@@ -81,22 +80,17 @@ class KotlinDeserializedJvmSymbolsProvider(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
if (callableId.classId != null) {
|
||||
return getClassDeclarations(callableId.classId!!).filterIsInstance<FirCallableMemberDeclaration>()
|
||||
.filter { it.name == callableId.callableName }
|
||||
.map { it.symbol }
|
||||
}
|
||||
|
||||
val packageFqName = callableId.packageName
|
||||
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
return getPackageParts(packageFqName).flatMap { (packageProto, context) ->
|
||||
packageProto.functionList.map {
|
||||
context.memberDeserializer.loadFunction(it).symbol
|
||||
}.filter { callableSymbol -> callableSymbol.callableId.callableName == callableId.callableName }
|
||||
}.filter { callableSymbol -> callableSymbol.callableId.callableName == name }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId) =
|
||||
findRegularClass(classId)?.let(::FirClassDeclaredMemberScope)
|
||||
|
||||
private fun getPackageParts(packageFqName: FqName): Collection<Pair<ProtoBuf.Package, FirDeserializationContext>> {
|
||||
return packagePartsCache.getOrPut(packageFqName) {
|
||||
computePackagePartsInfos(packageFqName)
|
||||
@@ -115,11 +109,14 @@ class KotlinDeserializedJvmSymbolsProvider(
|
||||
.mapTo(sortedSetOf(), JavaClass::name)
|
||||
|
||||
private fun getClassDeclarations(classId: ClassId): List<FirDeclaration> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val classSymbol = getClassLikeSymbolByFqName(classId) as? FirBasedSymbol<FirRegularClass> ?: return emptyList()
|
||||
return classSymbol.fir.declarations
|
||||
return findRegularClass(classId)?.declarations ?: emptyList()
|
||||
}
|
||||
|
||||
|
||||
private fun findRegularClass(classId: ClassId): FirRegularClass? =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(getClassLikeSymbolByFqName(classId) as? FirBasedSymbol<FirRegularClass>)?.fir
|
||||
|
||||
override fun getAllCallableNamesInClass(classId: ClassId): Set<Name> =
|
||||
getClassDeclarations(classId)
|
||||
.filterIsInstance<FirNamedDeclaration>()
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractProviderBasedScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeVariableSymbol
|
||||
@@ -28,7 +27,7 @@ class JavaClassUseSiteScope(
|
||||
klass: FirRegularClass,
|
||||
session: FirSession,
|
||||
internal val superTypesScope: FirScope,
|
||||
private val declaredMemberScope: FirClassDeclaredMemberScope
|
||||
private val declaredMemberScope: FirScope
|
||||
) : FirAbstractProviderBasedScope(session, lookupInFir = true) {
|
||||
internal val symbol = klass.symbol
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
abstract class AbstractFirSymbolProvider : FirSymbolProvider {
|
||||
protected val classCache = mutableMapOf<ClassId, ConeClassLikeSymbol?>()
|
||||
protected val callableCache = mutableMapOf<CallableId, List<ConeCallableSymbol>>()
|
||||
protected val topLevelCallableCache = mutableMapOf<CallableId, List<ConeCallableSymbol>>()
|
||||
protected val packageCache = mutableMapOf<FqName, FqName?>()
|
||||
|
||||
protected inline fun <K, V : Any?> MutableMap<K, V>.lookupCacheOrCalculate(key: K, crossinline l: (K) -> V): V? {
|
||||
@@ -52,4 +52,4 @@ abstract class AbstractFirSymbolProvider : FirSymbolProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationContainer
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
@@ -15,13 +14,14 @@ import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
interface FirProvider : FirSymbolProvider {
|
||||
fun getFirClassifierByFqName(fqName: ClassId): FirMemberDeclaration?
|
||||
|
||||
override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol?
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol>
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol>
|
||||
|
||||
override fun getPackage(fqName: FqName): FqName? {
|
||||
if (getFirFilesByPackage(fqName).isNotEmpty()) return fqName
|
||||
|
||||
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.toFirClassLike
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -25,7 +27,9 @@ interface FirSymbolProvider {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol>
|
||||
fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol>
|
||||
|
||||
fun getClassDeclaredMemberScope(classId: ClassId): FirScope?
|
||||
|
||||
fun getAllCallableNamesInPackage(fqName: FqName): Set<Name> = emptySet()
|
||||
fun getClassNamesInPackage(fqName: FqName): Set<Name> = emptySet()
|
||||
@@ -42,3 +46,25 @@ interface FirSymbolProvider {
|
||||
fun getInstance(session: FirSession) = session.service<FirSymbolProvider>()
|
||||
}
|
||||
}
|
||||
|
||||
fun FirSymbolProvider.getClassDeclaredCallableSymbols(classId: ClassId, name: Name): List<ConeCallableSymbol> {
|
||||
val declaredMemberScope = getClassDeclaredMemberScope(classId) ?: return emptyList()
|
||||
val result = mutableListOf<ConeCallableSymbol>()
|
||||
val processor: (ConeCallableSymbol) -> ProcessorAction = {
|
||||
result.add(it)
|
||||
ProcessorAction.NEXT
|
||||
}
|
||||
|
||||
declaredMemberScope.processFunctionsByName(name, processor)
|
||||
declaredMemberScope.processPropertiesByName(name, processor)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun FirSymbolProvider.getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
if (callableId.classId != null) {
|
||||
return getClassDeclaredCallableSymbols(callableId.classId!!, callableId.callableName)
|
||||
}
|
||||
|
||||
return getTopLevelCallableSymbols(callableId.packageName, callableId.callableName)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
@@ -39,7 +36,7 @@ fun FirRegularClass.buildUseSiteScope(useSiteSession: FirSession): FirScope {
|
||||
|
||||
private fun FirRegularClass.buildDefaultUseSiteScope(useSiteSession: FirSession): FirScope {
|
||||
val superTypeScope = FirCompositeScope(mutableListOf())
|
||||
val declaredScope = FirClassDeclaredMemberScope(this, useSiteSession)
|
||||
val declaredScope = FirClassDeclaredMemberScope(this)
|
||||
lookupSuperTypes(this, lookupInterfaces = true, deep = false, useSiteSession = useSiteSession)
|
||||
.mapNotNullTo(superTypeScope.scopes) { useSiteSuperType ->
|
||||
if (useSiteSuperType is ConeClassErrorType) return@mapNotNullTo null
|
||||
|
||||
+4
-3
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -15,10 +14,12 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class FirCompositeSymbolProvider(val providers: List<FirSymbolProvider>) : FirSymbolProvider {
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
return providers.flatMap { it.getCallableSymbols(callableId) }
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
return providers.flatMap { it.getTopLevelCallableSymbols(packageFqName, name) }
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId) = providers.firstNotNullResult { it.getClassDeclaredMemberScope(classId) }
|
||||
|
||||
override fun getPackage(fqName: FqName): FqName? {
|
||||
return providers.firstNotNullResult { it.getPackage(fqName) }
|
||||
}
|
||||
|
||||
+7
-3
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class FirDependenciesSymbolProviderImpl(val session: FirSession) : AbstractFirSymbolProvider() {
|
||||
private val dependencyProviders by lazy {
|
||||
@@ -25,12 +26,15 @@ class FirDependenciesSymbolProviderImpl(val session: FirSession) : AbstractFirSy
|
||||
}.toList()
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
return callableCache.lookupCacheOrCalculate(callableId) {
|
||||
dependencyProviders.flatMap { provider -> provider.getCallableSymbols(callableId) }
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
return topLevelCallableCache.lookupCacheOrCalculate(CallableId(packageFqName, null, name)) {
|
||||
dependencyProviders.flatMap { provider -> provider.getTopLevelCallableSymbols(packageFqName, name) }
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId) =
|
||||
dependencyProviders.firstNotNullResult { it.getClassDeclaredMemberScope(classId) }
|
||||
|
||||
override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? {
|
||||
return classCache.lookupCacheOrCalculate(classId) {
|
||||
for (provider in dependencyProviders) {
|
||||
|
||||
+18
-13
@@ -20,7 +20,12 @@ import org.jetbrains.kotlin.fir.deserialization.FirDeserializationContext
|
||||
import org.jetbrains.kotlin.fir.deserialization.deserializeClassToSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.getOrPut
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion
|
||||
@@ -150,18 +155,15 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
if (callableId.classId != null) {
|
||||
return getClassDeclarations(callableId.classId!!).filterIsInstance<FirCallableMemberDeclaration>()
|
||||
.filter { it.name == callableId.callableName }
|
||||
.map { it.symbol }
|
||||
}
|
||||
|
||||
return allPackageFragments[callableId.packageName]?.flatMap {
|
||||
it.getTopLevelCallableSymbols(callableId.callableName)
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
return allPackageFragments[packageFqName]?.flatMap {
|
||||
it.getTopLevelCallableSymbols(name)
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId): FirScope? =
|
||||
findRegularClass(classId)?.let(::FirClassDeclaredMemberScope)
|
||||
|
||||
override fun getAllCallableNamesInPackage(fqName: FqName): Set<Name> {
|
||||
return allPackageFragments[fqName]?.flatMapTo(mutableSetOf()) {
|
||||
it.getAllCallableNames()
|
||||
@@ -179,11 +181,14 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider
|
||||
}
|
||||
|
||||
private fun getClassDeclarations(classId: ClassId): List<FirDeclaration> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val classSymbol = getClassLikeSymbolByFqName(classId) as? FirBasedSymbol<FirRegularClass> ?: return emptyList()
|
||||
return classSymbol.fir.declarations
|
||||
return findRegularClass(classId)?.declarations ?: emptyList()
|
||||
}
|
||||
|
||||
|
||||
private fun findRegularClass(classId: ClassId): FirRegularClass? =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(getClassLikeSymbolByFqName(classId) as? FirBasedSymbol<FirRegularClass>)?.fir
|
||||
|
||||
override fun getNestedClassesNamesInClass(classId: ClassId): Set<Name> {
|
||||
return getClassDeclarations(classId).filterIsInstance<FirRegularClass>().mapTo(mutableSetOf()) { it.name }
|
||||
}
|
||||
|
||||
@@ -9,10 +9,15 @@ import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirProviderImpl(val session: FirSession) : FirProvider {
|
||||
override fun getFirCallableContainerFile(callableId: CallableId): FirFile? {
|
||||
@@ -23,12 +28,15 @@ class FirProviderImpl(val session: FirSession) : FirProvider {
|
||||
return (getFirClassifierByFqName(classId) as? FirSymbolOwner<*>)?.symbol as? ConeClassLikeSymbol
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
return (callableMap[callableId] ?: emptyList())
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
return (callableMap[CallableId(packageFqName, null, name)] ?: emptyList())
|
||||
.filterIsInstance<FirSymbolOwner<*>>()
|
||||
.mapNotNull { it.symbol as? ConeCallableSymbol }
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId) =
|
||||
(getFirClassifierByFqName(classId) as? FirRegularClass)?.let(::FirClassDeclaredMemberScope)
|
||||
|
||||
override fun getFirClassifierContainerFile(fqName: ClassId): FirFile {
|
||||
return classifierContainerFileMap[fqName] ?: error("Couldn't find container for $fqName")
|
||||
}
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.scopes.impl
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedImportImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.getCallableSymbols
|
||||
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
import org.jetbrains.kotlin.fir.resolve.getCallableSymbols
|
||||
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
|
||||
+22
-26
@@ -5,41 +5,37 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.NEXT
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.STOP
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeVariableSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirClassDeclaredMemberScope(
|
||||
klass: FirRegularClass,
|
||||
session: FirSession,
|
||||
lookupInFir: Boolean = true
|
||||
) : FirAbstractProviderBasedScope(session, lookupInFir) {
|
||||
private val classId = klass.symbol.classId
|
||||
class FirClassDeclaredMemberScope(private val klass: FirRegularClass) : FirScope {
|
||||
override fun processFunctionsByName(name: Name, processor: (ConeFunctionSymbol) -> ProcessorAction) =
|
||||
processCallables(name, processor)
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (ConeFunctionSymbol) -> ProcessorAction): ProcessorAction {
|
||||
val symbols = provider.getCallableSymbols(CallableId(classId.packageFqName, classId.relativeClassName, name))
|
||||
for (symbol in symbols) {
|
||||
if (symbol is ConeFunctionSymbol && !processor(symbol)) {
|
||||
return STOP
|
||||
}
|
||||
override fun processPropertiesByName(name: Name, processor: (ConeVariableSymbol) -> ProcessorAction) =
|
||||
processCallables(name, processor)
|
||||
|
||||
private inline fun <reified T : ConeCallableSymbol> processCallables(
|
||||
name: Name,
|
||||
processor: (T) -> ProcessorAction
|
||||
): ProcessorAction {
|
||||
for (declaration in klass.declarations) {
|
||||
if (declaration !is FirCallableMemberDeclaration) continue
|
||||
|
||||
val symbol = declaration.symbol as? T ?: continue
|
||||
if (symbol.callableId.callableName != name) continue
|
||||
|
||||
if (processor(symbol) == STOP) return STOP
|
||||
}
|
||||
|
||||
return NEXT
|
||||
}
|
||||
|
||||
override fun processPropertiesByName(name: Name, processor: (ConeVariableSymbol) -> ProcessorAction): ProcessorAction {
|
||||
val symbols = provider.getCallableSymbols(CallableId(classId.packageFqName, classId.relativeClassName, name))
|
||||
for (symbol in symbols) {
|
||||
if (symbol is ConePropertySymbol && !processor(symbol)) {
|
||||
return STOP
|
||||
}
|
||||
}
|
||||
return NEXT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -7,14 +7,14 @@ package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.resolve.getClassDeclaredCallableSymbols
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.NEXT
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.STOP
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeVariableSymbol
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirTopLevelDeclaredMemberScope(
|
||||
@@ -25,13 +25,13 @@ class FirTopLevelDeclaredMemberScope(
|
||||
private val packageFqName = file.packageFqName
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (ConeFunctionSymbol) -> ProcessorAction): ProcessorAction {
|
||||
val constructors = provider.getCallableSymbols(CallableId(packageFqName, FqName.topLevel(name), name))
|
||||
val constructors = provider.getClassDeclaredCallableSymbols(ClassId.topLevel(packageFqName.child(name)), name)
|
||||
for (symbol in constructors) {
|
||||
if (symbol is ConeFunctionSymbol && !processor(symbol)) {
|
||||
return STOP
|
||||
}
|
||||
}
|
||||
val symbols = provider.getCallableSymbols(CallableId(packageFqName, name))
|
||||
val symbols = provider.getTopLevelCallableSymbols(packageFqName, name)
|
||||
for (symbol in symbols) {
|
||||
if (symbol is ConeFunctionSymbol && !processor(symbol)) {
|
||||
return STOP
|
||||
@@ -41,7 +41,7 @@ class FirTopLevelDeclaredMemberScope(
|
||||
}
|
||||
|
||||
override fun processPropertiesByName(name: Name, processor: (ConeVariableSymbol) -> ProcessorAction): ProcessorAction {
|
||||
val symbols = provider.getCallableSymbols(CallableId(packageFqName, name))
|
||||
val symbols = provider.getTopLevelCallableSymbols(packageFqName, name)
|
||||
for (symbol in symbols) {
|
||||
if (symbol is ConePropertySymbol && !processor(symbol)) {
|
||||
return STOP
|
||||
@@ -49,4 +49,4 @@ class FirTopLevelDeclaredMemberScope(
|
||||
}
|
||||
return NEXT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetModule
|
||||
@@ -66,7 +65,7 @@ abstract class AbstractFirLoadCompiledKotlin : AbstractFirResolveWithSessionTest
|
||||
val firRenderer = FirRenderer(builder)
|
||||
|
||||
for (name in provider.getAllCallableNamesInPackage(packageFqName)) {
|
||||
for (symbol in provider.getCallableSymbols(CallableId(packageFqName, null, name))) {
|
||||
for (symbol in provider.getTopLevelCallableSymbols(packageFqName, name)) {
|
||||
(symbol as FirCallableSymbol).fir.accept(firRenderer)
|
||||
builder.appendln()
|
||||
}
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -42,7 +41,7 @@ class BuiltInsDeserializationForFirTestCase : AbstractFirResolveWithSessionTestC
|
||||
val firRenderer = FirRenderer(builder)
|
||||
|
||||
for (name in provider.getAllCallableNamesInPackage(packageFqName)) {
|
||||
for (symbol in provider.getCallableSymbols(CallableId(packageFqName, null, name))) {
|
||||
for (symbol in provider.getTopLevelCallableSymbols(packageFqName, name)) {
|
||||
(symbol as FirCallableSymbol).fir.accept(firRenderer)
|
||||
builder.appendln()
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.fir.java.JavaSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeAlias
|
||||
@@ -93,11 +94,13 @@ class IdeFirDependenciesSymbolProvider(
|
||||
return tryKotlin(classId) ?: tryJava(classId)
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(callableId: CallableId): List<ConeCallableSymbol> {
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<ConeCallableSymbol> {
|
||||
// TODO
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId): FirScope? = null
|
||||
|
||||
override fun getPackage(fqName: FqName): FqName? {
|
||||
|
||||
if (PackageIndexUtil.packageExists(fqName, depScope, project)) {
|
||||
|
||||
Reference in New Issue
Block a user