Add FirScope::getCallableNames function

This commit is contained in:
Roman Golyshev
2020-07-01 14:21:45 +03:00
committed by Ilya Kirillov
parent 1f3add49f4
commit 656086f90a
7 changed files with 43 additions and 0 deletions
@@ -55,6 +55,28 @@ class FirSignatureEnhancement(
FirJavaEnhancementContext(session) { null }.copyWithNewDefaultTypeQualifiers(typeQualifierResolver, jsr305State, owner.annotations)
private val enhancements = mutableMapOf<FirCallableSymbol<*>, FirCallableSymbol<*>>()
private val overriddenFunctions = mutableMapOf<FirFunctionSymbol<*>, Collection<FirFunctionSymbol<*>>>()
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
useSiteMemberScope.processPropertiesByName(name) process@{ original ->
val field = enhancements.getOrPut(original) { enhance(original, name) }
processor(field as FirVariableSymbol<*>)
}
return super.processPropertiesByName(name, processor)
}
override fun getCallableNames(): Set<Name> {
return useSiteMemberScope.getCallableNames() + super.getCallableNames()
}
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
useSiteMemberScope.processFunctionsByName(name) process@{ original ->
val function = enhancements.getOrPut(original) { enhance(original, name) }
processor(function as FirFunctionSymbol<*>)
}
fun enhancedFunction(
function: FirFunctionSymbol<*>,
@@ -45,6 +45,10 @@ class JavaClassUseSiteMemberScope(
}
}
override fun getCallableNames(): Set<Name> {
return declaredMemberScope.getCallableNames() + superTypesScope.getCallableNames()
}
private fun generateAccessorSymbol(
functionSymbol: FirFunctionSymbol<*>,
syntheticPropertyName: Name,
@@ -130,4 +130,8 @@ abstract class AbstractFirUseSiteMemberScope(
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
declaredMemberScope.processDeclaredConstructors(processor)
}
override fun getCallableNames(): Set<Name> {
return declaredMemberScope.getCallableNames() + superTypesScope.getCallableNames()
}
}
@@ -76,6 +76,10 @@ class FirClassDeclaredMemberScope(
) {
nestedClassifierScope?.processClassifiersByNameWithSubstitution(name, processor)
}
override fun getCallableNames(): Set<Name> {
return callablesIndex.keys
}
}
@@ -341,6 +341,10 @@ class FirTypeIntersectionScope private constructor(
return ProcessorAction.NEXT
}
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(mutableSetOf()) { it.getCallableNames() }
}
companion object {
fun prepareIntersectionScope(
session: FirSession,
@@ -44,4 +44,8 @@ class FirCompositeScope(private val scopes: Iterable<FirScope>) : FirScope() {
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
return processComposite(FirScope::processPropertiesByName, name, processor)
}
override fun getCallableNames(): Set<Name> {
return scopes.flatMapTo(mutableSetOf()) { it.getCallableNames() }
}
}
@@ -34,6 +34,7 @@ abstract class FirScope {
open fun mayContainName(name: Name) = true
open fun getCallableNames(): Set<Name> = emptySet()
}
fun FirTypeScope.processOverriddenFunctionsAndSelf(