FIR: Add components storage to FirSession

This commit is contained in:
Simon Ogorodnik
2018-03-20 01:08:56 +03:00
committed by Mikhail Glukhikh
parent 7e95eee9f1
commit 9976eff03a
3 changed files with 34 additions and 3 deletions
@@ -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()
}