FIR: rename util to retrieve primary constructor
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
1090eca086
commit
d348e58183
@@ -91,7 +91,7 @@ class Fir2IrConverter(
|
||||
anonymousObject: FirAnonymousObject,
|
||||
irClass: IrClass = classifierStorage.getCachedIrClass(anonymousObject)!!
|
||||
): IrClass {
|
||||
anonymousObject.getPrimaryConstructorIfAny()?.let {
|
||||
anonymousObject.primaryConstructor?.let {
|
||||
irClass.declarations += declarationStorage.createIrConstructor(
|
||||
it, irClass, isLocal = true
|
||||
)
|
||||
@@ -127,7 +127,7 @@ class Fir2IrConverter(
|
||||
regularClass: FirRegularClass,
|
||||
irClass: IrClass = classifierStorage.getCachedIrClass(regularClass)!!
|
||||
): IrClass {
|
||||
val irConstructor = regularClass.getPrimaryConstructorIfAny()?.let {
|
||||
val irConstructor = regularClass.primaryConstructor?.let {
|
||||
declarationStorage.getOrCreateIrConstructor(it, irClass, isLocal = regularClass.isLocal)
|
||||
}
|
||||
if (irConstructor != null) {
|
||||
|
||||
@@ -125,8 +125,7 @@ class Fir2IrVisitor(
|
||||
} else if (initializer is FirAnonymousObject) {
|
||||
// Otherwise, this is a default-ish enum entry, which doesn't need its own synthetic class.
|
||||
// During raw FIR building, we put the delegated constructor call inside an anonymous object.
|
||||
val primaryConstructor = initializer.getPrimaryConstructorIfAny()
|
||||
val delegatedConstructor = primaryConstructor?.delegatedConstructor
|
||||
val delegatedConstructor = initializer.primaryConstructor?.delegatedConstructor
|
||||
if (delegatedConstructor != null) {
|
||||
with(memberGenerator) {
|
||||
irEnumEntry.initializerExpression = irFactory.createExpressionBody(
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ internal class ClassMemberGenerator(
|
||||
fun convertClassContent(irClass: IrClass, klass: FirClass<*>) {
|
||||
declarationStorage.enterScope(irClass)
|
||||
conversionScope.withClass(irClass) {
|
||||
val primaryConstructor = klass.getPrimaryConstructorIfAny()
|
||||
val primaryConstructor = klass.primaryConstructor
|
||||
val irPrimaryConstructor = primaryConstructor?.let { declarationStorage.getCachedIrConstructor(it)!! }
|
||||
if (irPrimaryConstructor != null) {
|
||||
with(declarationStorage) {
|
||||
|
||||
+1
-1
@@ -454,7 +454,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
}
|
||||
val labelName =
|
||||
if (anonymousObject.classKind == ClassKind.ENUM_ENTRY) {
|
||||
anonymousObject.getPrimaryConstructorIfAny()?.symbol?.callableId?.className?.shortName()
|
||||
anonymousObject.primaryConstructor?.symbol?.callableId?.className?.shortName()
|
||||
} else null
|
||||
val result = withScopesForClass(labelName, anonymousObject, type) {
|
||||
transformDeclarationContent(anonymousObject, data).single as FirAnonymousObject
|
||||
|
||||
@@ -144,8 +144,8 @@ private object ConstructorDelegationComparator : Comparator<FirConstructor> {
|
||||
val FirClass<*>.constructorsSortedByDelegation: List<FirConstructor>
|
||||
get() = constructors.sortedWith(ConstructorDelegationComparator)
|
||||
|
||||
fun FirClass<*>.getPrimaryConstructorIfAny(): FirConstructor? =
|
||||
constructors.firstOrNull()?.takeIf { it.isPrimary }
|
||||
val FirClass<*>.primaryConstructor: FirConstructor?
|
||||
get() = constructors.firstOrNull()?.takeIf { it.isPrimary }
|
||||
|
||||
fun FirRegularClass.collectEnumEntries(): Collection<FirEnumEntry> {
|
||||
assert(classKind == ClassKind.ENUM_CLASS)
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.utils
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.getPrimaryConstructorIfAny
|
||||
import org.jetbrains.kotlin.fir.declarations.primaryConstructor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
@@ -22,7 +22,7 @@ internal fun mapAnnotationParameters(annotationCall: FirAnnotationCall, session:
|
||||
|
||||
val annotationCone = annotationCall.annotationTypeRef.coneType as? ConeClassLikeType ?: return emptyMap()
|
||||
|
||||
val annotationPrimaryCtor = (annotationCone.lookupTag.toSymbol(session)?.fir as? FirRegularClass)?.getPrimaryConstructorIfAny()
|
||||
val annotationPrimaryCtor = (annotationCone.lookupTag.toSymbol(session)?.fir as? FirRegularClass)?.primaryConstructor
|
||||
val annotationCtorParameterNames = annotationPrimaryCtor?.valueParameters?.map { it.name }
|
||||
|
||||
val resultSet = mutableMapOf<String, FirExpression>()
|
||||
@@ -54,4 +54,4 @@ internal fun FirExpression.convertConstantExpression(): KtConstantValue =
|
||||
when (this) {
|
||||
is FirConstExpression<*> -> convertConstantExpression()
|
||||
else -> KtUnsupportedConstantValue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user