org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2023 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.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.isConst
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.mpp.PropertySymbolMarker
import org.jetbrains.kotlin.mpp.ValueParameterSymbolMarker
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
sealed class FirVariableSymbol(override val callableId: CallableId) : FirCallableSymbol() {
val resolvedInitializer: FirExpression?
get() {
if (fir.initializer == null) return null
val requiredPhase = when {
this.isConst -> FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE
else -> FirResolvePhase.BODY_RESOLVE
}
lazyResolveToPhase(requiredPhase)
return fir.initializer
}
val resolvedDefaultValue: FirExpression?
get() {
val valueParameter = fir as? FirValueParameter
if (valueParameter?.defaultValue == null) return null
lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
return valueParameter.defaultValue
}
val isVal: Boolean
get() = fir.isVal
val isVar: Boolean
get() = fir.isVar
}
open class FirPropertySymbol(callableId: CallableId) : FirVariableSymbol(callableId), PropertySymbolMarker {
// TODO: should we use this constructor for local variables?
constructor(name: Name) : this(CallableId(name))
val isLocal: Boolean
get() = fir.isLocal
open val getterSymbol: FirPropertyAccessorSymbol?
get() = fir.getter?.symbol
open val setterSymbol: FirPropertyAccessorSymbol?
get() = fir.setter?.symbol
val backingFieldSymbol: FirBackingFieldSymbol?
get() = fir.backingField?.symbol
val delegateFieldSymbol: FirDelegateFieldSymbol?
get() = fir.delegateFieldSymbol
val delegate: FirExpression?
get() = fir.delegate
val hasDelegate: Boolean
get() = fir.delegate != null
val hasInitializer: Boolean
get() = fir.initializer != null
val initializerSource: KtSourceElement?
get() = fir.initializer?.source
val controlFlowGraphReference: FirControlFlowGraphReference?
get() {
lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
return fir.controlFlowGraphReference
}
}
class FirIntersectionOverridePropertySymbol(
callableId: CallableId,
override val intersections: Collection>,
override val containsMultipleNonSubsumed: Boolean,
) : FirPropertySymbol(callableId), FirIntersectionCallableSymbol
class FirIntersectionOverrideFieldSymbol(
callableId: CallableId,
override val intersections: Collection>,
override val containsMultipleNonSubsumed: Boolean,
) : FirFieldSymbol(callableId), FirIntersectionCallableSymbol
class FirBackingFieldSymbol(callableId: CallableId) : FirVariableSymbol(callableId) {
val propertySymbol: FirPropertySymbol
get() = fir.propertySymbol
val getterSymbol: FirPropertyAccessorSymbol?
get() = fir.propertySymbol.fir.getter?.symbol
}
class FirDelegateFieldSymbol(callableId: CallableId) : FirVariableSymbol(callableId)
open class FirFieldSymbol(callableId: CallableId) : FirVariableSymbol(callableId) {
val hasInitializer: Boolean
get() = fir.initializer != null
val hasConstantInitializer: Boolean
get() = fir.hasConstantInitializer
}
class FirEnumEntrySymbol(callableId: CallableId) : FirVariableSymbol(callableId) {
val initializerObjectSymbol: FirAnonymousObjectSymbol?
get() = (fir.initializer as? FirAnonymousObjectExpression)?.anonymousObject?.symbol
}
class FirValueParameterSymbol(name: Name) : FirVariableSymbol(CallableId(name)), ValueParameterSymbolMarker {
val hasDefaultValue: Boolean
get() = fir.defaultValue != null
val defaultValueSource: KtSourceElement?
get() = fir.defaultValue?.source
val isCrossinline: Boolean
get() = fir.isCrossinline
val isNoinline: Boolean
get() = fir.isNoinline
val isVararg: Boolean
get() = fir.isVararg
val containingFunctionSymbol: FirFunctionSymbol<*>
get() = fir.containingFunctionSymbol
}
class FirErrorPropertySymbol(
val diagnostic: ConeDiagnostic
) : FirVariableSymbol(CallableId(FqName.ROOT, NAME)) {
companion object {
val NAME: Name = Name.special("")
}
}