FIR: Add components storage to FirSession
This commit is contained in:
committed by
Mikhail Glukhikh
parent
7e95eee9f1
commit
9976eff03a
@@ -5,4 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
interface FirSession
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
interface FirSession {
|
||||
|
||||
|
||||
val components: Map<KClass<*>, Any>
|
||||
|
||||
fun <T : Any> getService(kclass: KClass<T>): T =
|
||||
components[kclass] as T
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> FirSession.service(): T =
|
||||
getService(T::class)
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
abstract class FirSessionBase : FirSession {
|
||||
|
||||
protected fun <T : Any> registerComponent(tClass: KClass<T>, t: T) {
|
||||
assert(tClass !in components) { "Already registered component" }
|
||||
components[tClass] = t
|
||||
}
|
||||
|
||||
override val components: MutableMap<KClass<*>, Any> = mutableMapOf()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user