[FIR generator] Replace AbstractElement with ElemenOrRef
In the FIR generator, the `AbstractElement` class was used to represent either an element type without type arguments applied (using the `Element` subclass), or an element type with applied type arguments (using the `ElementWithArguments` subclass). Instead, it is more logical to use the `Element` class to always represent a non-parameterized element type, and for a parameterized element type use the `ElementRef` class, just like we do in the IR generator.
This commit is contained in:
committed by
Space Team
parent
86c8f3cc35
commit
04ac4b71a3
+4
-7
@@ -10,20 +10,17 @@ import org.jetbrains.kotlin.generators.tree.printer.generics
|
||||
/**
|
||||
* A common interface representing a FIR or IR tree element.
|
||||
*/
|
||||
interface AbstractElement<Element : AbstractElement<Element, Field>, Field : AbstractField> : FieldContainer, ImplementationKindOwner,
|
||||
TypeRef /* TODO: Replace with ElementOrRef */ {
|
||||
interface AbstractElement<Element, Field> : ElementOrRef<Element, Field>, FieldContainer, ImplementationKindOwner
|
||||
where Element : AbstractElement<Element, Field>,
|
||||
Field : AbstractField {
|
||||
|
||||
val name: String
|
||||
|
||||
val fields: Set<Field>
|
||||
|
||||
val parents: List<Element>
|
||||
|
||||
val params: List<TypeVariable>
|
||||
|
||||
// TODO: Remove this property as soon as we replace org.jetbrains.kotlin.fir.tree.generator.model.ElementWithArguments with
|
||||
// a generic ElementRef class
|
||||
val typeArguments: List<TypeArgument>
|
||||
val parents: List<Element>
|
||||
|
||||
val parentsArguments: Map<Element, Map<TypeRef, TypeRef>>
|
||||
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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<TypeRef>
|
||||
}
|
||||
|
||||
class SimpleTypeArgument(name: String, val upperBound: TypeRef?) : TypeArgument(name) {
|
||||
override val upperBounds: List<TypeRef> = 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<TypeRef>) : TypeArgument(name) {
|
||||
override fun toString(): String {
|
||||
return name
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,41 @@ class ClassRef<P : TypeParameterRef> private constructor(
|
||||
override fun toString() = canonicalName
|
||||
}
|
||||
|
||||
interface ElementOrRef<Element, Field> : ParametrizedTypeRef<ElementOrRef<Element, Field>, NamedTypeParameterRef>, ClassOrElementRef
|
||||
where Element : AbstractElement<Element, Field>,
|
||||
Field : AbstractField {
|
||||
val element: Element
|
||||
}
|
||||
|
||||
data class ElementRef<Element : AbstractElement<Element, Field>, Field : AbstractField>(
|
||||
override val element: Element,
|
||||
override val args: Map<NamedTypeParameterRef, TypeRef> = emptyMap(),
|
||||
override val nullable: Boolean = false,
|
||||
) : ElementOrRef<Element, Field> {
|
||||
override fun copy(args: Map<NamedTypeParameterRef, TypeRef>) = ElementRef(element, args, nullable)
|
||||
override fun copy(nullable: Boolean) = ElementRef(element, args, nullable)
|
||||
|
||||
override val type: String
|
||||
get() = element.type
|
||||
override val packageName: String?
|
||||
get() = element.packageName
|
||||
|
||||
override fun getTypeWithArguments(notNull: Boolean): String {
|
||||
return element.type + generics
|
||||
}
|
||||
|
||||
override fun toString() = buildString {
|
||||
append(element.name)
|
||||
append("<")
|
||||
append(args)
|
||||
append(">")
|
||||
if (nullable) {
|
||||
append("?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sealed interface TypeParameterRef : TypeRef
|
||||
|
||||
data class PositionTypeParameterRef(
|
||||
|
||||
Reference in New Issue
Block a user