aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin/DocumentationBuilder.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/Kotlin/DocumentationBuilder.kt')
-rw-r--r--src/Kotlin/DocumentationBuilder.kt29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index be6d5d7c..053615bc 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,34 @@ 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 kdoc = findKDoc(descriptor)
+ val docText = kdoc?.getContent() ?: ""
val tree = parseMarkdown(docText)
//println(tree.toTestString())
- val content = buildContent(tree, descriptor)
+ val content = buildContent(tree)
+ if (kdoc is KDocSection) {
+ val tags = PsiTreeUtil.getChildrenOfType(kdoc, javaClass<KDocTag>())
+ 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 displayName(sectionName: String?): String? =
+ when(sectionName) {
+ "param" -> "Parameters"
+ "throws", "exception" -> "Exceptions"
+ else -> sectionName
+ }
+
fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) {
links.put(node, descriptor)
}