aboutsummaryrefslogtreecommitdiff
path: root/src/Java
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-10-30 19:33:29 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-10-30 19:33:29 +0100
commitded569657d1f16905180313593336963c467f242 (patch)
treeb25ff8eab14b565e6eb03b959c76e3a5601cd565 /src/Java
parente4b2ae90bf0e84f76ceb7c56b7c128d28adad917 (diff)
downloaddokka-ded569657d1f16905180313593336963c467f242.tar.gz
dokka-ded569657d1f16905180313593336963c467f242.tar.bz2
dokka-ded569657d1f16905180313593336963c467f242.zip
load KDoc comments when building javadoc
Diffstat (limited to 'src/Java')
-rw-r--r--src/Java/JavaDocumentationBuilder.kt103
1 files changed, 59 insertions, 44 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 660ac4a8..e0cc53a0 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -1,31 +1,30 @@
package org.jetbrains.dokka
import com.intellij.psi.*
-import com.intellij.psi.javadoc.*
+import com.intellij.psi.javadoc.PsiDocTag
+import com.intellij.psi.javadoc.PsiDocTagValue
+import com.intellij.psi.javadoc.PsiDocToken
+import com.intellij.psi.javadoc.PsiInlineDocTag
import org.jetbrains.dokka.DocumentationNode.Kind
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.nodes.Node
import org.jsoup.nodes.TextNode
-public class JavaDocumentationBuilder(private val options: DocumentationOptions,
- private val refGraph: NodeReferenceGraph) {
- fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
- if (file.classes.all { skipElement(it) }) {
- return
- }
- val packageNode = module.findOrCreatePackageNode(file.packageName, emptyMap())
- appendClasses(packageNode, file.classes)
- }
-
- fun appendClasses(packageNode: DocumentationNode, classes: Array<PsiClass>) {
- packageNode.appendChildren(classes) { build() }
+data class JavadocParseResult(val content: Content, val deprecatedContent: Content?) {
+ companion object {
+ val Empty = JavadocParseResult(Content.Empty, null)
}
+}
- data class JavadocParseResult(val content: Content, val deprecatedContent: Content?)
+interface JavaDocumentationParser {
+ fun parseDocumentation(element: PsiNamedElement): JavadocParseResult
+}
- fun parseDocumentation(docComment: PsiDocComment?): JavadocParseResult {
- if (docComment == null) return JavadocParseResult(Content.Empty, null)
+class JavadocParser(private val refGraph: NodeReferenceGraph) : JavaDocumentationParser {
+ override fun parseDocumentation(element: PsiNamedElement): JavadocParseResult {
+ val docComment = (element as? PsiDocCommentOwner)?.docComment
+ if (docComment == null) return JavadocParseResult.Empty
val result = MutableContent()
var deprecatedContent: Content? = null
val para = ContentParagraph()
@@ -169,6 +168,49 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
}
return null
}
+}
+
+
+private fun getSignature(element: PsiElement?) = when(element) {
+ is PsiClass -> element.qualifiedName
+ is PsiField -> element.containingClass!!.qualifiedName + "#" + element.name
+ is PsiMethod ->
+ element.containingClass!!.qualifiedName + "#" + element.name + "(" +
+ element.parameterList.parameters.map { it.type.typeSignature() }.joinToString(",") + ")"
+ else -> null
+}
+
+private fun PsiType.typeSignature(): String = when(this) {
+ is PsiArrayType -> "Array<${componentType.typeSignature()}>"
+ else -> mapTypeName(this)
+}
+
+private fun mapTypeName(psiType: PsiType): String = when (psiType) {
+ PsiType.VOID -> "Unit"
+ is PsiPrimitiveType -> psiType.canonicalText.capitalize()
+ is PsiClassType -> {
+ val psiClass = psiType.resolve()
+ if (psiClass?.qualifiedName == "java.lang.Object") "Any" else psiType.className
+ }
+ is PsiEllipsisType -> mapTypeName(psiType.componentType)
+ is PsiArrayType -> "Array"
+ else -> psiType.canonicalText
+}
+
+class JavaDocumentationBuilder(private val options: DocumentationOptions,
+ private val refGraph: NodeReferenceGraph,
+ private val docParser: JavaDocumentationParser = JavadocParser(refGraph)) {
+ fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
+ if (file.classes.all { skipElement(it) }) {
+ return
+ }
+ val packageNode = module.findOrCreatePackageNode(file.packageName, emptyMap())
+ appendClasses(packageNode, file.classes)
+ }
+
+ fun appendClasses(packageNode: DocumentationNode, classes: Array<PsiClass>) {
+ packageNode.appendChildren(classes) { build() }
+ }
fun register(element: PsiElement, node: DocumentationNode) {
val signature = getSignature(element)
@@ -190,25 +232,10 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
refGraph.link(qualifiedName, node, kind)
}
}
-
- private fun getSignature(element: PsiElement?) = when(element) {
- is PsiClass -> element.qualifiedName
- is PsiField -> element.containingClass!!.qualifiedName + "#" + element.name
- is PsiMethod ->
- element.containingClass!!.qualifiedName + "#" + element.name + "(" +
- element.parameterList.parameters.map { it.type.typeSignature() }.joinToString(",") + ")"
- else -> null
- }
-
- private fun PsiType.typeSignature(): String = when(this) {
- is PsiArrayType -> "Array<${componentType.typeSignature()}>"
- else -> mapTypeName(this)
- }
-
fun DocumentationNode(element: PsiNamedElement,
kind: Kind,
name: String = element.name ?: "<anonymous>"): DocumentationNode {
- val (docComment, deprecatedContent) = parseDocumentation((element as? PsiDocCommentOwner)?.docComment)
+ val (docComment, deprecatedContent) = docParser.parseDocumentation(element)
val node = DocumentationNode(name, docComment, kind)
if (element is PsiModifierListOwner) {
node.appendModifiers(element)
@@ -378,18 +405,6 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
return node
}
- private fun mapTypeName(psiType: PsiType): String = when (psiType) {
- PsiType.VOID -> "Unit"
- is PsiPrimitiveType -> psiType.canonicalText.capitalize()
- is PsiClassType -> {
- val psiClass = psiType.resolve()
- if (psiClass?.qualifiedName == "java.lang.Object") "Any" else psiType.className
- }
- is PsiEllipsisType -> mapTypeName(psiType.componentType)
- is PsiArrayType -> "Array"
- else -> psiType.canonicalText
- }
-
fun PsiAnnotation.build(): DocumentationNode {
val node = DocumentationNode(nameReferenceElement?.text ?: "<?>", Content.Empty, DocumentationNode.Kind.Annotation)
parameterList.attributes.forEach {