diff options
-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 |