Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fixup) Deduplicate InterfaceAbstractClassSolver
- Loading branch information
Showing
3 changed files
with
49 additions
and
226 deletions.
There are no files selected for viewing
197 changes: 0 additions & 197 deletions
197
...ree-generator/src/org/jetbrains/kotlin/ir/generator/model/InterfaceAbstractClassSolver.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ator/src/org/jetbrains/kotlin/ir/generator/model/configureInterfacesAndAbstractClasses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2010-2021 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.ir.generator.model | ||
|
||
import org.jetbrains.kotlin.generators.util.Node | ||
import org.jetbrains.kotlin.generators.util.solveGraphForClassVsInterface | ||
import org.jetbrains.kotlin.ir.generator.util.TypeKind | ||
|
||
private class NodeImpl(val element: Element) : Node { | ||
override val parents: List<Node> | ||
get() = element.elementParents.map { NodeImpl(it.element) } | ||
|
||
override val origin: Node | ||
get() = this | ||
|
||
override fun equals(other: Any?): Boolean = | ||
other is NodeImpl && element == other.element | ||
|
||
override fun hashCode(): Int = | ||
element.hashCode() | ||
} | ||
|
||
fun configureInterfacesAndAbstractClasses(elements: List<Element>) { | ||
val nodes = elements.map(::NodeImpl) | ||
val solution = solveGraphForClassVsInterface( | ||
nodes, | ||
nodes.filter { it.element.targetKind == TypeKind.Interface }, | ||
nodes.filter { it.element.targetKind == TypeKind.Class }, | ||
) | ||
updateKinds(nodes, solution) | ||
} | ||
|
||
private fun updateKinds(nodes: List<NodeImpl>, solution: List<Boolean>) { | ||
for (index in solution.indices) { | ||
val isClass = solution[index] | ||
val element = nodes[index].element | ||
if (isClass) { | ||
check(element.targetKind != TypeKind.Interface) { element } | ||
element.kind = Element.Kind.AbstractClass | ||
} else { | ||
element.kind = Element.Kind.Interface | ||
} | ||
} | ||
} |