From 4ed5b2ec786b0f67405e5db81be2a2d9f4b6e591 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 5 Feb 2015 16:53:40 +0100 Subject: use code from Kotlin plugin for resolving references in KDoc; delete some dead code --- src/Analysis/PsiAPI.kt | 23 ----------------------- src/Kotlin/DocumentationBuilder.kt | 31 +++++-------------------------- 2 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 src/Analysis/PsiAPI.kt (limited to 'src') diff --git a/src/Analysis/PsiAPI.kt b/src/Analysis/PsiAPI.kt deleted file mode 100644 index 19ac4675..00000000 --- a/src/Analysis/PsiAPI.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.jetbrains.dokka - -import com.intellij.psi.* -import kotlin.support.* - -fun PsiElement.children(): Stream { - val parent = this - var current: PsiElement? = null - return object : Stream { - override fun iterator(): Iterator = object : AbstractIterator() { - { - setNext(parent.getFirstChild()) - } - override fun computeNext() { - current = current?.getNextSibling() - if (current == null) - done() - else - setNext(current!!) - } - } - } -} diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 976626db..041b7617 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.kdoc.findKDoc import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag +import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink public data class DocumentationOptions(val includeNonPublic: Boolean = false, val sourceLinks: List) @@ -542,11 +543,11 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati private fun resolveContentLink(node: DocumentationNode, content: ContentNode): ContentNode { if (content is ContentExternalLink) { val referenceText = content.href - val symbol = resolveReference(getResolutionScope(node), referenceText) + val symbols = resolveKDocLink(session, getResolutionScope(node), null, referenceText.split('.').toList()) // don't include unresolved links in generated doc // assume that if an href doesn't contain '/', it's not an attempt to reference an external file - if (symbol != null || "/" !in referenceText) { - val targetNode = descriptorToNode[symbol] + if (symbols.isNotEmpty() || "/" !in referenceText) { + val targetNode = if (symbols.isEmpty()) null else descriptorToNode[symbols.first()] val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#") contentLink.children.addAll(content.children.map { resolveContentLink(node, it) }) return contentLink @@ -555,26 +556,4 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati resolveContentLinks(node, content) return content } - - private fun resolveReference(context: DeclarationDescriptor, reference: String): DeclarationDescriptor? { - if (Name.isValidIdentifier(reference)) { - val scope = getResolutionScope(context) - val symbolName = Name.guess(reference) - return scope.getLocalVariable(symbolName) ?: - scope.getProperties(symbolName).firstOrNull() ?: - scope.getFunctions(symbolName).firstOrNull() ?: - scope.getClassifier(symbolName) - - } - - if ("." !in reference) - return null - - val names = reference.split('.') - val result = names.fold(context) {(nextContext, name) -> - nextContext?.let { resolveReference(it, name) } - } - - return result - } -} \ No newline at end of file +} -- cgit