org.jetbrains.kotlin.fir.extensions.FirExtensionService.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.extensions
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSessionComponent
import org.jetbrains.kotlin.fir.NoMutableState
import org.jetbrains.kotlin.fir.util.ConeTypeRegistry
import org.jetbrains.kotlin.util.ArrayMapAccessor
import org.jetbrains.kotlin.util.ComponentArrayOwner
import org.jetbrains.kotlin.util.TypeRegistry
import kotlin.reflect.KClass
@RequiresOptIn
annotation class PluginServicesInitialization
@NoMutableState
class FirExtensionService(val session: FirSession) : ComponentArrayOwner>(), FirSessionComponent {
companion object : ConeTypeRegistry>() {
inline fun > registeredExtensions(): ArrayMapAccessor, V> {
@Suppress("UNCHECKED_CAST")
return generateAccessor(P::class, default = emptyList() as V)
}
fun
> registeredExtensions(kClass: KClass
): ArrayMapAccessor, V> {
@Suppress("UNCHECKED_CAST")
return generateAccessor(kClass, default = emptyList() as V)
}
}
override val typeRegistry: TypeRegistry>
get() = Companion
var registeredExtensionsSize: Int = 0
private set
@PluginServicesInitialization
fun registerExtensions(extensionClass: KClass, extensionFactories: List>) {
registeredExtensionsSize += extensionFactories.size
val extensions = extensionFactories.map { it.create(session) }
registerComponent(
extensionClass,
extensions
)
}
@PluginServicesInitialization
fun getAllExtensions(): List {
return arrayMap.flatten()
}
}
val FirSession.extensionService: FirExtensionService by FirSession.sessionComponentAccessor()