From 2bdb222516df07519bf5415941e88ce9a24993ea Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 5 Feb 2015 12:44:26 +0100 Subject: [PATCH] as a workaround for KT-4502, wrap KDoc rendering functions in an object --- .../idea/JetQuickDocumentationProvider.java | 3 +- .../kotlin/idea/kdoc/KDocRenderer.kt | 70 ++++++++++--------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/JetQuickDocumentationProvider.java b/idea/src/org/jetbrains/kotlin/idea/JetQuickDocumentationProvider.java index 522ad38407e..ce40acac926 100644 --- a/idea/src/org/jetbrains/kotlin/idea/JetQuickDocumentationProvider.java +++ b/idea/src/org/jetbrains/kotlin/idea/JetQuickDocumentationProvider.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.asJava.KotlinLightMethod; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; +import org.jetbrains.kotlin.idea.kdoc.KDocRenderer; import org.jetbrains.kotlin.kdoc.KdocPackage; import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag; import org.jetbrains.kotlin.psi.JetDeclaration; @@ -92,7 +93,7 @@ public class JetQuickDocumentationProvider extends AbstractDocumentationProvider KDocTag comment = KdocPackage.findKDoc(declarationDescriptor); if (comment != null) { - renderedDecl = renderedDecl + "
" + org.jetbrains.kotlin.idea.kdoc.KdocPackage.renderKDoc(comment); + renderedDecl = renderedDecl + "
" + KDocRenderer.INSTANCE$.renderKDoc(comment); } return renderedDecl; diff --git a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt index 3a1d35900f3..d24e8ad4163 100644 --- a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt @@ -20,47 +20,49 @@ import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection -fun renderKDoc(docComment: KDocTag): String { - val content = docComment.getContent() - val result = StringBuilder("

") - result.append(markdownToHtml(content)) - if (docComment is KDocSection) { - val paramTags = docComment.findTagsByName("param").filter { it.getSubjectName() != null } - renderTagList(paramTags, "Parameters", result) +object KDocRenderer { + fun renderKDoc(docComment: KDocTag): String { + val content = docComment.getContent() + val result = StringBuilder("

") + result.append(markdownToHtml(content)) + if (docComment is KDocSection) { + val paramTags = docComment.findTagsByName("param").filter { it.getSubjectName() != null } + renderTagList(paramTags, "Parameters", result) - renderTag(docComment.findTagByName("return"), "Returns", result) + renderTag(docComment.findTagByName("return"), "Returns", result) - val throwsTags = (docComment.findTagsByName("exception").union(docComment.findTagsByName("throws"))) - .filter { it.getSubjectName() != null } - renderTagList(throwsTags, "Throws", result) + val throwsTags = (docComment.findTagsByName("exception").union(docComment.findTagsByName("throws"))) + .filter { it.getSubjectName() != null } + renderTagList(throwsTags, "Throws", result) - renderTag(docComment.findTagByName("author"), "Author", result) - renderTag(docComment.findTagByName("since"), "Since", result) + renderTag(docComment.findTagByName("author"), "Author", result) + renderTag(docComment.findTagByName("since"), "Since", result) + } + result.append("

") + return result.toString() } - result.append("

") - return result.toString() -} -private fun renderTagList(tags: List, title: String, to: StringBuilder) { - if (tags.isEmpty()) { - return - } - to.append("
${title}:
") - tags.forEach { - to.append("
${it.getSubjectName()} - ${markdownToHtml(it.getContent().trimLeading())}
") - } - to.append("
") -} - -private fun renderTag(tag: KDocTag?, title: String, to: StringBuilder) { - if (tag != null) { + private fun renderTagList(tags: List, title: String, to: StringBuilder) { + if (tags.isEmpty()) { + return + } to.append("
${title}:
") - to.append("
${markdownToHtml(tag.getContent())}
") + tags.forEach { + to.append("
${it.getSubjectName()} - ${markdownToHtml(it.getContent().trimLeading())}
") + } to.append("
") } -} -fun markdownToHtml(markdown: String): String { - // TODO Integrate a real Markdown parser - return StringUtil.replace(markdown, "\n", "
"); + private fun renderTag(tag: KDocTag?, title: String, to: StringBuilder) { + if (tag != null) { + to.append("
${title}:
") + to.append("
${markdownToHtml(tag.getContent())}
") + to.append("
") + } + } + + fun markdownToHtml(markdown: String): String { + // TODO Integrate a real Markdown parser + return StringUtil.replace(markdown, "\n", "
"); + } }