diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-03 23:05:28 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-03 23:05:28 +0400 |
commit | 04135d13e4f1fc41893767b8719e9189cd41617a (patch) | |
tree | c8b4efe0df0dffbe77285eaee07bfe570befcde9 | |
parent | 71cd87e239ba4ba846eb5da04e45a451b8a840cb (diff) | |
download | dokka-04135d13e4f1fc41893767b8719e9189cd41617a.tar.gz dokka-04135d13e4f1fc41893767b8719e9189cd41617a.tar.bz2 dokka-04135d13e4f1fc41893767b8719e9189cd41617a.zip |
Resolve links to symbols with custom text
-rw-r--r-- | src/Kotlin/DocumentationContext.kt | 4 | ||||
-rw-r--r-- | src/Kotlin/ResolveReferences.kt | 30 |
2 files changed, 16 insertions, 18 deletions
diff --git a/src/Kotlin/DocumentationContext.kt b/src/Kotlin/DocumentationContext.kt index 649543ac..95c3ded1 100644 --- a/src/Kotlin/DocumentationContext.kt +++ b/src/Kotlin/DocumentationContext.kt @@ -9,9 +9,9 @@ import org.jetbrains.jet.lang.resolve.name.FqName /** * Context for documentation generation. * - * Holds information about relations between nodes and descriptors during documentation generation + * Holds information about relations between [nodes](DocumentationNode) and [descriptors](DeclarationDescriptor) during documentation generation * - * %bindingContext: symbol resolution context + * $bindingContext: symbol resolution context */ public class DocumentationContext(val bindingContext: BindingContext) { val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>() diff --git a/src/Kotlin/ResolveReferences.kt b/src/Kotlin/ResolveReferences.kt index 90e23ffb..b14d3718 100644 --- a/src/Kotlin/ResolveReferences.kt +++ b/src/Kotlin/ResolveReferences.kt @@ -46,38 +46,36 @@ public fun DocumentationContext.resolveReferences(node: DocumentationNode) { } } -fun DocumentationContext.resolveContentLinks(node : DocumentationNode, content: ContentNode) { +fun DocumentationContext.resolveContentLinks(node: DocumentationNode, content: ContentNode) { val snapshot = content.children.toList() for (child in snapshot) { - if (child is ContentNameLink) { + val referenceText = when (child) { + is ContentExternalLink -> child.href + is ContentNameLink -> child.name + else -> null + } + + if (referenceText != null && Name.isValidIdentifier(referenceText)) { val scope = getResolutionScope(node) - val symbolName = child.name + val symbolName = Name.guess(referenceText) val symbol = - scope.getLocalVariable(Name.guess(symbolName)) ?: - scope.getProperties(Name.guess(symbolName)).firstOrNull() ?: - scope.getFunctions(Name.guess(symbolName)).firstOrNull() ?: - scope.getClassifier(Name.guess(symbolName)) + scope.getLocalVariable(symbolName) ?: + scope.getProperties(symbolName).firstOrNull() ?: + scope.getFunctions(symbolName).firstOrNull() ?: + scope.getClassifier(symbolName) if (symbol != null) { val targetNode = descriptorToNode[symbol] if (targetNode != null) { - // we have a doc node for the symbol val index = content.children.indexOf(child) content.children.remove(index) val contentLink = ContentNodeLink(targetNode) - contentLink.children.add(ContentIdentifier(symbolName)) - //contentLink.children.addAll(child.children) - content.children.add(index, contentLink) - } else { - // we don't have a doc node for the symbol, render as identifier - val index = content.children.indexOf(child) - content.children.remove(index) - val contentLink = ContentIdentifier(symbolName) contentLink.children.addAll(child.children) content.children.add(index, contentLink) } } } + resolveContentLinks(node, child) } }
\ No newline at end of file |