From 0fac1d925b74f24002a4e1538088ce66c4b02cb9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 30 Jan 2015 19:01:40 +0100 Subject: code review --- src/Kotlin/ContentBuilder.kt | 2 +- src/Kotlin/DocumentationBuilder.kt | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/Kotlin') diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 95e08c92..35beec54 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -112,7 +112,7 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: ContentNode) { - val inlineContent = tree.children.firstOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree) + val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree) inlineContent.forEach { buildContentTo(it, target) } diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 053615bc..c0533437 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -41,13 +41,15 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati fun parseDocumentation(descriptor: DeclarationDescriptor): Content { val kdoc = findKDoc(descriptor) - val docText = kdoc?.getContent() ?: "" - val tree = parseMarkdown(docText) + if (kdoc == null) { + return Content.Empty + } + val tree = parseMarkdown(kdoc.getContent()) //println(tree.toTestString()) val content = buildContent(tree) if (kdoc is KDocSection) { - val tags = PsiTreeUtil.getChildrenOfType(kdoc, javaClass()) - tags?.forEach { + val tags = kdoc.getTags() + tags.forEach { if (it.getName() == "code") { content.append(functionBody(descriptor, it.getContent())) } else { @@ -61,11 +63,13 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati return content } + fun KDocSection.getTags(): Array = PsiTreeUtil.getChildrenOfType(this, javaClass()) ?: array() + fun displayName(sectionName: String?): String? = when(sectionName) { "param" -> "Parameters" "throws", "exception" -> "Exceptions" - else -> sectionName + else -> sectionName?.capitalize() } fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) { -- cgit