[tree generator] Remove AbstractField.defaultValueInBase

It is now unneeded, and future needs should be possible to
be resolved otherwise.
Removing it will simplify further changes to tree generator,
especially for IR.
This commit is contained in:
Wojciech Litewka
2024-03-12 13:43:42 +01:00
committed by Space Team
parent 6b9a671476
commit c1266daf73
5 changed files with 9 additions and 12 deletions
@@ -32,7 +32,6 @@ sealed class Field(
override var withGetter: Boolean = false override var withGetter: Boolean = false
override var defaultValueInBase: String? = null
override var defaultValueInImplementation: String? = null override var defaultValueInImplementation: String? = null
override var defaultValueInBuilder: String? override var defaultValueInBuilder: String?
get() = null get() = null
@@ -58,7 +57,6 @@ sealed class Field(
override fun updateFieldsInCopy(copy: Field) { override fun updateFieldsInCopy(copy: Field) {
super.updateFieldsInCopy(copy) super.updateFieldsInCopy(copy)
copy.withGetter = withGetter copy.withGetter = withGetter
copy.defaultValueInBase = defaultValueInBase
copy.defaultValueInImplementation = defaultValueInImplementation copy.defaultValueInImplementation = defaultValueInImplementation
copy.customUseInIrFactoryStrategy = customUseInIrFactoryStrategy copy.customUseInIrFactoryStrategy = customUseInIrFactoryStrategy
copy.customSetter = customSetter copy.customSetter = customSetter
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -52,7 +52,7 @@ abstract class AbstractElementPrinter<Element : AbstractElement<Element, Field,
withIndent { withIndent {
for (field in filterFields(element)) { for (field in filterFields(element)) {
if (field.isParameter) continue if (field.isParameter) continue
if (!field.withGetter && field.defaultValueInImplementation == null && field.defaultValueInBase == null && field.isFinal && field.fromParent) { if (!field.withGetter && field.defaultValueInImplementation == null && field.isFinal && field.fromParent) {
continue continue
} }
if (separateFieldsWithBlankLine) println() if (separateFieldsWithBlankLine) println()
@@ -60,7 +60,7 @@ abstract class AbstractElementPrinter<Element : AbstractElement<Element, Field,
field, field,
inImplementation = false, inImplementation = false,
override = field.fromParent, override = field.fromParent,
modality = Modality.ABSTRACT.takeIf { !field.isFinal && !kind.isInterface && field.defaultValueInBase == null }, modality = Modality.ABSTRACT.takeIf { !field.isFinal && !kind.isInterface },
) )
} }
printAdditionalMethods(element) printAdditionalMethods(element)
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -50,7 +50,6 @@ abstract class AbstractField<Field : AbstractField<Field>> {
open val containsElement: Boolean open val containsElement: Boolean
get() = typeRef is ElementOrRef<*> || this is ListField && baseType is ElementOrRef<*> get() = typeRef is ElementOrRef<*> || this is ListField && baseType is ElementOrRef<*>
open val defaultValueInBase: String? get() = null
open val defaultValueInImplementation: String? get() = null open val defaultValueInImplementation: String? get() = null
/** /**
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -42,7 +42,7 @@ abstract class AbstractFieldPrinter<Field : AbstractField<*>>(
modality: Modality? = null, modality: Modality? = null,
) { ) {
printer.run { printer.run {
val defaultValue = if (inImplementation) field.defaultValueInImplementation else field.defaultValueInBase val defaultValue = if (inImplementation) field.defaultValueInImplementation else null
printPropertyDeclaration( printPropertyDeclaration(
name = field.name, name = field.name,
type = actualTypeOfField(field), type = actualTypeOfField(field),
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -73,11 +73,11 @@ abstract class AbstractImplementation<Implementation, Element, Field>(
} }
private fun withDefault(field: Field) = private fun withDefault(field: Field) =
!field.isFinal && (field.defaultValueInImplementation != null || field.defaultValueInBase != null || field.isLateinit) !field.isFinal && (field.defaultValueInImplementation != null || field.isLateinit)
val fieldsInConstructor by lazy { allFields.filterNot(::withDefault) } val fieldsInConstructor by lazy { allFields.filterNot(::withDefault) }
val fieldsInBody by lazy { allFields.filter(::withDefault).filter { it.defaultValueInBase == null } } val fieldsInBody by lazy { allFields.filter(::withDefault) }
var requiresOptIn = false var requiresOptIn = false