This commit is contained in:
Leonid Pereverzin 2023-05-07 16:06:26 +03:00
parent 4f9fba5237
commit ffaa932127
2 changed files with 21 additions and 4 deletions

View File

@ -1,6 +1,6 @@
package documentBuilder package documentBuilder
public class GraphManager(private val graph: DependencyGraph) { public class GraphManager(public val graph: DependencyGraph) {
fun buildDocument(file: FileName) { fun buildDocument(file: FileName) {
val list = graph.nodes[file] val list = graph.nodes[file]
if (list != null) { if (list != null) {

View File

@ -1,6 +1,8 @@
package documentBuilder package documentBuilder
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlin.collections.MutableList
public typealias FileName = String public typealias FileName = String
@ -38,14 +40,29 @@ public data class IncludeDependency(
) : DependencyGraphEdge { ) : DependencyGraphEdge {
override fun visit(graphManager: GraphManager) { override fun visit(graphManager: GraphManager) {
val parent = parentNode val parent = parentNode
val childs: MutableList<MdAstElement> = mutableListOf()
for (file in includeList) { for (file in includeList) {
graphManager.buildDocument(file) graphManager.buildDocument(file)
parent.children.add(graphManager.graph.nodes[file].mdAst) childs.addAll(graphManager.graph.nodes[file]!!.mdAst.children)
} }
dependentNode = parent val elements: MutableList<MdAstElement> = parent.children.toMutableList()
val index = parent.children.indexOf(dependentNode)
elements.removeAt(index)
elements.addAll(index, childs)
parent.children = elements
} }
} }
// parent - List<MdAstElement> --------------------------------------
// | \
// | \
// \ \
// | \
// | \
// dependentNode - MdAstElement \
// |
// List<FileName> -> List<MdAstRoot> --> List<List<MdAstElement>> ===> List<MdAstElement>
/** /**
* Whole dependency graph. * Whole dependency graph.
* *