[FIR] Add methods to collect all class and callable ids from extensions

They will be needed for generating IR for all declarations from plugins
This commit is contained in:
Dmitriy Novozhilov
2021-09-30 16:12:54 +03:00
committed by TeamCityServer
parent 9baf10cfcc
commit 79f1779d89
3 changed files with 20 additions and 1 deletions
@@ -38,8 +38,11 @@ abstract class FirDeclarationGenerationExtension(session: FirSession) : FirPredi
// Can be called on IMPORTS stage
open fun hasPackage(packageFqName: FqName): Boolean = false
// Can be called after BODY_RESOLVE stage (checkers and fir2ir)
open fun getCallableNamesForClass(classSymbol: FirClassSymbol<*>): Set<Name> = emptySet()
open fun getNestedClassifiersNames(classSymbol: FirClassSymbol<*>): Set<Name> = emptySet()
open fun getTopLevelCallableIds(): Set<CallableId> = emptySet()
open fun getTopLevelClassIds(): Set<ClassId> = emptySet()
fun interface Factory : FirExtension.Factory<FirDeclarationGenerationExtension>
}
@@ -151,6 +151,10 @@ class AllOpenClassGenerator(session: FirSession) : FirDeclarationGenerationExten
}
}
override fun getTopLevelClassIds(): Set<ClassId> {
return setOf(GENERATED_CLASS_ID)
}
override fun hasPackage(packageFqName: FqName): Boolean {
return packageFqName == FOO_PACKAGE
}
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) {
@@ -66,7 +67,18 @@ class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclaration
if (callableId.classId != null) return null
return matchedClasses
.filter { it.classId.packageFqName == callableId.packageName }
.firstOrNull { callableId.callableName.identifier == "dummy${it.classId.shortClassName.identifier}" }
.firstOrNull { callableId.callableName.identifier == it.classId.toDummyCallableName() }
}
private fun ClassId.toDummyCallableName(): String {
return "dummy${shortClassName.identifier}"
}
override fun getTopLevelCallableIds(): Set<CallableId> {
return matchedClasses.mapTo(mutableSetOf()) {
val classId = it.classId
CallableId(classId.packageFqName, Name.identifier(classId.toDummyCallableName()))
}
}
override val key: AllOpenPluginKey