All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.util.ComponentArrayOwner.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2021 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.util

import kotlin.reflect.KClass

/**
 * [ComponentArrayOwner] based on [ArrayMap] with flexible size and should be used for
 *   storing services in entities with limited number of instances, like FirSession
 */
abstract class ComponentArrayOwner : AbstractArrayMapOwner() {
    final override val arrayMap: ArrayMap =
        ArrayMapImpl()

    final override fun registerComponent(tClass: KClass, value: V) {
        arrayMap[typeRegistry.getId(tClass)] = value
    }

    protected operator fun get(key: KClass): V {
        val id = typeRegistry.getId(key)
        return arrayMap[id] ?: error("No '$key'($id) component in array: $this")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy