[Commonizer] assembelCirTree: Supoprt TypeAlias -> Class commonization
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.commonizer.tree
|
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.cir.CirTypeAlias
|
||||||
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
||||||
|
|
||||||
@@ -22,12 +23,15 @@ internal fun CirModuleNode.assembleCirTree(): CirTreeModule? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirPackageNode.assembleCirTree(): CirTreePackage? {
|
internal fun CirPackageNode.assembleCirTree(): CirTreePackage? {
|
||||||
|
val commonizedPackage = commonDeclaration() ?: return null
|
||||||
|
val commonizedTypeAliases = typeAliases.mapNotNull { (_, typeAlias) -> typeAlias.assembleCirTree() }
|
||||||
|
|
||||||
return CirTreePackage(
|
return CirTreePackage(
|
||||||
pkg = commonDeclaration() ?: return null,
|
pkg = commonizedPackage,
|
||||||
properties = properties.mapNotNull { (key, property) -> property.assembleCirTree(key) },
|
properties = properties.mapNotNull { (key, property) -> property.assembleCirTree(key) },
|
||||||
functions = functions.mapNotNull { (key, function) -> function.assembleCirTree(key) },
|
functions = functions.mapNotNull { (key, function) -> function.assembleCirTree(key) },
|
||||||
typeAliases = typeAliases.mapNotNull { (_, typeAlias) -> typeAlias.assembleCirTree() },
|
typeAliases = commonizedTypeAliases.filterIsInstance<CirTreeTypeAlias>(),
|
||||||
classes = classes.mapNotNull { (_, clazz) -> clazz.assembleCirTree() }
|
classes = classes.mapNotNull { (_, clazz) -> clazz.assembleCirTree() } + commonizedTypeAliases.filterIsInstance<CirTreeClass>()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,11 +46,12 @@ internal fun CirClassNode.assembleCirTree(): CirTreeClass? {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirTypeAliasNode.assembleCirTree(): CirTreeTypeAlias? {
|
internal fun CirTypeAliasNode.assembleCirTree(): CirTreeClassifier? {
|
||||||
return CirTreeTypeAlias(
|
return when (val commonDeclaration = commonDeclaration()) {
|
||||||
id = id,
|
is CirTypeAlias -> CirTreeTypeAlias(id, commonDeclaration)
|
||||||
typeAlias = commonDeclaration() as? CirTypeAlias ?: return null
|
is CirClass -> CirTreeClass(id, commonDeclaration)
|
||||||
)
|
else -> null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirPropertyNode.assembleCirTree(approximationKey: PropertyApproximationKey): CirTreeProperty? {
|
internal fun CirPropertyNode.assembleCirTree(approximationKey: PropertyApproximationKey): CirTreeProperty? {
|
||||||
|
|||||||
+85
@@ -29,4 +29,89 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
|
|||||||
result.assertCommonized("c", "")
|
result.assertCommonized("c", "")
|
||||||
result.assertCommonized("d", "")
|
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