SNRK-82: Add code from another repository

This commit is contained in:
Kirill Grachev 2023-05-06 19:46:38 +03:00
parent 14c1e650b9
commit a13c4a8e8c
2 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,17 @@
package documentBuilder
internal class GraphManager(private val graph: DependencyGraph) {
fun buildDocument(file: FileName) {
val list = graph.nodes[file]
if (list != null) {
for (element in list.dependencies) {
element.visit(this)
}
}
}
fun getAstRootDocument(file: FileName): MdAstRoot {
buildDocument(file)
return graph.nodes[file]!!.mdAst
}
}

View File

@ -1,5 +1,7 @@
package documentBuilder
import kotlinx.coroutines.coroutineScope
public typealias FileName = String
/**
@ -19,6 +21,7 @@ public data class DependencyGraphNode(
* Interface of all dependency edges.
*/
public sealed interface DependencyGraphEdge {
public fun visit(graphManager: GraphManager)
}
/**
@ -32,7 +35,16 @@ public data class IncludeDependency(
val parentNode: MdAstParent,
val dependentNode: MdAstElement,
val includeList: List<FileName>
) : DependencyGraphEdge
) : DependencyGraphEdge {
override fun visit(graphManager: GraphManager) {
val parent = parentNode
for (file in includeList) {
graphManager.buildDocument(file)
parent.children.add(graphManager.graph.nodes[file].mdAst)
}
dependentNode = parent
}
}
/**
* Whole dependency graph.