<lambda>null1 package org.jetbrains.dokka
2
3 import com.google.inject.Singleton
4
5 enum class RefKind {
6 Owner,
7 Member,
8 InheritedMember,
9 InheritedCompanionObjectMember,
10 Detail,
11 Link,
12 HiddenLink,
13 Extension,
14 Inheritor,
15 Superclass,
16 Override,
17 Annotation,
18 HiddenAnnotation,
19 Deprecation,
20 TopLevelPage,
21 Platform,
22 ExternalType,
23 AttributeRef,
24 AttributeSource
25 }
26
27 data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: RefKind) {
28 }
29
30 class PendingDocumentationReference(val lazyNodeFrom: () -> DocumentationNode?,
31 val lazyNodeTo: () -> DocumentationNode?,
32 val kind: RefKind) {
resolvenull33 fun resolve() {
34 val fromNode = lazyNodeFrom()
35 val toNode = lazyNodeTo()
36 if (fromNode != null && toNode != null) {
37 fromNode.addReferenceTo(toNode, kind)
38 }
39 }
40 }
41
42 class NodeReferenceGraph() {
43 private val nodeMap = hashMapOf<String, DocumentationNode>()
44 val references = arrayListOf<PendingDocumentationReference>()
45
registernull46 fun register(signature: String, node: DocumentationNode) {
47 nodeMap.put(signature, node)
48 }
49
linknull50 fun link(fromNode: DocumentationNode, toSignature: String, kind: RefKind) {
51 references.add(PendingDocumentationReference({ -> fromNode}, { -> nodeMap[toSignature]}, kind))
52 }
53
linknull54 fun link(fromSignature: String, toNode: DocumentationNode, kind: RefKind) {
55 references.add(PendingDocumentationReference({ -> nodeMap[fromSignature]}, { -> toNode}, kind))
56 }
57
linknull58 fun link(fromSignature: String, toSignature: String, kind: RefKind) {
59 references.add(PendingDocumentationReference({ -> nodeMap[fromSignature]}, { -> nodeMap[toSignature]}, kind))
60 }
61
lookupnull62 fun lookup(signature: String) = nodeMap[signature]
63
64 fun lookupOrWarn(signature: String, logger: DokkaLogger): DocumentationNode? {
65 val result = nodeMap[signature]
66 if (result == null) {
67 logger.warn("Can't find node by signature `$signature`")
68 }
69 return result
70 }
71
resolveReferencesnull72 fun resolveReferences() {
73 references.forEach { it.resolve() }
74 }
75 }
76
77 @Singleton
78 class PlatformNodeRegistry {
79 private val platformNodes = hashMapOf<String, DocumentationNode>()
80
getnull81 operator fun get(platform: String): DocumentationNode {
82 return platformNodes.getOrPut(platform) {
83 DocumentationNode(platform, Content.Empty, NodeKind.Platform)
84 }
85 }
86 }
87