[FIR] Properly collect constructors from class in presence of plugins
This commit is contained in:
committed by
TeamCityServer
parent
6712191538
commit
af6d6ec2b9
+1
-35
@@ -5,14 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.utils
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -38,24 +34,6 @@ val FirClass.superConeTypes: List<ConeClassLikeType> get() = superTypeRefs.mapNo
|
||||
val FirClass.anonymousInitializers: List<FirAnonymousInitializer>
|
||||
get() = declarations.filterIsInstance<FirAnonymousInitializer>()
|
||||
|
||||
val FirClass.constructors: List<FirConstructor>
|
||||
get() = declarations.filterIsInstance<FirConstructor>()
|
||||
|
||||
val FirConstructor.delegatedThisConstructor: FirConstructor?
|
||||
get() = delegatedConstructor?.takeIf { it.isThis }
|
||||
?.let { (it.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol?.fir as? FirConstructor }
|
||||
|
||||
val FirClass.constructorsSortedByDelegation: List<FirConstructor>
|
||||
get() = constructors.sortedWith(ConstructorDelegationComparator)
|
||||
|
||||
val FirClass.primaryConstructor: FirConstructor?
|
||||
get() = constructors.find(FirConstructor::isPrimary)
|
||||
|
||||
fun FirRegularClass.collectEnumEntries(): Collection<FirEnumEntry> {
|
||||
assert(classKind == ClassKind.ENUM_CLASS)
|
||||
return declarations.filterIsInstance<FirEnumEntry>()
|
||||
}
|
||||
|
||||
val FirQualifiedAccess.referredPropertySymbol: FirPropertySymbol?
|
||||
get() {
|
||||
val reference = calleeReference as? FirResolvedNamedReference ?: return null
|
||||
@@ -69,16 +47,4 @@ inline val FirDeclaration.isFromLibrary: Boolean
|
||||
inline val FirDeclaration.isSynthetic: Boolean
|
||||
get() = origin == FirDeclarationOrigin.Synthetic
|
||||
|
||||
private object ConstructorDelegationComparator : Comparator<FirConstructor> {
|
||||
override fun compare(p0: FirConstructor?, p1: FirConstructor?): Int {
|
||||
if (p0 == null && p1 == null) return 0
|
||||
if (p0 == null) return -1
|
||||
if (p1 == null) return 1
|
||||
if (p0.delegatedThisConstructor == p1) return 1
|
||||
if (p1.delegatedThisConstructor == p0) return -1
|
||||
// If neither is a delegation to each other, the order doesn't matter.
|
||||
// Here we return 0 to preserve the original order.
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ package org.jetbrains.kotlin.fir.symbols.impl
|
||||
import org.jetbrains.kotlin.fir.FirLabel
|
||||
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.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.AccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
@@ -30,6 +33,12 @@ sealed class FirFunctionSymbol<D : FirFunction>(
|
||||
else -> null
|
||||
} as? FirResolvedContractDescription
|
||||
}
|
||||
|
||||
val resolvedControlFlowGraphReference: FirControlFlowGraphReference?
|
||||
get() {
|
||||
ensureResolved(FirResolvePhase.BODY_RESOLVE)
|
||||
return fir.controlFlowGraphReference
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------ named ------------------------
|
||||
@@ -52,6 +61,25 @@ class FirConstructorSymbol(
|
||||
) : FirFunctionSymbol<FirConstructor>(callableId) {
|
||||
val isPrimary: Boolean
|
||||
get() = fir.isPrimary
|
||||
|
||||
val resolvedDelegatedConstructor: FirConstructorSymbol?
|
||||
get() {
|
||||
val delegatedConstructorCall = resolvedDelegatedConstructorCall ?: return null
|
||||
return (delegatedConstructorCall.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirConstructorSymbol
|
||||
}
|
||||
|
||||
val resolvedDelegatedConstructorCall: FirDelegatedConstructorCall?
|
||||
get() {
|
||||
if (fir.delegatedConstructor == null) return null
|
||||
ensureResolved(FirResolvePhase.BODY_RESOLVE)
|
||||
return fir.delegatedConstructor
|
||||
}
|
||||
|
||||
val delegatedConstructorCallIsThis: Boolean
|
||||
get() = fir.delegatedConstructor?.isThis ?: false
|
||||
|
||||
val delegatedConstructorCallIsSuper: Boolean
|
||||
get() = fir.delegatedConstructor?.isSuper ?: false
|
||||
}
|
||||
|
||||
open class FirAccessorSymbol(
|
||||
|
||||
Reference in New Issue
Block a user