aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-05-03 18:20:33 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-07-14 23:57:11 +0300
commit74b228108445a8a9024b6892f6562d77c658fc64 (patch)
treebc61e3d132d060af01fb58b1480e06d98b8ee09c /core
parentee0b640ad5c4a8cc1b65403dc2c48e7723b8f53a (diff)
downloaddokka-74b228108445a8a9024b6892f6562d77c658fc64.tar.gz
dokka-74b228108445a8a9024b6892f6562d77c658fc64.tar.bz2
dokka-74b228108445a8a9024b6892f6562d77c658fc64.zip
[backport] KT-24152: Support implicit sections inheritance
Original: 5636fac
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Java/JavadocParser.kt40
1 files changed, 39 insertions, 1 deletions
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt
index 554cd2d3..41b77aed 100644
--- a/core/src/main/kotlin/Java/JavadocParser.kt
+++ b/core/src/main/kotlin/Java/JavadocParser.kt
@@ -2,12 +2,12 @@ package org.jetbrains.dokka
import com.intellij.psi.*
import com.intellij.psi.impl.source.javadoc.CorePsiDocTagValueImpl
-import com.intellij.psi.javadoc.*
import com.intellij.psi.impl.source.tree.JavaDocElementType
import com.intellij.psi.javadoc.*
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.IncorrectOperationException
import com.intellij.util.containers.isNullOrEmpty
+import org.jetbrains.kotlin.utils.keysToMap
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.nodes.Node
@@ -43,6 +43,17 @@ class JavadocParser(
paragraphs.forEach {
result.append(it)
}
+
+ if (element is PsiMethod) {
+ val tagsByName = element.searchInheritedTags()
+ for ((tagName, tags) in tagsByName) {
+ for ((tag, context) in tags) {
+ val section = result.addSection(javadocSectionDisplayName(tagName), tag.getSubjectName())
+ section.convertJavadocElements(tag.contentElements(), context)
+ }
+ }
+ }
+
docComment.tags.forEach { tag ->
when (tag.name) {
"see" -> result.convertSeeTag(tag)
@@ -51,6 +62,7 @@ class JavadocParser(
convertJavadocElements(tag.contentElements(), element)
}
}
+ in tagsToInherit -> {}
else -> {
val subjectName = tag.getSubjectName()
val section = result.addSection(javadocSectionDisplayName(tag.name), subjectName)
@@ -62,6 +74,32 @@ class JavadocParser(
return JavadocParseResult(result, deprecatedContent)
}
+ private val tagsToInherit = setOf("param", "return", "throws")
+
+ private data class TagWithContext(val tag: PsiDocTag, val context: PsiNamedElement)
+
+ private fun PsiMethod.searchInheritedTags(): Map<String, Collection<TagWithContext>> {
+
+ val output = tagsToInherit.keysToMap { mutableMapOf<String?, TagWithContext>() }
+
+ fun recursiveSearch(methods: Array<PsiMethod>) {
+ for (method in methods) {
+ recursiveSearch(method.findSuperMethods())
+ }
+ for (method in methods) {
+ for (tag in method.docComment?.tags.orEmpty()) {
+ if (tag.name in tagsToInherit) {
+ output[tag.name]!![tag.getSubjectName()] = TagWithContext(tag, method)
+ }
+ }
+ }
+ }
+
+ recursiveSearch(arrayOf(this))
+ return output.mapValues { it.value.values }
+ }
+
+
private fun PsiDocTag.contentElements(): Iterable<PsiElement> {
val tagValueElements = children
.dropWhile { it.node?.elementType == JavaDocTokenType.DOC_TAG_NAME }