[FIR] Introduce some typed FirReference.toResolvedXXXSymbol utilities
This commit is contained in:
committed by
Space Team
parent
cffc32ec76
commit
b53c4a6353
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.declarations.utils
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.references.resolvedSymbol
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
@@ -32,7 +32,7 @@ val FirClass.delegateFields: List<FirField>
|
||||
get() = declarations.filterIsInstance<FirField>().filter { it.isSynthetic }
|
||||
|
||||
val FirQualifiedAccess.referredVariableSymbol: FirVariableSymbol<*>?
|
||||
get() = calleeReference.resolvedSymbol as? FirVariableSymbol<*>
|
||||
get() = calleeReference.toResolvedVariableSymbol()
|
||||
|
||||
val FirQualifiedAccess.referredPropertySymbol: FirPropertySymbol?
|
||||
get() = referredVariableSymbol as? FirPropertySymbol
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
||||
@@ -19,7 +18,7 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.resolved
|
||||
import org.jetbrains.kotlin.fir.references.resolvedSymbol
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
@@ -55,7 +54,7 @@ inline val FirCall.dynamicVarargArguments: List<FirExpression>?
|
||||
get() = dynamicVararg?.arguments
|
||||
|
||||
inline val FirFunctionCall.isCalleeDynamic: Boolean
|
||||
get() = (calleeReference.resolvedSymbol?.fir as? FirFunction)?.origin == FirDeclarationOrigin.DynamicScope
|
||||
get() = calleeReference.toResolvedFunctionSymbol()?.origin == FirDeclarationOrigin.DynamicScope
|
||||
|
||||
inline val FirCall.resolvedArgumentMapping: LinkedHashMap<FirExpression, FirValueParameter>?
|
||||
get() = when (val argumentList = argumentList) {
|
||||
|
||||
@@ -6,11 +6,49 @@
|
||||
package org.jetbrains.kotlin.fir.references
|
||||
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
|
||||
val FirReference.resolved: FirResolvedNamedReference? get() = this as? FirResolvedNamedReference
|
||||
val FirReference.resolvedSymbol: FirBasedSymbol<*>? get() = resolved?.resolvedSymbol
|
||||
|
||||
fun FirReference.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
||||
return this.resolvedSymbol as? FirCallableSymbol<*>
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE",)
|
||||
inline fun <reified T : FirBasedSymbol<*>> FirReference.toResolvedSymbol(
|
||||
discardErrorReference: Boolean = false
|
||||
): @kotlin.internal.NoInfer T? {
|
||||
val resolvedReference = resolved ?: return null
|
||||
if (discardErrorReference && resolvedReference is FirResolvedErrorReference) {
|
||||
return null
|
||||
}
|
||||
return resolvedReference.resolvedSymbol as? T
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedBaseSymbol(discardErrorReference: Boolean = false): FirBasedSymbol<*>? {
|
||||
return this.toResolvedSymbol<FirBasedSymbol<*>>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedCallableSymbol(discardErrorReference: Boolean = false): FirCallableSymbol<*>? {
|
||||
return this.toResolvedSymbol<FirCallableSymbol<*>>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedTypeParameterSymbol(discardErrorReference: Boolean = false): FirTypeParameterSymbol? {
|
||||
return this.toResolvedSymbol<FirTypeParameterSymbol>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedVariableSymbol(discardErrorReference: Boolean = false): FirVariableSymbol<*>? {
|
||||
return this.toResolvedSymbol<FirVariableSymbol<*>>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedPropertySymbol(discardErrorReference: Boolean = false): FirPropertySymbol? {
|
||||
return this.toResolvedSymbol<FirPropertySymbol>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedValueParameterSymbol(discardErrorReference: Boolean = false): FirValueParameterSymbol? {
|
||||
return this.toResolvedSymbol<FirValueParameterSymbol>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedFunctionSymbol(discardErrorReference: Boolean = false): FirNamedFunctionSymbol? {
|
||||
return this.toResolvedSymbol<FirNamedFunctionSymbol>(discardErrorReference)
|
||||
}
|
||||
|
||||
fun FirReference.toResolvedConstructorSymbol(discardErrorReference: Boolean = false): FirConstructorSymbol? {
|
||||
return this.toResolvedSymbol<FirConstructorSymbol>(discardErrorReference)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.references.resolvedSymbol
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.name.*
|
||||
|
||||
@@ -61,10 +61,7 @@ class FirConstructorSymbol(
|
||||
get() = fir.isPrimary
|
||||
|
||||
val resolvedDelegatedConstructor: FirConstructorSymbol?
|
||||
get() {
|
||||
val delegatedConstructorCall = resolvedDelegatedConstructorCall ?: return null
|
||||
return delegatedConstructorCall.calleeReference.resolvedSymbol as? FirConstructorSymbol
|
||||
}
|
||||
get() = resolvedDelegatedConstructorCall?.calleeReference?.toResolvedConstructorSymbol()
|
||||
|
||||
val resolvedDelegatedConstructorCall: FirDelegatedConstructorCall?
|
||||
get() {
|
||||
|
||||
Reference in New Issue
Block a user