aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-05-04 00:32:40 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-07-14 23:57:11 +0300
commita50de81d3d0ce88d2fd8e91a55b203ba49e66eb1 (patch)
treec83035c118424cdeb280ded3d41ff4e911cb7bf2 /core/src
parent74b228108445a8a9024b6892f6562d77c658fc64 (diff)
downloaddokka-a50de81d3d0ce88d2fd8e91a55b203ba49e66eb1.tar.gz
dokka-a50de81d3d0ce88d2fd8e91a55b203ba49e66eb1.tar.bz2
dokka-a50de81d3d0ce88d2fd8e91a55b203ba49e66eb1.zip
[backport] KT-24028: Add type info to param and return section in javadoc
Original: a603157
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Java/JavadocParser.kt23
-rw-r--r--core/src/main/kotlin/Model/Content.kt30
2 files changed, 52 insertions, 1 deletions
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt
index 41b77aed..5e23e357 100644
--- a/core/src/main/kotlin/Java/JavadocParser.kt
+++ b/core/src/main/kotlin/Java/JavadocParser.kt
@@ -28,6 +28,18 @@ class JavadocParser(
private val logger: DokkaLogger,
private val signatureProvider: ElementSignatureProvider
) : JavaDocumentationParser {
+
+ private fun ContentSection.appendTypeElement(signature: String, selector: (DocumentationNode) -> DocumentationNode?) {
+ append(LazyContentBlock {
+ val node = refGraph.lookupOrWarn(signature, logger)?.let(selector)
+ if (node != null) {
+ it.append(NodeRenderContent(node, LanguageService.RenderMode.SUMMARY))
+ it.symbol(":")
+ it.text(" ")
+ }
+ })
+ }
+
override fun parseDocumentation(element: PsiNamedElement): JavadocParseResult {
val docComment = (element as? PsiDocCommentOwner)?.docComment
if (docComment == null) return JavadocParseResult.Empty
@@ -49,6 +61,17 @@ class JavadocParser(
for ((tagName, tags) in tagsByName) {
for ((tag, context) in tags) {
val section = result.addSection(javadocSectionDisplayName(tagName), tag.getSubjectName())
+ val signature = signatureProvider.signature(element)
+ when (tagName) {
+ "param" -> {
+ section.appendTypeElement(signature) {
+ it.details.find { it.kind == NodeKind.Parameter }?.detailOrNull(NodeKind.Type)
+ }
+ }
+ "return" -> {
+ section.appendTypeElement(signature) { it.detailOrNull(NodeKind.Type) }
+ }
+ }
section.convertJavadocElements(tag.contentElements(), context)
}
}
diff --git a/core/src/main/kotlin/Model/Content.kt b/core/src/main/kotlin/Model/Content.kt
index 1f5bbc83..010ee7ca 100644
--- a/core/src/main/kotlin/Model/Content.kt
+++ b/core/src/main/kotlin/Model/Content.kt
@@ -9,7 +9,7 @@ object ContentEmpty : ContentNode {
}
open class ContentBlock() : ContentNode {
- val children = arrayListOf<ContentNode>()
+ open val children = arrayListOf<ContentNode>()
fun append(node: ContentNode) {
children.add(node)
@@ -27,6 +27,34 @@ open class ContentBlock() : ContentNode {
get() = children.sumBy { it.textLength }
}
+class NodeRenderContent(
+ val node: DocumentationNode,
+ val mode: LanguageService.RenderMode
+): ContentNode {
+ override val textLength: Int
+ get() = 0 //TODO: Clarify?
+}
+
+class LazyContentBlock(private val fillChildren: (ContentBlock) -> Unit) : ContentBlock() {
+ private var computed = false
+ override val children: ArrayList<ContentNode>
+ get() {
+ if (!computed) {
+ computed = true
+ fillChildren(this)
+ }
+ return super.children
+ }
+
+ override fun equals(other: Any?): Boolean {
+ return other is LazyContentBlock && other.fillChildren == fillChildren && super.equals(other)
+ }
+
+ override fun hashCode(): Int {
+ return super.hashCode() + 31 * fillChildren.hashCode()
+ }
+}
+
enum class IdentifierKind {
TypeName,
ParameterName,