Add FirSymbolProvider::getAllCallableNamesInPackage function

- Also, fix implementation of `getCallableNames` in few cases
This commit is contained in:
Roman Golyshev
2020-07-01 14:29:34 +03:00
committed by Ilya Kirillov
parent 97d4918ed3
commit 0f5fc1fa99
7 changed files with 26 additions and 1 deletions
@@ -55,6 +55,8 @@ abstract class FirSymbolProvider : FirSessionComponent {
open fun getNestedClassesNamesInClass(classId: ClassId): Set<Name> = emptySet() open fun getNestedClassesNamesInClass(classId: ClassId): Set<Name> = emptySet()
abstract fun getPackage(fqName: FqName): FqName? // TODO: Replace to symbol sometime abstract fun getPackage(fqName: FqName): FqName? // TODO: Replace to symbol sometime
open fun getAllCallableNamesInPackage(): Set<Name> = emptySet()
} }
fun FirSession.getNestedClassifierScope(lookupTag: ConeClassLikeLookupTag): FirScope? = fun FirSession.getNestedClassifierScope(lookupTag: ConeClassLikeLookupTag): FirScope? =
@@ -46,4 +46,8 @@ class FirCompositeSymbolProvider(val providers: List<FirSymbolProvider>) : FirSy
override fun getNestedClassesNamesInClass(classId: ClassId): Set<Name> { override fun getNestedClassesNamesInClass(classId: ClassId): Set<Name> {
return providers.flatMapTo(mutableSetOf()) { it.getNestedClassesNamesInClass(classId) } return providers.flatMapTo(mutableSetOf()) { it.getNestedClassesNamesInClass(classId) }
} }
override fun getAllCallableNamesInPackage(): Set<Name> {
return providers.flatMapTo(mutableSetOf()) { it.getAllCallableNamesInPackage() }
}
} }
@@ -76,6 +76,12 @@ class FirProviderImpl(val session: FirSession, val kotlinScopeProvider: KotlinSc
klass.accept(FirRecorder, state to owner.file) klass.accept(FirRecorder, state to owner.file)
} }
override fun getAllCallableNamesInPackage(): Set<Name> {
return state.callableMap.keys.asSequence()
.filter { it.className == null }
.mapTo(mutableSetOf()) { it.callableName }
}
private val FirAnnotatedDeclaration.file: FirFile private val FirAnnotatedDeclaration.file: FirFile
get() = when (this) { get() = when (this) {
is FirFile -> this is FirFile -> this
@@ -71,5 +71,5 @@ class FirLocalScope private constructor(
override fun mayContainName(name: Name) = properties.containsKey(name) || functions[name].isNotEmpty() || classes.containsKey(name) override fun mayContainName(name: Name) = properties.containsKey(name) || functions[name].isNotEmpty() || classes.containsKey(name)
override fun getCallableNames(): Set<Name> = properties.keys + functions.keys + classes.keys override fun getCallableNames(): Set<Name> = properties.keys + functions.keys
} }
@@ -56,4 +56,8 @@ class FirPackageMemberScope(val fqName: FqName, val session: FirSession) : FirSc
} }
} }
} }
override fun getCallableNames(): Set<Name> {
return symbolProvider.getAllCallableNamesInPackage()
}
} }
@@ -35,4 +35,8 @@ class FirStaticScope(private val delegateScope: FirScope) : FirScope() {
} }
} }
} }
override fun getCallableNames(): Set<Name> {
return delegateScope.getCallableNames()
}
} }
@@ -166,6 +166,11 @@ internal class FirIdeProvider(
// TODO: check that this implementation is correct // TODO: check that this implementation is correct
cacheProvider.recordGeneratedMember(owner, klass) cacheProvider.recordGeneratedMember(owner, klass)
} }
// TODO this should be reworked because [FirIdeProvider] should not have such method
override fun getAllCallableNamesInPackage(): Set<Name> {
return cacheProvider.getAllCallableNamesInPackage()
}
} }
internal val FirSession.firIdeProvider: FirIdeProvider by FirSession.sessionComponentAccessor() internal val FirSession.firIdeProvider: FirIdeProvider by FirSession.sessionComponentAccessor()