aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin/CrossReferences.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/Kotlin/CrossReferences.kt')
-rw-r--r--src/Kotlin/CrossReferences.kt37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Kotlin/CrossReferences.kt b/src/Kotlin/CrossReferences.kt
new file mode 100644
index 00000000..7504cebc
--- /dev/null
+++ b/src/Kotlin/CrossReferences.kt
@@ -0,0 +1,37 @@
+package org.jetbrains.dokka
+
+import org.jetbrains.jet.lang.descriptors.ClassKind
+
+/**
+ * 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.Type).forEach { detail ->
+ val descriptor = relations[detail]
+ if (descriptor != null) {
+ val typeNode = descriptorToNode[descriptor]
+ if (typeNode != null) {
+ // if typeNode is null, type is external to module
+ detail.addReferenceTo(typeNode, DocumentationReference.Kind.Link)
+ }
+ }
+ }
+
+ for (member in node.members) {
+ buildCrossReferences(member)
+ }
+}
+