[FIR] Add accessors to parts of signatures to symbols
This commit is contained in:
committed by
teamcityserver
parent
0f06ab537f
commit
d3966e8844
@@ -5,7 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.symbols
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
|
||||
abstract class FirBasedSymbol<E : FirDeclaration> {
|
||||
private var _fir: E? = null
|
||||
@@ -17,4 +20,13 @@ abstract class FirBasedSymbol<E : FirDeclaration> {
|
||||
fun bind(e: E) {
|
||||
_fir = e
|
||||
}
|
||||
|
||||
val origin: FirDeclarationOrigin
|
||||
get() = fir.origin
|
||||
|
||||
val source: FirSourceElement?
|
||||
get() = fir.source
|
||||
|
||||
val moduleData: FirModuleData
|
||||
get() = fir.moduleData
|
||||
}
|
||||
|
||||
@@ -5,16 +5,59 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class FirCallableSymbol<D : FirCallableDeclaration> : FirBasedSymbol<D>() {
|
||||
abstract val callableId: CallableId
|
||||
|
||||
val resolvedReturnTypeRef: FirResolvedTypeRef
|
||||
get() {
|
||||
ensureType(fir.returnTypeRef)
|
||||
return fir.returnTypeRef as FirResolvedTypeRef
|
||||
}
|
||||
|
||||
val resolvedReceiverTypeRef: FirResolvedTypeRef?
|
||||
get() {
|
||||
ensureType(fir.receiverTypeRef)
|
||||
return fir.receiverTypeRef as FirResolvedTypeRef?
|
||||
}
|
||||
|
||||
val resolvedStatus: FirResolvedDeclarationStatus
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.STATUS)
|
||||
return fir.status as FirResolvedDeclarationStatus
|
||||
}
|
||||
|
||||
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
||||
get() {
|
||||
return fir.typeParameters.map { it.symbol }
|
||||
}
|
||||
|
||||
val dispatchReceiverType: ConeKotlinType?
|
||||
get() = fir.dispatchReceiverType
|
||||
|
||||
val name: Name
|
||||
get() = callableId.callableName
|
||||
|
||||
val deprecation: DeprecationsPerUseSite?
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.STATUS)
|
||||
return fir.deprecation
|
||||
}
|
||||
|
||||
private fun ensureType(typeRef: FirTypeRef?) {
|
||||
when (typeRef) {
|
||||
null, is FirResolvedTypeRef -> {}
|
||||
is FirImplicitTypeRef -> ensureResolved(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE)
|
||||
else -> ensureResolved(FirResolvePhase.TYPES)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = "${this::class.simpleName} $callableId"
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -20,19 +24,62 @@ sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
||||
}
|
||||
|
||||
sealed class FirClassSymbol<C : FirClass>(classId: ClassId) : FirClassLikeSymbol<C>(classId) {
|
||||
private val lookupTag =
|
||||
private val lookupTag: ConeClassLikeLookupTag =
|
||||
if (classId.isLocal) ConeClassLookupTagWithFixedSymbol(classId, this)
|
||||
else ConeClassLikeLookupTagImpl(classId)
|
||||
|
||||
override fun toLookupTag(): ConeClassLikeLookupTag = lookupTag
|
||||
|
||||
val resolvedSuperTypeRefs: List<FirResolvedTypeRef>
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.SUPER_TYPES)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return fir.superTypeRefs as List<FirResolvedTypeRef>
|
||||
}
|
||||
|
||||
val declarationSymbols: List<FirBasedSymbol<*>>
|
||||
get() {
|
||||
return fir.declarations.map { it.symbol }
|
||||
}
|
||||
|
||||
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
||||
get() {
|
||||
return fir.typeParameters.map { it.symbol }
|
||||
}
|
||||
|
||||
val classKind: ClassKind
|
||||
get() = fir.classKind
|
||||
}
|
||||
|
||||
class FirRegularClassSymbol(classId: ClassId) : FirClassSymbol<FirRegularClass>(classId)
|
||||
class FirRegularClassSymbol(classId: ClassId) : FirClassSymbol<FirRegularClass>(classId) {
|
||||
val resolvedStatus: FirResolvedDeclarationStatus
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.STATUS)
|
||||
return fir.status as FirResolvedDeclarationStatus
|
||||
}
|
||||
}
|
||||
|
||||
val ANONYMOUS_CLASS_ID = ClassId(FqName.ROOT, FqName.topLevel(Name.special("<anonymous>")), true)
|
||||
|
||||
class FirAnonymousObjectSymbol : FirClassSymbol<FirAnonymousObject>(ANONYMOUS_CLASS_ID)
|
||||
|
||||
class FirTypeAliasSymbol(classId: ClassId) : FirClassLikeSymbol<FirTypeAlias>(classId) {
|
||||
override fun toLookupTag() = ConeClassLikeLookupTagImpl(classId)
|
||||
override fun toLookupTag(): ConeClassLikeLookupTag = ConeClassLikeLookupTagImpl(classId)
|
||||
|
||||
val resolvedStatus: FirResolvedDeclarationStatus
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.STATUS)
|
||||
return fir.status as FirResolvedDeclarationStatus
|
||||
}
|
||||
|
||||
val resolvedExpandedTypeRef: FirResolvedTypeRef
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.SUPER_TYPES)
|
||||
return fir.expandedTypeRef as FirResolvedTypeRef
|
||||
}
|
||||
|
||||
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
||||
get() {
|
||||
return fir.typeParameters.map { it.symbol }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,30 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.symbols.AccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
sealed class FirFunctionSymbol<D : FirFunction>(
|
||||
override val callableId: CallableId
|
||||
) : FirCallableSymbol<D>()
|
||||
) : FirCallableSymbol<D>() {
|
||||
val valueParameterSymbols: List<FirValueParameterSymbol>
|
||||
get() = fir.valueParameters.map { it.symbol }
|
||||
|
||||
val resolvedContractDescription: FirResolvedContractDescription?
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.CONTRACTS)
|
||||
return when (this) {
|
||||
is FirNamedFunctionSymbol -> fir.contractDescription
|
||||
is FirPropertyAccessorSymbol -> fir.contractDescription
|
||||
else -> null
|
||||
} as? FirResolvedContractDescription
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------ named ------------------------
|
||||
|
||||
|
||||
+17
-1
@@ -5,12 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class FirTypeParameterSymbol : FirClassifierSymbol<FirTypeParameter>() {
|
||||
|
||||
val name: Name
|
||||
get() = fir.name
|
||||
|
||||
@@ -19,5 +22,18 @@ class FirTypeParameterSymbol : FirClassifierSymbol<FirTypeParameter>() {
|
||||
override fun toLookupTag(): ConeTypeParameterLookupTag = lookupTag
|
||||
|
||||
override fun toString(): String = "${this::class.simpleName} ${name.asString()}"
|
||||
|
||||
val resolvedBounds: List<FirResolvedTypeRef>
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.TYPES)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return fir.bounds as List<FirResolvedTypeRef>
|
||||
}
|
||||
|
||||
val variance: Variance
|
||||
get() = fir.variance
|
||||
|
||||
val isReified: Boolean
|
||||
get() = fir.isReified
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -19,6 +20,33 @@ open class FirPropertySymbol(
|
||||
) : FirVariableSymbol<FirProperty>(callableId) {
|
||||
// TODO: should we use this constructor for local variables?
|
||||
constructor(name: Name) : this(CallableId(name))
|
||||
|
||||
val isLocal: Boolean
|
||||
get() = fir.isLocal
|
||||
|
||||
val getterSymbol: FirPropertyAccessorSymbol?
|
||||
get() = fir.getter?.symbol
|
||||
|
||||
val setterSymbol: FirPropertyAccessorSymbol?
|
||||
get() = fir.setter?.symbol
|
||||
|
||||
val hasInitializer: Boolean
|
||||
get() = fir.initializer != null
|
||||
|
||||
val hasDelegate: Boolean
|
||||
get() = fir.delegate != null
|
||||
|
||||
val controlFlowGraphReference: FirControlFlowGraphReference?
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.BODY_RESOLVE)
|
||||
return fir.controlFlowGraphReference
|
||||
}
|
||||
|
||||
val isVal: Boolean
|
||||
get() = fir.isVal
|
||||
|
||||
val isVar: Boolean
|
||||
get() = fir.isVar
|
||||
}
|
||||
|
||||
class FirIntersectionOverridePropertySymbol(
|
||||
@@ -26,20 +54,36 @@ class FirIntersectionOverridePropertySymbol(
|
||||
override val intersections: Collection<FirCallableSymbol<*>>
|
||||
) : FirPropertySymbol(callableId), FirIntersectionCallableSymbol
|
||||
|
||||
class FirBackingFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirProperty>(callableId)
|
||||
class FirBackingFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirProperty>(callableId) {
|
||||
val isVal: Boolean
|
||||
get() = fir.isVal
|
||||
|
||||
class FirDelegateFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirProperty>(callableId) {
|
||||
val delegate: FirExpression
|
||||
get() = fir.delegate!!
|
||||
val isVar: Boolean
|
||||
get() = fir.isVar
|
||||
|
||||
val getterSymbol: FirPropertyAccessorSymbol?
|
||||
get() = fir.getter?.symbol
|
||||
}
|
||||
|
||||
class FirDelegateFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirProperty>(callableId)
|
||||
|
||||
class FirFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirField>(callableId)
|
||||
|
||||
class FirEnumEntrySymbol(callableId: CallableId) : FirVariableSymbol<FirEnumEntry>(callableId)
|
||||
|
||||
class FirValueParameterSymbol(name: Name) : FirVariableSymbol<FirValueParameter>(CallableId(name)) {
|
||||
val name: Name
|
||||
get() = callableId.callableName
|
||||
val hasDefaultValue: Boolean
|
||||
get() = fir.defaultValue != null
|
||||
|
||||
val isCrossinline: Boolean
|
||||
get() = fir.isCrossinline
|
||||
|
||||
val isNoinline: Boolean
|
||||
get() = fir.isNoinline
|
||||
|
||||
val isVararg: Boolean
|
||||
get() = fir.isVararg
|
||||
|
||||
}
|
||||
|
||||
class FirErrorPropertySymbol(
|
||||
|
||||
Reference in New Issue
Block a user