diff options
author | Dmitry Jemerov <intelliyole@gmail.com> | 2015-01-16 19:17:13 +0100 |
---|---|---|
committer | Dmitry Jemerov <intelliyole@gmail.com> | 2015-01-16 19:17:13 +0100 |
commit | 18bd85cc710718658d6c902c04de5d356cd0aee8 (patch) | |
tree | fcecd542c10b764a8120cd839db47c25f8eba386 /src | |
parent | 0f7f49d4828b618d0f5ea0475d15f7498b61f6de (diff) | |
parent | d093fc192beab22086506240fbe7747663cc73fa (diff) | |
download | dokka-18bd85cc710718658d6c902c04de5d356cd0aee8.tar.gz dokka-18bd85cc710718658d6c902c04de5d356cd0aee8.tar.bz2 dokka-18bd85cc710718658d6c902c04de5d356cd0aee8.zip |
Merge pull request #22 from orangy/broken-links
don't generate broken links if a doc comment references an unresolved symbol
Diffstat (limited to 'src')
-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? { |