[FIR/IR generator] Move usedTypes to AbstractElement, rename it
This commit is contained in:
committed by
Space Team
parent
e4078d163b
commit
19ff050eae
+9
@@ -166,6 +166,15 @@ abstract class AbstractElement<Element, Field, Implementation>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Types/functions that you want to additionally import in the file with the element class.
|
||||
*
|
||||
* This is useful if, for example, default values of fields reference classes or functions from other packages.
|
||||
*
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
val additionalImports = mutableListOf<Importable>()
|
||||
|
||||
final override fun get(fieldName: String): Field? {
|
||||
return allFields.firstOrNull { it.name == fieldName }
|
||||
}
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ abstract class AbstractElementPrinter<Element : AbstractElement<Element, Field,
|
||||
|
||||
context(ImportCollector)
|
||||
fun printElement(element: Element) {
|
||||
addAllImports(element.additionalImports)
|
||||
printer.run {
|
||||
val kind = element.kind ?: error("Expected non-null element kind")
|
||||
|
||||
|
||||
+8
-1
@@ -42,7 +42,14 @@ abstract class AbstractImplementation<Implementation, Element, Field>(
|
||||
|
||||
override val packageName = element.packageName + ".impl"
|
||||
|
||||
val usedTypes = mutableListOf<Importable>()
|
||||
/**
|
||||
* Types/functions that you want to additionally import in the file with the implementation class.
|
||||
*
|
||||
* This is useful if, for example, default values of fields reference classes or functions from other packages.
|
||||
*
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
val additionalImports = mutableListOf<Importable>()
|
||||
|
||||
init {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ abstract class AbstractImplementationPrinter<Implementation, Element, Implementa
|
||||
|
||||
context(ImportCollector)
|
||||
fun printImplementation(implementation: Implementation) {
|
||||
addAllImports(implementation.additionalImports)
|
||||
printer.run {
|
||||
buildSet {
|
||||
if (implementation.requiresOptIn) {
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ abstract class AbstractImplementationConfigurator<Implementation, Element, Imple
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
fun additionalImports(vararg importables: Importable) {
|
||||
importables.forEach { implementation.usedTypes += it }
|
||||
implementation.additionalImports.addAll(importables)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user