aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin/DocumentationBuilder.kt
diff options
context:
space:
mode:
authorDmitry Jemerov <intelliyole@gmail.com>2015-01-30 19:04:34 +0100
committerDmitry Jemerov <intelliyole@gmail.com>2015-01-30 19:04:34 +0100
commitb5286f576f470ad1665a7b1acc9ea276bc1a0c18 (patch)
tree5cf3800e961b9da84b2db03707603865496f5ed0 /src/Kotlin/DocumentationBuilder.kt
parentb55b258574a01a02f906f5f12646ecacfc640e20 (diff)
parent0fac1d925b74f24002a4e1538088ce66c4b02cb9 (diff)
downloaddokka-b5286f576f470ad1665a7b1acc9ea276bc1a0c18.tar.gz
dokka-b5286f576f470ad1665a7b1acc9ea276bc1a0c18.tar.bz2
dokka-b5286f576f470ad1665a7b1acc9ea276bc1a0c18.zip
Merge pull request #24 from orangy/sections-rewrite
Use KDoc PSI instead of custom Markdown extensions to parse KDoc into sections
Diffstat (limited to 'src/Kotlin/DocumentationBuilder.kt')
-rw-r--r--src/Kotlin/DocumentationBuilder.kt35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index be6d5d7c..c0533437 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -18,6 +18,10 @@ import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.psi.JetParameter
+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
public data class DocumentationOptions(val includeNonPublic: Boolean = false,
val sourceLinks: List<SourceLinkDefinition>)
@@ -36,13 +40,38 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
val packages = hashMapOf<FqName, DocumentationNode>()
fun parseDocumentation(descriptor: DeclarationDescriptor): Content {
- val docText = descriptor.getDocumentationElements().map { it.extractText() }.join("\n")
- val tree = parseMarkdown(docText)
+ val kdoc = findKDoc(descriptor)
+ if (kdoc == null) {
+ return Content.Empty
+ }
+ val tree = parseMarkdown(kdoc.getContent())
//println(tree.toTestString())
- val content = buildContent(tree, descriptor)
+ val content = buildContent(tree)
+ if (kdoc is KDocSection) {
+ val tags = kdoc.getTags()
+ tags.forEach {
+ if (it.getName() == "code") {
+ content.append(functionBody(descriptor, it.getContent()))
+ } else {
+ val section = content.addSection(displayName(it.getName()), it.getSubjectName())
+ val sectionContent = it.getContent()
+ val markdownNode = parseMarkdown(sectionContent)
+ buildInlineContentTo(markdownNode, section)
+ }
+ }
+ }
return content
}
+ fun KDocSection.getTags(): Array<KDocTag> = PsiTreeUtil.getChildrenOfType(this, javaClass<KDocTag>()) ?: array()
+
+ fun displayName(sectionName: String?): String? =
+ when(sectionName) {
+ "param" -> "Parameters"
+ "throws", "exception" -> "Exceptions"
+ else -> sectionName?.capitalize()
+ }
+
fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) {
links.put(node, descriptor)
}