1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
package org.jetbrains.dokka.pages
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.links.DRI
import java.util.*
interface PageNode {
val name: String
val content: ContentNode
val dri: DRI
val documentable: Documentable?
val embeddedResources: List<String>
val children: List<PageNode>
fun modified(
name: String = this.name,
content: ContentNode = this.content,
embeddedResources: List<String> = this.embeddedResources,
children: List<PageNode> = this.children
): PageNode
}
class ModulePageNode(
override val name: String,
override val content: ContentNode,
override val documentable: Documentable?,
override val children: List<PageNode>,
override val embeddedResources: List<String> = listOf()
) : PageNode {
override val dri: DRI = DRI.topLevel
override fun modified(
name: String,
content: ContentNode,
embeddedResources: List<String>,
children: List<PageNode>
): ModulePageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else ModulePageNode(name, content, documentable, children, embeddedResources)
private fun PageNode.transformNode(operation: (PageNode) -> PageNode): PageNode =
operation(this).let { newNode ->
newNode.modified(children = newNode.children.map { it.transformNode(operation) })
}
fun transformPageNodeTree(operation: (PageNode) -> PageNode) =
this.transformNode(operation) as ModulePageNode
val parentMap: IdentityHashMap<PageNode, PageNode> by lazy {
IdentityHashMap<PageNode, PageNode>().apply {
fun addParent(parent: PageNode) {
parent.children.forEach { child ->
put(child, parent)
addParent(child)
}
}
addParent(this@ModulePageNode)
}
}
}
class PackagePageNode(
override val name: String,
override val content: ContentNode,
override val dri: DRI,
override val documentable: Documentable?,
override val children: List<PageNode>,
override val embeddedResources: List<String> = listOf()
) : PageNode {
override fun modified(
name: String,
content: ContentNode,
embeddedResources: List<String>,
children: List<PageNode>
): PackagePageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else PackagePageNode(name, content, dri, documentable, children, embeddedResources)
}
class ClassPageNode(
override val name: String,
override val content: ContentNode,
override val dri: DRI,
override val documentable: Documentable?,
override val children: List<PageNode>,
override val embeddedResources: List<String> = listOf()
) : PageNode {
override fun modified(
name: String,
content: ContentNode,
embeddedResources: List<String>,
children: List<PageNode>
): ClassPageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else ClassPageNode(name, content, dri, documentable, children, embeddedResources)
}
class MemberPageNode(
override val name: String,
override val content: ContentNode,
override val dri: DRI,
override val documentable: Documentable?,
override val children: List<PageNode> = emptyList(),
override val embeddedResources: List<String> = listOf()
) : PageNode {
override fun modified(
name: String,
content: ContentNode,
embeddedResources: List<String>,
children: List<PageNode>
): MemberPageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else MemberPageNode(name, content, dri, documentable, children, embeddedResources)
}
data class PlatformData(val name: String, val platformType: Platform, val targets: List<String>) {
override fun toString() = targets.toString()
}
fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) {
this
} else {
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
private infix fun <T> List<T>.shallowEq(other: List<T>) =
this === other || (this.size == other.size && (this zip other).all { (a, b) -> a === b })
// Navigation??
// content modifier?
//data class ContentLink(val link: String): ContentNode
|