FirClassSubstitutionScope: extract SubstitutedData & reorder functions
This commit is contained in:
+46
-48
@@ -119,14 +119,7 @@ class FirClassSubstitutionScope(
|
|||||||
}
|
}
|
||||||
if (skipPrivateMembers && member.visibility == Visibilities.PRIVATE) return original
|
if (skipPrivateMembers && member.visibility == Visibilities.PRIVATE) return original
|
||||||
|
|
||||||
val (newTypeParameters, newSubstitutor) = createNewTypeParametersAndSubstitutor(member)
|
val (newTypeParameters, newReceiverType, newReturnType, newSubstitutor) = createSubstitutedData(member)
|
||||||
|
|
||||||
val receiverType = member.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>()
|
|
||||||
val newReceiverType = receiverType?.substitute(newSubstitutor)
|
|
||||||
|
|
||||||
val returnType = typeCalculator.tryCalculateReturnType(member).type
|
|
||||||
val newReturnType = returnType.substitute(newSubstitutor)
|
|
||||||
|
|
||||||
val newParameterTypes = member.valueParameters.map {
|
val newParameterTypes = member.valueParameters.map {
|
||||||
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
||||||
}
|
}
|
||||||
@@ -156,12 +149,8 @@ class FirClassSubstitutionScope(
|
|||||||
private fun createFakeOverrideConstructor(original: FirConstructorSymbol): FirConstructorSymbol {
|
private fun createFakeOverrideConstructor(original: FirConstructorSymbol): FirConstructorSymbol {
|
||||||
if (substitutor == ConeSubstitutor.Empty) return original
|
if (substitutor == ConeSubstitutor.Empty) return original
|
||||||
val constructor = original.fir
|
val constructor = original.fir
|
||||||
val (newTypeParameters, newSubstitutor) = createNewTypeParametersAndSubstitutor(constructor)
|
|
||||||
|
|
||||||
|
|
||||||
val returnType = constructor.returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
|
||||||
val newReturnType = returnType.substitute(newSubstitutor)
|
|
||||||
|
|
||||||
|
val (newTypeParameters, _, newReturnType, newSubstitutor) = createSubstitutedData(constructor)
|
||||||
val newParameterTypes = constructor.valueParameters.map {
|
val newParameterTypes = constructor.valueParameters.map {
|
||||||
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
||||||
}
|
}
|
||||||
@@ -175,6 +164,50 @@ class FirClassSubstitutionScope(
|
|||||||
).symbol
|
).symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createFakeOverrideProperty(original: FirPropertySymbol): FirPropertySymbol {
|
||||||
|
if (substitutor == ConeSubstitutor.Empty) return original
|
||||||
|
val member = original.fir
|
||||||
|
if (skipPrivateMembers && member.visibility == Visibilities.PRIVATE) return original
|
||||||
|
|
||||||
|
val (newTypeParameters, newReceiverType, newReturnType) = createSubstitutedData(member)
|
||||||
|
if (newReceiverType == null &&
|
||||||
|
newReturnType == null && newTypeParameters === member.typeParameters
|
||||||
|
) {
|
||||||
|
return original
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return createFakeOverrideProperty(
|
||||||
|
session,
|
||||||
|
member,
|
||||||
|
original,
|
||||||
|
newReceiverType,
|
||||||
|
newReturnType,
|
||||||
|
newTypeParameters as List<FirTypeParameter>,
|
||||||
|
derivedClassId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class SubstitutedData(
|
||||||
|
val typeParameters: List<FirTypeParameterRef>,
|
||||||
|
val receiverType: ConeKotlinType?,
|
||||||
|
val returnType: ConeKotlinType?,
|
||||||
|
val substitutor: ConeSubstitutor
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun createSubstitutedData(member: FirCallableMemberDeclaration<*>): SubstitutedData {
|
||||||
|
val (newTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor(
|
||||||
|
member as FirTypeParameterRefsOwner
|
||||||
|
)
|
||||||
|
|
||||||
|
val receiverType = member.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>()
|
||||||
|
val newReceiverType = receiverType?.substitute(substitutor)
|
||||||
|
|
||||||
|
val returnType = typeCalculator.tryCalculateReturnType(member).type
|
||||||
|
val newReturnType = returnType.substitute(substitutor)
|
||||||
|
return SubstitutedData(newTypeParameters, newReceiverType, newReturnType, substitutor)
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a list of type parameters, and a substitutor that should be used for all other types
|
// Returns a list of type parameters, and a substitutor that should be used for all other types
|
||||||
private fun createNewTypeParametersAndSubstitutor(
|
private fun createNewTypeParametersAndSubstitutor(
|
||||||
member: FirTypeParameterRefsOwner
|
member: FirTypeParameterRefsOwner
|
||||||
@@ -227,41 +260,6 @@ class FirClassSubstitutionScope(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFakeOverrideProperty(original: FirPropertySymbol): FirPropertySymbol {
|
|
||||||
if (substitutor == ConeSubstitutor.Empty) return original
|
|
||||||
val member = original.fir
|
|
||||||
if (skipPrivateMembers && member.visibility == Visibilities.PRIVATE) return original
|
|
||||||
|
|
||||||
val (newTypeParameters, newSubstitutor) = createNewTypeParametersAndSubstitutor(member)
|
|
||||||
|
|
||||||
val receiverType = member.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>()
|
|
||||||
val newReceiverType = receiverType?.substitute(newSubstitutor)
|
|
||||||
|
|
||||||
val returnType = typeCalculator.tryCalculateReturnType(member).type
|
|
||||||
val newReturnType = returnType.substitute(newSubstitutor)
|
|
||||||
|
|
||||||
if (newReceiverType == null &&
|
|
||||||
newReturnType == null && newTypeParameters === member.typeParameters
|
|
||||||
) {
|
|
||||||
return original
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Member properties can't capture type parameters, so
|
|
||||||
* it's safe to cast newTypeParameters to List<FirTypeParameter>
|
|
||||||
*/
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return createFakeOverrideProperty(
|
|
||||||
session,
|
|
||||||
member,
|
|
||||||
original,
|
|
||||||
newReceiverType,
|
|
||||||
newReturnType,
|
|
||||||
newTypeParameters as List<FirTypeParameter>,
|
|
||||||
derivedClassId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createFakeOverrideField(original: FirFieldSymbol): FirFieldSymbol {
|
private fun createFakeOverrideField(original: FirFieldSymbol): FirFieldSymbol {
|
||||||
if (substitutor == ConeSubstitutor.Empty) return original
|
if (substitutor == ConeSubstitutor.Empty) return original
|
||||||
val member = original.fir
|
val member = original.fir
|
||||||
|
|||||||
Reference in New Issue
Block a user