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

org.jetbrains.kotlin.fir.symbols.Fir2IrBindableSymbol.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2020 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.fir.symbols

import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.descriptors.*
import org.jetbrains.kotlin.ir.symbols.IrBindableSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.render

abstract class Fir2IrBindableSymbol(
    override val signature: IdSignature,
) : IrBindableSymbol {

    private var _owner: B? = null

    @UnsafeDuringIrConstructionAPI
    override val owner: B
        get() = _owner ?: throw IllegalStateException("Symbol is unbound")

    override fun bind(owner: B) {
        if (_owner == null) {
            _owner = owner
        } else {
            throw IllegalStateException("${javaClass.simpleName} for $signature is already bound")
        }
    }

    override val isBound: Boolean
        get() = _owner != null

    @OptIn(UnsafeDuringIrConstructionAPI::class)
    @ObsoleteDescriptorBasedAPI
    override val descriptor: D
        @Suppress("UNCHECKED_CAST")
        get() = owner.toIrBasedDescriptor() as D

    @ObsoleteDescriptorBasedAPI
    override val hasDescriptor: Boolean
        get() = false

    override var privateSignature: IdSignature? = null

    @OptIn(UnsafeDuringIrConstructionAPI::class)
    override fun toString(): String {
        if (isBound) return owner.render()
        return "Unbound public symbol for $signature"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy