[FIR generator] Move Field and FieldContainer to common module

This is a step towards commonizing the code generator between
FIR and IR: KT-61970
This commit is contained in:
Sergej Jaskiewicz
2023-09-04 20:10:00 +02:00
committed by Space Team
parent 982b9221b4
commit e62343427d
6 changed files with 65 additions and 34 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.generators.tree.FieldContainer
import org.jetbrains.kotlin.generators.tree.Importable
private const val DEFAULT_BUILDER_PACKAGE = "org.jetbrains.kotlin.fir.tree.builder"
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.fir.tree.generator.printer.BASE_PACKAGE
import org.jetbrains.kotlin.fir.tree.generator.printer.typeWithArguments
import org.jetbrains.kotlin.fir.tree.generator.util.set
import org.jetbrains.kotlin.generators.tree.FieldContainer
import org.jetbrains.kotlin.generators.tree.Importable
interface KindOwner : Importable {
@@ -15,11 +16,6 @@ interface KindOwner : Importable {
val allParents: List<KindOwner>
}
interface FieldContainer {
val allFields: List<Field>
operator fun get(fieldName: String): Field?
}
interface AbstractElement : FieldContainer, KindOwner {
val name: String
val fields: Set<Field>
@@ -8,32 +8,20 @@ package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.fir.tree.generator.printer.typeWithArguments
import org.jetbrains.kotlin.generators.tree.ArbitraryImportable
import org.jetbrains.kotlin.generators.tree.Importable
import org.jetbrains.kotlin.generators.tree.AbstractField
sealed class Field : Importable {
abstract val name: String
open val arguments = mutableListOf<Importable>()
abstract val nullable: Boolean
abstract var isVolatile: Boolean
abstract var isFinal: Boolean
abstract var isLateinit: Boolean
abstract var isParameter: Boolean
sealed class Field : AbstractField() {
open var withReplace: Boolean = false
abstract val isFirType: Boolean
var fromParent: Boolean = false
open var needsSeparateTransform: Boolean = false
var parentHasSeparateTransform: Boolean = true
open var needTransformInOtherChildren: Boolean = false
open var customInitializationCall: String? = null
open val arbitraryImportables: MutableList<Importable> = mutableListOf()
open var optInAnnotation: ArbitraryImportable? = null
open val defaultValueInImplementation: String? get() = null
abstract var isMutable: Boolean
abstract var isMutableOrEmpty: Boolean
open var isMutableInInterface: Boolean = false
open val withGetter: Boolean get() = false
open val customSetter: String? get() = null
open val fromDelegate: Boolean get() = false
open val overridenTypes: MutableSet<Importable> = mutableSetOf()
@@ -65,21 +53,6 @@ sealed class Field : Importable {
protected abstract fun internalCopy(): Field
override fun toString(): String {
return name
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
if (javaClass != other.javaClass) return false
other as Field
return name == other.name
}
override fun hashCode(): Int {
return name.hashCode()
}
}
// ----------- Field with default -----------
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.generators.tree.ArbitraryImportable
import org.jetbrains.kotlin.generators.tree.FieldContainer
import org.jetbrains.kotlin.generators.tree.Importable
class ImplementationWithArg(
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2023 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.
*/
package org.jetbrains.kotlin.generators.tree
abstract class AbstractField : Importable {
abstract val name: String
open val arguments = mutableListOf<Importable>()
abstract val nullable: Boolean
abstract var isVolatile: Boolean
abstract var isFinal: Boolean
abstract var isLateinit: Boolean
abstract var isParameter: Boolean
open val arbitraryImportables: MutableList<Importable> = mutableListOf()
open var optInAnnotation: ArbitraryImportable? = null
abstract var isMutable: Boolean
open val withGetter: Boolean get() = false
open val customSetter: String? get() = null
var fromParent: Boolean = false
override fun toString(): String {
return name
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
if (javaClass != other.javaClass) return false
other as AbstractField
return name == other.name
}
override fun hashCode(): Int {
return name.hashCode()
}
}
@@ -0,0 +1,11 @@
/*
* Copyright 2010-2023 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.
*/
package org.jetbrains.kotlin.generators.tree
interface FieldContainer {
val allFields: List<AbstractField>
operator fun get(fieldName: String): AbstractField?
}