[FIR generator] Factor out TypeArgument 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-07 15:15:02 +02:00
committed by Space Team
parent 46cbec7260
commit 977e316489
17 changed files with 72 additions and 46 deletions
@@ -5,4 +5,6 @@
package org.jetbrains.kotlin.generators.tree
data class ArbitraryImportable(override val packageName: String, override val type: String) : Importable
data class ArbitraryImportable(override val packageName: String, override val type: String) : Importable {
override fun getTypeWithArguments(notNull: Boolean): String = type
}
@@ -9,4 +9,8 @@ interface Importable {
val type: String
val packageName: String?
val fullQualifiedName: String? get() = packageName?.let { "$it.${type.replace(Regex("<.+>"), "")}" }
}
fun getTypeWithArguments(notNull: Boolean = false): String
}
val Importable.typeWithArguments: String get() = getTypeWithArguments()
@@ -0,0 +1,28 @@
/*
* 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
sealed class TypeArgument(val name: String) {
abstract val upperBounds: List<Importable>
}
class SimpleTypeArgument(name: String, val upperBound: Importable?) : TypeArgument(name) {
override val upperBounds: List<Importable> = listOfNotNull(upperBound)
override fun toString(): String {
var result = name
if (upperBound != null) {
result += " : ${upperBound.typeWithArguments}"
}
return result
}
}
class TypeArgumentWithMultipleUpperBounds(name: String, override val upperBounds: List<Importable>) : TypeArgument(name) {
override fun toString(): String {
return name
}
}