aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin/CrossReferences.kt
blob: c06b81d46d8e7ce578fea5d8e0b343a088e3d08d (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
package org.jetbrains.dokka

/**
 * Generates cross-references for documentation such as extensions for a type
 *
 * $receiver: [DocumentationContext] for node/descriptor resolutions
 * $node: [DocumentationNode] to visit
 */
public fun DocumentationContext.buildCrossReferences(node: DocumentationNode) {
    node.details(DocumentationNode.Kind.Receiver).forEach { detail ->
        val receiverType = detail.detail(DocumentationNode.Kind.Type)
        val descriptor = relations[receiverType]
        if (descriptor != null) {
            val typeNode = descriptorToNode[descriptor]
            // if typeNode is null, extension is to external type like in a library
            // should we create dummy node here?
            typeNode?.addReferenceTo(node, DocumentationReference.Kind.Extension)
        }
    }
    node.details(DocumentationNode.Kind.Supertype).forEach { detail ->
        val descriptor = relations[detail]
        if (descriptor != null) {
            val typeNode = descriptorToNode[descriptor]
            typeNode?.addReferenceTo(node, DocumentationReference.Kind.Inheritor)
        }
    }
    node.details.forEach { detail ->
        val descriptor = relations[detail]
        if (descriptor != null) {
            val typeNode = descriptorToNode[descriptor]
            if (typeNode != null) {
                detail.addReferenceTo(typeNode, DocumentationReference.Kind.Link)
            }
        }
    }

    for (child in node.members) {
        buildCrossReferences(child)
    }
    for (child in node.details) {
        buildCrossReferences(child)
    }
}