aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/pages/PageNodes.kt
blob: 46109d8725c84cc2745cdbd80a42fc5b64900ed9 (plain)
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
package org.jetbrains.dokka.pages

import org.jetbrains.dokka.Model.DocumentationNode
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.links.DRI

abstract class PageNode(
    val name: String,
    val content: List<ContentNode>,
    val parent: PageNode?,
    val dri: DRI?,
    val documentationNode: DocumentationNode<*>?
) {
    val children: List<PageNode>
        get() = _children

    private val _children: MutableList<PageNode> = mutableListOf()

    fun appendChildren(children: List<PageNode>) = _children.addAll(children)
    fun appendChild(child: PageNode) = _children.add(child)
}

class ModulePageNode(
    name: String,
    content: List<ContentNode>,
    parent: PageNode? = null,
    documentationNode: DocumentationNode<*>?
): PageNode(name, content, parent, null, documentationNode)

class PackagePageNode(
    name: String,
    content: List<ContentNode>,
    parent: PageNode,
    dri: DRI,
    documentationNode: DocumentationNode<*>?
): PageNode(name, content, parent, dri, documentationNode)

class ClassPageNode(
    name: String,
    content: List<ContentNode>,
    parent: PageNode,
    dri: DRI,
    documentationNode: DocumentationNode<*>?
): PageNode(name, content, parent, dri, documentationNode)  // class, companion object

class MemberPageNode(
    name: String,
    content: List<ContentNode>,
    parent: PageNode,
    dri: DRI,
    documentationNode: DocumentationNode<*>?
): PageNode(name, content, parent, dri, documentationNode) // functions, extension functions, properties

data class PlatformData(val platformName: String, val platformType: Platform)

fun PageNode.platforms(): List<PlatformData> = this.content.flatMap { it.platforms }.distinct() // TODO: Override equals???
fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { this } else { this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() }



// Navigation??

// content modifier?
//data class ContentLink(val link: String): ContentNode