Implement CommonizerTarget.withAllAncestors
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.util.transitiveClosure
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.io.Serializable
|
||||
|
||||
@@ -101,6 +102,14 @@ public val CommonizerTarget.level: Int
|
||||
}
|
||||
}
|
||||
|
||||
public fun CommonizerTarget.withAllAncestors(): Set<CommonizerTarget> {
|
||||
return setOf(this) + transitiveClosure(this) {
|
||||
when (this) {
|
||||
is SharedCommonizerTarget -> targets
|
||||
is LeafCommonizerTarget -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public infix fun CommonizerTarget.isAncestorOf(other: CommonizerTarget): Boolean {
|
||||
if (this is SharedCommonizerTarget) {
|
||||
|
||||
+26
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.commonizer
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@@ -28,4 +29,29 @@ class CommonizerTargetUtilsTest {
|
||||
assertTrue(parseCommonizerTarget("(c, d)") isDescendentOf hierarchicalParent)
|
||||
assertTrue(LeafCommonizerTarget("e") isDescendentOf hierarchicalParent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun withAllAncestors() {
|
||||
val target = parseCommonizerTarget("((a, b), (c, d), (e, (f, g)))")
|
||||
|
||||
assertEquals(
|
||||
setOf(
|
||||
target,
|
||||
parseCommonizerTarget("(a, b)"),
|
||||
parseCommonizerTarget("(c, d)"),
|
||||
parseCommonizerTarget("(e, (f, g))"),
|
||||
parseCommonizerTarget("(f, g)"),
|
||||
LeafCommonizerTarget("a"),
|
||||
LeafCommonizerTarget("b"),
|
||||
LeafCommonizerTarget("c"),
|
||||
LeafCommonizerTarget("d"),
|
||||
LeafCommonizerTarget("e"),
|
||||
LeafCommonizerTarget("f"),
|
||||
LeafCommonizerTarget("g")
|
||||
),
|
||||
target.withAllAncestors(),
|
||||
"Expected all targets present"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user