[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:
committed by
TeamCityServer
parent
9baf10cfcc
commit
79f1779d89
+3
@@ -38,8 +38,11 @@ abstract class FirDeclarationGenerationExtension(session: FirSession) : FirPredi
|
|||||||
// Can be called on IMPORTS stage
|
// Can be called on IMPORTS stage
|
||||||
open fun hasPackage(packageFqName: FqName): Boolean = false
|
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 getCallableNamesForClass(classSymbol: FirClassSymbol<*>): Set<Name> = emptySet()
|
||||||
open fun getNestedClassifiersNames(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>
|
fun interface Factory : FirExtension.Factory<FirDeclarationGenerationExtension>
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -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 {
|
override fun hasPackage(packageFqName: FqName): Boolean {
|
||||||
return packageFqName == FOO_PACKAGE
|
return packageFqName == FOO_PACKAGE
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -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.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||||
import org.jetbrains.kotlin.name.CallableId
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) {
|
class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) {
|
||||||
@@ -66,7 +67,18 @@ class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclaration
|
|||||||
if (callableId.classId != null) return null
|
if (callableId.classId != null) return null
|
||||||
return matchedClasses
|
return matchedClasses
|
||||||
.filter { it.classId.packageFqName == callableId.packageName }
|
.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
|
override val key: AllOpenPluginKey
|
||||||
|
|||||||
Reference in New Issue
Block a user