FIR: constructor refactoring, now there are callable members
This commit is contained in:
@@ -193,11 +193,11 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KtDeclarationWithBody.extractValueParametersTo(
|
private fun KtDeclarationWithBody.extractValueParametersTo(
|
||||||
container: FirAbstractFunction,
|
container: FirFunction,
|
||||||
defaultType: FirType? = null
|
defaultType: FirType? = null
|
||||||
) {
|
) {
|
||||||
for (valueParameter in valueParameters) {
|
for (valueParameter in valueParameters) {
|
||||||
container.valueParameters += valueParameter.toFirValueParameter(defaultType)
|
(container.valueParameters as MutableList<FirValueParameter>) += valueParameter.toFirValueParameter(defaultType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,9 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtClassOrObject.extractSuperTypeListEntriesTo(container: FirClassImpl): FirType? {
|
private fun KtClassOrObject.extractSuperTypeListEntriesTo(
|
||||||
|
container: FirClassImpl, delegatedSelfType: FirType
|
||||||
|
): FirType? {
|
||||||
var superTypeCallEntry: KtSuperTypeCallEntry? = null
|
var superTypeCallEntry: KtSuperTypeCallEntry? = null
|
||||||
var delegatedSuperType: FirType? = null
|
var delegatedSuperType: FirType? = null
|
||||||
for (superTypeListEntry in superTypeListEntries) {
|
for (superTypeListEntry in superTypeListEntries) {
|
||||||
@@ -240,6 +242,7 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
|
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
|
||||||
superTypeCallEntry,
|
superTypeCallEntry,
|
||||||
delegatedSuperType,
|
delegatedSuperType,
|
||||||
|
delegatedSelfType,
|
||||||
owner = this
|
owner = this
|
||||||
)
|
)
|
||||||
container.declarations += firPrimaryConstructor
|
container.declarations += firPrimaryConstructor
|
||||||
@@ -249,6 +252,7 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
private fun KtPrimaryConstructor?.toFirConstructor(
|
private fun KtPrimaryConstructor?.toFirConstructor(
|
||||||
superTypeCallEntry: KtSuperTypeCallEntry?,
|
superTypeCallEntry: KtSuperTypeCallEntry?,
|
||||||
delegatedSuperType: FirType,
|
delegatedSuperType: FirType,
|
||||||
|
delegatedSelfType: FirType,
|
||||||
owner: KtClassOrObject
|
owner: KtClassOrObject
|
||||||
): FirConstructor {
|
): FirConstructor {
|
||||||
val constructorCallee = superTypeCallEntry?.calleeExpression
|
val constructorCallee = superTypeCallEntry?.calleeExpression
|
||||||
@@ -265,6 +269,8 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
session,
|
session,
|
||||||
this ?: owner,
|
this ?: owner,
|
||||||
this?.visibility ?: Visibilities.UNKNOWN,
|
this?.visibility ?: Visibilities.UNKNOWN,
|
||||||
|
this?.platformStatus ?: FirMemberPlatformStatus.DEFAULT,
|
||||||
|
delegatedSelfType,
|
||||||
firDelegatedCall
|
firDelegatedCall
|
||||||
)
|
)
|
||||||
this?.extractAnnotationsTo(firConstructor)
|
this?.extractAnnotationsTo(firConstructor)
|
||||||
@@ -309,8 +315,8 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
enumEntry.nameAsSafeName
|
enumEntry.nameAsSafeName
|
||||||
)
|
)
|
||||||
enumEntry.extractAnnotationsTo(firEnumEntry)
|
enumEntry.extractAnnotationsTo(firEnumEntry)
|
||||||
val delegatedSuperType = enumEntry.extractSuperTypeListEntriesTo(firEnumEntry)
|
|
||||||
val delegatedSelfType = enumEntry.toDelegatedSelfType()
|
val delegatedSelfType = enumEntry.toDelegatedSelfType()
|
||||||
|
val delegatedSuperType = enumEntry.extractSuperTypeListEntriesTo(firEnumEntry, delegatedSelfType)
|
||||||
for (declaration in enumEntry.declarations) {
|
for (declaration in enumEntry.declarations) {
|
||||||
firEnumEntry.declarations += when (declaration) {
|
firEnumEntry.declarations += when (declaration) {
|
||||||
is KtSecondaryConstructor -> declaration.toFirConstructor(
|
is KtSecondaryConstructor -> declaration.toFirConstructor(
|
||||||
@@ -365,14 +371,14 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
)
|
)
|
||||||
classOrObject.extractAnnotationsTo(firClass)
|
classOrObject.extractAnnotationsTo(firClass)
|
||||||
classOrObject.extractTypeParametersTo(firClass)
|
classOrObject.extractTypeParametersTo(firClass)
|
||||||
val delegatedSuperType = classOrObject.extractSuperTypeListEntriesTo(firClass)
|
val delegatedSelfType = classOrObject.toDelegatedSelfType()
|
||||||
|
val delegatedSuperType = classOrObject.extractSuperTypeListEntriesTo(firClass, delegatedSelfType)
|
||||||
classOrObject.primaryConstructor?.valueParameters?.forEach {
|
classOrObject.primaryConstructor?.valueParameters?.forEach {
|
||||||
if (it.hasValOrVar()) {
|
if (it.hasValOrVar()) {
|
||||||
firClass.declarations += it.toFirProperty()
|
firClass.declarations += it.toFirProperty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val delegatedSelfType = classOrObject.toDelegatedSelfType()
|
|
||||||
for (declaration in classOrObject.declarations) {
|
for (declaration in classOrObject.declarations) {
|
||||||
firClass.declarations += when (declaration) {
|
firClass.declarations += when (declaration) {
|
||||||
is KtSecondaryConstructor -> declaration.toFirConstructor(
|
is KtSecondaryConstructor -> declaration.toFirConstructor(
|
||||||
@@ -450,6 +456,8 @@ class RawFirBuilder(val session: FirSession) {
|
|||||||
session,
|
session,
|
||||||
this,
|
this,
|
||||||
visibility,
|
visibility,
|
||||||
|
platformStatus,
|
||||||
|
delegatedSelfType,
|
||||||
getDelegationCall().convert(delegatedSuperType, delegatedSelfType, hasPrimaryConstructor),
|
getDelegationCall().convert(delegatedSuperType, delegatedSelfType, hasPrimaryConstructor),
|
||||||
buildFirBody()
|
buildFirBody()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,23 +5,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.declarations
|
package org.jetbrains.kotlin.fir.declarations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
|
||||||
import org.jetbrains.kotlin.fir.BaseTransformedType
|
import org.jetbrains.kotlin.fir.BaseTransformedType
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
|
import org.jetbrains.kotlin.fir.VisitedSupertype
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||||
|
|
||||||
@BaseTransformedType
|
@BaseTransformedType
|
||||||
interface FirConstructor : FirFunction, FirAnnotationContainer {
|
interface FirConstructor : @VisitedSupertype FirFunction, FirCallableMember {
|
||||||
val delegatedConstructor: FirDelegatedConstructorCall?
|
val delegatedConstructor: FirDelegatedConstructorCall?
|
||||||
|
|
||||||
val visibility: Visibility
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||||
visitor.visitConstructor(this, data)
|
visitor.visitConstructor(this, data)
|
||||||
|
|
||||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||||
acceptAnnotations(visitor, data)
|
super<FirCallableMember>.acceptChildren(visitor, data)
|
||||||
delegatedConstructor?.accept(visitor, data)
|
delegatedConstructor?.accept(visitor, data)
|
||||||
for (parameter in valueParameters) {
|
for (parameter in valueParameters) {
|
||||||
parameter.accept(visitor, data)
|
parameter.accept(visitor, data)
|
||||||
|
|||||||
+22
-5
@@ -6,26 +6,43 @@
|
|||||||
package org.jetbrains.kotlin.fir.declarations.impl
|
package org.jetbrains.kotlin.fir.declarations.impl
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirMemberPlatformStatus
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBody
|
import org.jetbrains.kotlin.fir.expressions.FirBody
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||||
|
import org.jetbrains.kotlin.fir.transformInplace
|
||||||
import org.jetbrains.kotlin.fir.transformSingle
|
import org.jetbrains.kotlin.fir.transformSingle
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirType
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
open class FirConstructorImpl(
|
open class FirConstructorImpl(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
psi: PsiElement?,
|
psi: PsiElement?,
|
||||||
final override val visibility: Visibility,
|
visibility: Visibility,
|
||||||
|
platformStatus: FirMemberPlatformStatus,
|
||||||
|
delegatedSelfType: FirType,
|
||||||
final override var delegatedConstructor: FirDelegatedConstructorCall?,
|
final override var delegatedConstructor: FirDelegatedConstructorCall?,
|
||||||
body: FirBody?
|
override val body: FirBody?
|
||||||
) : FirAbstractFunction(session, psi, body), FirConstructor {
|
) : FirAbstractCallableMember(
|
||||||
|
session, psi, NAME, visibility, Modality.FINAL,
|
||||||
|
platformStatus, false, null, delegatedSelfType
|
||||||
|
), FirConstructor {
|
||||||
|
override val valueParameters = mutableListOf<FirValueParameter>()
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
||||||
delegatedConstructor = delegatedConstructor?.transformSingle(transformer, data)
|
valueParameters.transformInplace(transformer, data)
|
||||||
|
delegatedConstructor?.transformSingle(transformer, data)
|
||||||
|
|
||||||
return super<FirAbstractFunction>.transformChildren(transformer, data)
|
return super<FirAbstractCallableMember>.transformChildren(transformer, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val NAME = Name.special("<init>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-1
@@ -8,11 +8,15 @@ package org.jetbrains.kotlin.fir.declarations.impl
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirMemberPlatformStatus
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirType
|
||||||
|
|
||||||
class FirPrimaryConstructorImpl(
|
class FirPrimaryConstructorImpl(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
psi: PsiElement?,
|
psi: PsiElement?,
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
|
platformStatus: FirMemberPlatformStatus,
|
||||||
|
delegatedSelfType: FirType,
|
||||||
delegatedConstructor: FirDelegatedConstructorCall?
|
delegatedConstructor: FirDelegatedConstructorCall?
|
||||||
) : FirConstructorImpl(session, psi, visibility, delegatedConstructor, body = null)
|
) : FirConstructorImpl(session, psi, visibility, platformStatus, delegatedSelfType, delegatedConstructor, body = null)
|
||||||
Reference in New Issue
Block a user