diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-16 13:25:16 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-16 13:25:16 +0100 |
commit | d093fc192beab22086506240fbe7747663cc73fa (patch) | |
tree | c7c858dfbf29b5b3764be1252467c82c6e6fb31a /src/Kotlin/DocumentationBuilder.kt | |
parent | d75cc63e9b1edc229fad225956ba44fa433e2d0e (diff) | |
download | dokka-d093fc192beab22086506240fbe7747663cc73fa.tar.gz dokka-d093fc192beab22086506240fbe7747663cc73fa.tar.bz2 dokka-d093fc192beab22086506240fbe7747663cc73fa.zip |
don't generate broken links if a doc comment references an unresolved symbol
Diffstat (limited to 'src/Kotlin/DocumentationBuilder.kt')
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 6403f14c..be6d5d7c 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor -import org.jetbrains.kotlin.resolve.source.getPsi import java.io.File import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiNameIdentifierOwner @@ -506,24 +505,26 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } fun resolveContentLinks(node: DocumentationNode, content: ContentNode) { - val snapshot = content.children.toList() - for (child in snapshot) { - if (child is ContentExternalLink) { - val referenceText = child.href - val symbol = resolveReference(getResolutionScope(node), referenceText) - if (symbol != null) { - val targetNode = descriptorToNode[symbol] - val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#") - - val index = content.children.indexOf(child) - content.children.remove(index) - contentLink.children.addAll(child.children) - content.children.add(index, contentLink) - } - + val resolvedContentChildren = content.children.map { resolveContentLink(node, it) } + content.children.clear() + content.children.addAll(resolvedContentChildren) + } + + private fun resolveContentLink(node: DocumentationNode, content: ContentNode): ContentNode { + if (content is ContentExternalLink) { + val referenceText = content.href + val symbol = resolveReference(getResolutionScope(node), referenceText) + // 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] + val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#") + contentLink.children.addAll(content.children.map { resolveContentLink(node, it) }) + return contentLink } - resolveContentLinks(node, child) } + resolveContentLinks(node, content) + return content } private fun resolveReference(context: DeclarationDescriptor, reference: String): DeclarationDescriptor? { |