[FIR] Add ability to generate members and nested classifiers for generated classes

This commit is contained in:
Dmitriy Novozhilov
2021-09-24 16:54:21 +03:00
committed by TeamCityServer
parent 270962e176
commit f3a9d70eb6
22 changed files with 515 additions and 183 deletions
@@ -17,3 +17,14 @@ inline fun <K : Any, V> FirCache<K, V, Nothing?>.getValue(key: K): V =
operator fun <K : Any, V> FirCache<K, V, Nothing>.contains(key: K): Boolean {
return getValueIfComputed(key) != null
}
class FirLazyValue<out V, in CONTEXT>(private val cache: FirCache<Unit, V, CONTEXT>) {
fun getValue(context: CONTEXT): V {
return cache.getValue(Unit, context)
}
}
@Suppress("NOTHING_TO_INLINE")
inline fun <V> FirLazyValue<V, Nothing?>.getValue(): V {
return getValue(null)
}
@@ -37,6 +37,10 @@ abstract class FirCachesFactory : FirSessionComponent {
createValue: (K, CONTEXT) -> Pair<V, DATA>,
postCompute: (K, V, DATA) -> Unit
): FirCache<K, V, CONTEXT>
fun <V, CONTEXT> createLazyValue(createValue: (CONTEXT) -> V): FirLazyValue<V, CONTEXT> {
return FirLazyValue(createCache { _, context -> createValue(context) })
}
}
val FirSession.firCachesFactory: FirCachesFactory by FirSession.sessionComponentAccessor()
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.fir.declarations
sealed class FirDeclarationOrigin(private val displayName: String? = null, val fromSupertypes: Boolean = false) {
sealed class FirDeclarationOrigin(private val displayName: String? = null, val fromSupertypes: Boolean = false, val generated: Boolean = false) {
object Source : FirDeclarationOrigin()
object Library : FirDeclarationOrigin()
object BuiltIns : FirDeclarationOrigin()
@@ -18,7 +18,7 @@ sealed class FirDeclarationOrigin(private val displayName: String? = null, val f
object IntersectionOverride : FirDeclarationOrigin(fromSupertypes = true)
object Delegated : FirDeclarationOrigin()
class Plugin(val key: FirPluginKey) : FirDeclarationOrigin(displayName = "Plugin[$key]")
class Plugin(val key: FirPluginKey) : FirDeclarationOrigin(displayName = "Plugin[$key]", generated = true)
override fun toString(): String {
return displayName ?: this::class.simpleName!!