[FIR generator] Extract the Implementation class to a common module
We want to use it to generate implementation classes for other trees, just like we already do with elements (see `AbstractElement`).
This commit is contained in:
committed by
Space Team
parent
85cff98a38
commit
91b5a71f1a
+3
-6
@@ -18,7 +18,7 @@ class Element(
|
||||
name: String,
|
||||
override val propertyName: String,
|
||||
category: Category,
|
||||
) : AbstractElement<Element, Field>(name) {
|
||||
) : AbstractElement<Element, Field, Nothing>(name) {
|
||||
|
||||
enum class Category(private val packageDir: String, val defaultVisitorParam: String) {
|
||||
Expression("expressions", "expression"),
|
||||
@@ -136,8 +136,8 @@ class Element(
|
||||
}
|
||||
}
|
||||
|
||||
typealias ElementRef = GenericElementRef<Element, Field>
|
||||
typealias ElementOrRef = GenericElementOrRef<Element, Field>
|
||||
typealias ElementRef = GenericElementRef<Element>
|
||||
typealias ElementOrRef = GenericElementOrRef<Element>
|
||||
|
||||
sealed class Field(
|
||||
override val name: String,
|
||||
@@ -179,9 +179,6 @@ sealed class Field(
|
||||
override val isFinal: Boolean
|
||||
get() = defaultValueInImplementation != null
|
||||
|
||||
override val isLateinit: Boolean
|
||||
get() = false
|
||||
|
||||
override val isParameter: Boolean
|
||||
get() = false
|
||||
|
||||
|
||||
+10
-18
@@ -75,14 +75,11 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
||||
if (!element.isRootElement) {
|
||||
printBlock {
|
||||
for (child in element.walkableChildren) {
|
||||
print(child.name)
|
||||
if (child.nullable) {
|
||||
print("?")
|
||||
}
|
||||
print(child.name, child.call())
|
||||
when (child) {
|
||||
is SingleField -> println(".accept(visitor, data)")
|
||||
is SingleField -> println("accept(visitor, data)")
|
||||
is ListField -> {
|
||||
print(".forEach { it")
|
||||
print("forEach { it")
|
||||
if (child.baseType.nullable) {
|
||||
print("?")
|
||||
}
|
||||
@@ -109,12 +106,9 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
||||
print(child.name)
|
||||
when (child) {
|
||||
is SingleField -> {
|
||||
print(" = ", child.name)
|
||||
if (child.nullable) {
|
||||
print("?")
|
||||
}
|
||||
print(".transform(transformer, data)")
|
||||
val elementRef = child.typeRef as GenericElementRef<*, *>
|
||||
print(" = ", child.name, child.call())
|
||||
print("transform(transformer, data)")
|
||||
val elementRef = child.typeRef as GenericElementRef<*>
|
||||
if (!elementRef.element.hasTransformMethod) {
|
||||
print(" as ", elementRef.render())
|
||||
}
|
||||
@@ -122,15 +116,13 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
||||
}
|
||||
is ListField -> {
|
||||
if (child.isMutable) {
|
||||
print(" = ", child.name)
|
||||
if (child.nullable) {
|
||||
print("?")
|
||||
}
|
||||
print(" = ", child.name, child.call())
|
||||
addImport(transformIfNeeded)
|
||||
println(".transformIfNeeded(transformer, data)")
|
||||
println("transformIfNeeded(transformer, data)")
|
||||
} else {
|
||||
addImport(transformInPlace)
|
||||
println(".transformInPlace(transformer, data)")
|
||||
print(child.call())
|
||||
println("transformInPlace(transformer, data)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user