[FIR] Remove FirDeclarationsForMetadataProviderExtension extension
`IrGeneratedDeclarationsRegistrar` should be now used instead to register IR declarations in resulting metadata
This commit is contained in:
+43
-32
@@ -9,22 +9,57 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationsForMetadataProviderExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.declarationForMetadataProviders
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClass
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.getOrPut
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled
|
||||
|
||||
|
||||
/**
|
||||
* This extension can be used to provide information about declarations, which should be written in Kotlin metadata (i.e. be part of a module's ABI),
|
||||
* but for some reason can not (or should not) be generated with [FirDeclarationGenerationExtension]
|
||||
*
|
||||
* Example: assume your plugin generates some constructor in [IrGenerationExtension] which have value parameters matching
|
||||
* all properties of a class, and this constructor is used only as an implementation detail (so the only actor who accesses it
|
||||
* is a plugin itself). The constructor should be accessible from another module, so it should be present in the metadata. But you
|
||||
* can not generate this constructor in [FirDeclarationGenerationExtension], because it depends on types of properties,
|
||||
* which may be not resolved at the moment of constructor creation.
|
||||
*
|
||||
*
|
||||
* // MODULE: a
|
||||
* open class Base {
|
||||
* val x: Int = 1
|
||||
* val y = "hello"
|
||||
*
|
||||
* constructor()
|
||||
*
|
||||
* // generated
|
||||
* constructor(x: Int, y: String) { ... } // (1)
|
||||
* }
|
||||
*
|
||||
* // MODULE: b(a)
|
||||
* class Derived : Base {
|
||||
* val z = 1.0
|
||||
*
|
||||
* constructor() : super()
|
||||
*
|
||||
* // generated
|
||||
* constructor(x: Int, y: String, z: Double) : super(x, y) { ... } // (2)
|
||||
*
|
||||
* // constructor (1) should be presented in metadata of class Base, so IR plugin
|
||||
* // can reference it during generation of constructor (2)
|
||||
* }
|
||||
*
|
||||
* All declarations provided by this extension should be fully resolved and contain all sub declarations if they exist.
|
||||
* E.g. if you want to provide some class then this class should contain all declarations of this class you want to be
|
||||
* present in metadata in `declarations` field of a `FirRegularClass`.
|
||||
* [FirDeclarationGenerationExtension] won't be called for classes provided by this extension.
|
||||
*/
|
||||
abstract class FirProvidedDeclarationsForMetadataService : FirSessionComponent {
|
||||
companion object {
|
||||
fun create(session: FirSession): FirProvidedDeclarationsForMetadataService {
|
||||
val extensionProviders = session.extensionService.declarationForMetadataProviders
|
||||
return if (extensionProviders.isEmpty()) Empty else FirProvidedDeclarationsForMetadataServiceImpl(session, extensionProviders)
|
||||
return FirProvidedDeclarationsForMetadataServiceImpl(session)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,33 +70,9 @@ abstract class FirProvidedDeclarationsForMetadataService : FirSessionComponent {
|
||||
|
||||
abstract fun registerDeclaration(declaration: FirCallableDeclaration)
|
||||
|
||||
private object Empty : FirProvidedDeclarationsForMetadataService() {
|
||||
override fun getProvidedTopLevelDeclarations(packageFqName: FqName, scopeSession: ScopeSession): List<FirDeclaration> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getProvidedConstructors(owner: FirClassSymbol<*>, scopeSession: ScopeSession): List<FirConstructor> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getProvidedCallables(owner: FirClassSymbol<*>, scopeSession: ScopeSession): List<FirCallableDeclaration> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getProvidedNestedClassifiers(owner: FirClassSymbol<*>, scopeSession: ScopeSession): List<FirClassLikeSymbol<*>> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun registerDeclaration(declaration: FirCallableDeclaration) {
|
||||
shouldNotBeCalled()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FirProvidedDeclarationsForMetadataServiceImpl(
|
||||
private val session: FirSession,
|
||||
private val extensionDeclarationProviders: List<FirDeclarationsForMetadataProviderExtension>
|
||||
) : FirProvidedDeclarationsForMetadataService() {
|
||||
private class FirProvidedDeclarationsForMetadataServiceImpl(private val session: FirSession) : FirProvidedDeclarationsForMetadataService() {
|
||||
private val topLevelsCache: MutableMap<FqName, MutableList<FirDeclaration>> =
|
||||
mutableMapOf()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user