[FIR] Add workaround for KT-19306
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.types
|
package org.jetbrains.kotlin.fir.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.utils.AttributeArrayOwner
|
import org.jetbrains.kotlin.fir.utils.AttributeArrayOwner
|
||||||
|
import org.jetbrains.kotlin.fir.utils.Protected
|
||||||
import org.jetbrains.kotlin.fir.utils.TypeRegistry
|
import org.jetbrains.kotlin.fir.utils.TypeRegistry
|
||||||
import org.jetbrains.kotlin.fir.utils.isEmpty
|
import org.jetbrains.kotlin.fir.utils.isEmpty
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
@@ -20,6 +21,7 @@ abstract class ConeAttribute<T : ConeAttribute<T>> {
|
|||||||
abstract val key: KClass<out T>
|
abstract val key: KClass<out T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(Protected::class)
|
||||||
class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : AttributeArrayOwner<ConeAttribute<*>, ConeAttribute<*>>() {
|
class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : AttributeArrayOwner<ConeAttribute<*>, ConeAttribute<*>>() {
|
||||||
companion object : TypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() {
|
companion object : TypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() {
|
||||||
inline fun <reified T : ConeAttribute<T>> attributeAccessor(): ReadOnlyProperty<ConeAttributes, T?> {
|
inline fun <reified T : ConeAttribute<T>> attributeAccessor(): ReadOnlyProperty<ConeAttributes, T?> {
|
||||||
|
|||||||
@@ -10,8 +10,14 @@ import kotlin.properties.ReadOnlyProperty
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
@RequiresOptIn
|
||||||
|
annotation class Protected
|
||||||
|
|
||||||
|
@OptIn(Protected::class)
|
||||||
abstract class AbstractArrayMapOwner<K : Any, V : Any> {
|
abstract class AbstractArrayMapOwner<K : Any, V : Any> {
|
||||||
protected abstract val arrayMap: ArrayMap<V>
|
// TODO: make [arrayMap] protected and remove annotation after KT-19306 fix
|
||||||
|
@get:Protected
|
||||||
|
abstract val arrayMap: ArrayMap<V>
|
||||||
protected abstract val typeRegistry: TypeRegistry<K, V>
|
protected abstract val typeRegistry: TypeRegistry<K, V>
|
||||||
|
|
||||||
abstract class AbstractArrayMapAccessor<K : Any, V : Any, T : V>(
|
abstract class AbstractArrayMapAccessor<K : Any, V : Any, T : V>(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import kotlin.reflect.KClass
|
|||||||
* Note that you can remove attributes from [AttributeArrayOwner] despite
|
* Note that you can remove attributes from [AttributeArrayOwner] despite
|
||||||
* from components in [ComponentArrayOwner]
|
* from components in [ComponentArrayOwner]
|
||||||
*/
|
*/
|
||||||
|
@OptIn(Protected::class)
|
||||||
abstract class AttributeArrayOwner<K : Any, T : Any> : AbstractArrayMapOwner<K, T>() {
|
abstract class AttributeArrayOwner<K : Any, T : Any> : AbstractArrayMapOwner<K, T>() {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
final override var arrayMap: ArrayMap<T> = EmptyArrayMap as ArrayMap<T>
|
final override var arrayMap: ArrayMap<T> = EmptyArrayMap as ArrayMap<T>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlin.reflect.KClass
|
|||||||
* [ComponentArrayOwner] based on [ArrayMap] with flexible size and should be used for
|
* [ComponentArrayOwner] based on [ArrayMap] with flexible size and should be used for
|
||||||
* storing services in entities with limited number of instances, like FirSession
|
* storing services in entities with limited number of instances, like FirSession
|
||||||
*/
|
*/
|
||||||
|
@OptIn(Protected::class)
|
||||||
abstract class ComponentArrayOwner<K : Any, V : Any> : AbstractArrayMapOwner<K, V>() {
|
abstract class ComponentArrayOwner<K : Any, V : Any> : AbstractArrayMapOwner<K, V>() {
|
||||||
final override val arrayMap: ArrayMap<V> =
|
final override val arrayMap: ArrayMap<V> =
|
||||||
ArrayMapImpl()
|
ArrayMapImpl()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
|||||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||||
import org.jetbrains.kotlin.fir.utils.ArrayMapAccessor
|
import org.jetbrains.kotlin.fir.utils.ArrayMapAccessor
|
||||||
import org.jetbrains.kotlin.fir.utils.ComponentArrayOwner
|
import org.jetbrains.kotlin.fir.utils.ComponentArrayOwner
|
||||||
|
import org.jetbrains.kotlin.fir.utils.Protected
|
||||||
import org.jetbrains.kotlin.fir.utils.TypeRegistry
|
import org.jetbrains.kotlin.fir.utils.TypeRegistry
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ class FirExtensionService(val session: FirSession) : ComponentArrayOwner<FirExte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PluginServicesInitialization
|
@PluginServicesInitialization
|
||||||
|
@OptIn(Protected::class)
|
||||||
fun getAllExtensions(): List<FirExtension> {
|
fun getAllExtensions(): List<FirExtension> {
|
||||||
return arrayMap.flatten()
|
return arrayMap.flatten()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user