mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[Commonizer] assembelCirTree: Supoprt TypeAlias -> Class commonization
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer.tree
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirTypeAlias
|
||||
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
||||
|
||||
@@ -22,12 +23,15 @@ internal fun CirModuleNode.assembleCirTree(): CirTreeModule? {
|
||||
}
|
||||
|
||||
internal fun CirPackageNode.assembleCirTree(): CirTreePackage? {
|
||||
val commonizedPackage = commonDeclaration() ?: return null
|
||||
val commonizedTypeAliases = typeAliases.mapNotNull { (_, typeAlias) -> typeAlias.assembleCirTree() }
|
||||
|
||||
return CirTreePackage(
|
||||
pkg = commonDeclaration() ?: return null,
|
||||
pkg = commonizedPackage,
|
||||
properties = properties.mapNotNull { (key, property) -> property.assembleCirTree(key) },
|
||||
functions = functions.mapNotNull { (key, function) -> function.assembleCirTree(key) },
|
||||
typeAliases = typeAliases.mapNotNull { (_, typeAlias) -> typeAlias.assembleCirTree() },
|
||||
classes = classes.mapNotNull { (_, clazz) -> clazz.assembleCirTree() }
|
||||
typeAliases = commonizedTypeAliases.filterIsInstance<CirTreeTypeAlias>(),
|
||||
classes = classes.mapNotNull { (_, clazz) -> clazz.assembleCirTree() } + commonizedTypeAliases.filterIsInstance<CirTreeClass>()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -42,11 +46,12 @@ internal fun CirClassNode.assembleCirTree(): CirTreeClass? {
|
||||
)
|
||||
}
|
||||
|
||||
internal fun CirTypeAliasNode.assembleCirTree(): CirTreeTypeAlias? {
|
||||
return CirTreeTypeAlias(
|
||||
id = id,
|
||||
typeAlias = commonDeclaration() as? CirTypeAlias ?: return null
|
||||
)
|
||||
internal fun CirTypeAliasNode.assembleCirTree(): CirTreeClassifier? {
|
||||
return when (val commonDeclaration = commonDeclaration()) {
|
||||
is CirTypeAlias -> CirTreeTypeAlias(id, commonDeclaration)
|
||||
is CirClass -> CirTreeClass(id, commonDeclaration)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun CirPropertyNode.assembleCirTree(approximationKey: PropertyApproximationKey): CirTreeProperty? {
|
||||
|
||||
@@ -29,4 +29,89 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
result.assertCommonized("c", "")
|
||||
result.assertCommonized("d", "")
|
||||
}
|
||||
|
||||
/**
|
||||
* See: https://youtrack.jetbrains.com/issue/KT-45992
|
||||
*/
|
||||
fun `todo test typealias and class`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a,b)")
|
||||
simpleSingleSourceTarget("a", """class X """)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class B
|
||||
typealias X = B
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized("(a,b)", "expect class X")
|
||||
}
|
||||
|
||||
fun `test typealias to different classes`() {
|
||||
val result = commonize {
|
||||
outputTarget("(((a,b), (c,d)), (e,f))")
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class AB
|
||||
typealias x = AB
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class AB
|
||||
typealias x = AB
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"c", """
|
||||
class CD
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
class CD
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget("e", """class x""")
|
||||
simpleSingleSourceTarget("f", """class x""")
|
||||
}
|
||||
|
||||
result.assertCommonized("a", """class AB""")
|
||||
result.assertCommonized("b", """class AB""")
|
||||
result.assertCommonized("c", """class CD""")
|
||||
result.assertCommonized("d", """class CD""")
|
||||
result.assertCommonized("e", """class x""")
|
||||
result.assertCommonized("f", """class x""")
|
||||
|
||||
result.assertCommonized(
|
||||
"(a,b)", """
|
||||
expect class AB expect constructor()
|
||||
typealias x = AB
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
expect class CD expect constructor()
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
expect class CD expect constructor()
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(e,f)", """expect class x expect constructor()"""
|
||||
)
|
||||
|
||||
result.assertCommonized("((a,b), (c,d))", """expect class x""")
|
||||
result.assertCommonized("(((a,b), (c,d)), (e,f))", """expect class x""")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user