[FIR generator] Deduplicate the logic of needPureAbstractElement

This commit is contained in:
Sergej Jaskiewicz
2023-09-18 19:29:03 +02:00
committed by Space Team
parent 45792c2e60
commit 9a4c28498c
4 changed files with 7 additions and 7 deletions
@@ -98,7 +98,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
}
print(" : ")
if (!isInterface && !allParents.any { it.kind == ImplementationKind.AbstractClass || it.kind == ImplementationKind.SealedClass }) {
if (needPureAbstractElement) {
print("${pureAbstractElementType.type}(), ")
}
print(allParents.joinToString { "${it.typeWithArguments}${it.kind.braces()}" })
@@ -113,10 +113,6 @@ private fun List<String>.filterRedundantImports(
}
val ImplementationKindOwner.needPureAbstractElement: Boolean
get() = (kind != ImplementationKind.Interface && kind != ImplementationKind.SealedInterface) && !allParents.any { it.kind == ImplementationKind.AbstractClass || it.kind == ImplementationKind.SealedClass }
val Field.isVal: Boolean
get() = (this is FieldList && !isMutableOrEmpty) || (this is FieldWithDefault && origin is FieldList && !origin.isMutableOrEmpty) || !isMutable
@@ -160,7 +160,7 @@ private fun markLeaves(elements: List<Element>) {
private fun addAbstractElement(elements: List<Element>) {
for (el in elements) {
if (el.kind!!.typeKind == TypeKind.Class && el.elementParents.none { it.element.kind!!.typeKind == TypeKind.Class }) {
if (el.needPureAbstractElement) {
el.otherParents += elementBaseType
}
}
@@ -8,4 +8,8 @@ package org.jetbrains.kotlin.generators.tree
interface ImplementationKindOwner : Importable {
var kind: ImplementationKind?
val allParents: List<ImplementationKindOwner>
}
}
val ImplementationKindOwner.needPureAbstractElement: Boolean
get() = !(kind?.isInterface ?: false) &&
allParents.none { it.kind == ImplementationKind.AbstractClass || it.kind == ImplementationKind.SealedClass }