[FIR/IR generator] Make AbstractField generic over itself

This will make some code more type-safe.
This commit is contained in:
Sergej Jaskiewicz
2023-11-14 19:04:31 +01:00
committed by Space Team
parent c6eb7d6c21
commit 38ee477ab4
14 changed files with 21 additions and 23 deletions
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.generators.tree.*
private const val DEFAULT_BUILDER_PACKAGE = "org.jetbrains.kotlin.fir.tree.builder"
sealed class Builder : FieldContainer, TypeRef, Importable {
sealed class Builder : FieldContainer<FieldWithDefault>, TypeRef, Importable {
val parents: MutableList<IntermediateBuilder> = mutableListOf()
val usedTypes: MutableList<Importable> = mutableListOf()
abstract override val allFields: List<FieldWithDefault>
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.generators.tree.*
sealed class Field : AbstractField() {
sealed class Field : AbstractField<Field>() {
open var withReplace: Boolean = false
open var needsSeparateTransform: Boolean = false
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.generators.tree.*
class Implementation(val element: Element, val name: String?) : FieldContainer, ImplementationKindOwner {
class Implementation(val element: Element, val name: String?) : FieldContainer<FieldWithDefault>, ImplementationKindOwner {
override val allParents: List<ImplementationKindOwner> get() = listOf(element)
val isDefault = name == null
override val typeName = name ?: (element.typeName + "Impl")
@@ -159,7 +159,6 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
println()
withIndent {
for (field in walkableFields) {
check(field is FieldWithDefault)
when (field.name) {
"explicitReceiver" -> {
val explicitReceiver = implementation["explicitReceiver"]!!
@@ -226,7 +225,6 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
if (!isInterface && !isAbstract) {
printBlock {
for (field in transformableChildren) {
check(field is FieldWithDefault)
when {
field.name == "explicitReceiver" -> {
val explicitReceiver = implementation["explicitReceiver"]!!