aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt14
-rw-r--r--core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt7
-rw-r--r--core/src/main/kotlin/model/doc/DocTag.kt5
-rw-r--r--core/src/main/kotlin/model/doc/TagWrapper.kt2
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt3
-rw-r--r--plugins/base/src/main/kotlin/parsers/HtmlParser.kt89
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt61
-rw-r--r--plugins/base/src/main/kotlin/parsers/Parser.kt77
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt55
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt8
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt33
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt11
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt193
-rw-r--r--plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt690
-rw-r--r--plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt10
-rw-r--r--plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt24
-rw-r--r--plugins/base/src/test/kotlin/utils/contentUtils.kt16
-rw-r--r--plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt6
18 files changed, 1060 insertions, 244 deletions
diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
index 67c0e692..264be933 100644
--- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
+++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt
@@ -3,7 +3,6 @@ package matchers.content
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
-import assertk.assertions.matches
import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.test.tools.matchers.content.*
@@ -53,12 +52,6 @@ fun <T : ContentComposite> ContentMatcherBuilder<T>.hasExactText(expected: Strin
}
}
-fun <T : ContentComposite> ContentMatcherBuilder<T>.textMatches(pattern: Regex) {
- assertions += {
- assertThat(this::extractedText).matches(pattern)
- }
-}
-
inline fun <reified S : ContentComposite> ContentMatcherBuilder<*>.composite(
block: ContentMatcherBuilder<S>.() -> Unit
) {
@@ -96,6 +89,13 @@ fun ContentMatcherBuilder<*>.table(block: ContentMatcherBuilder<ContentTable>.()
fun ContentMatcherBuilder<*>.platformHinted(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) =
composite<PlatformHintedContent> { group(block) }
+fun ContentMatcherBuilder<*>.list(block: ContentMatcherBuilder<ContentList>.() -> Unit) = composite(block)
+
+fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<ContentGroup> {
+ block()
+ check { assertThat(this::style).contains(ContentStyle.Caption) }
+}
+
fun ContentMatcherBuilder<*>.br() = node<ContentBreakLine>()
fun ContentMatcherBuilder<*>.somewhere(block: ContentMatcherBuilder<*>.() -> Unit) {
diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt
index f42e28f3..6a0e1c97 100644
--- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt
+++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/contentMatchers.kt
@@ -69,10 +69,9 @@ private class TextMatcherState(
) : MatchWalkerState() {
override fun next(node: ContentNode): MatchWalkerState {
node as? ContentText ?: throw MatcherError("Expected text: \"$text\" but got\n${node.debugRepresentation()}", anchor)
- val trimmed = node.text.trim()
return when {
- text == trimmed -> rest.pop()
- text.startsWith(trimmed) -> TextMatcherState(text.removePrefix(node.text).trim(), rest, anchor)
+ text == node.text -> rest.pop()
+ text.startsWith(node.text) -> TextMatcherState(text.removePrefix(node.text), rest, anchor)
else -> throw MatcherError("Expected text: \"$text\", but got: \"${node.text}\"", anchor)
}
}
@@ -111,7 +110,7 @@ private class SkippingMatcherState(
private class FurtherSiblings(val list: List<MatcherElement>, val parent: CompositeMatcher<*>) {
fun pop(): MatchWalkerState = when (val head = list.firstOrNull()) {
- is TextMatcher -> TextMatcherState(head.text.trim(), drop(), head)
+ is TextMatcher -> TextMatcherState(head.text, drop(), head)
is NodeMatcher<*> -> NodeMatcherState(head, drop())
is Anything -> SkippingMatcherState(drop().pop())
null -> EmptyMatcherState(parent)
diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt
index 04b5c913..7698ebb3 100644
--- a/core/src/main/kotlin/model/doc/DocTag.kt
+++ b/core/src/main/kotlin/model/doc/DocTag.kt
@@ -354,3 +354,8 @@ data class Var(
override val children: List<DocTag> = emptyList(),
override val params: Map<String, String> = emptyMap()
) : DocTag()
+
+data class Caption(
+ override val children: List<DocTag> = emptyList(),
+ override val params: Map<String, String> = emptyMap()
+) : DocTag() \ No newline at end of file
diff --git a/core/src/main/kotlin/model/doc/TagWrapper.kt b/core/src/main/kotlin/model/doc/TagWrapper.kt
index cfe99b1e..cea132a8 100644
--- a/core/src/main/kotlin/model/doc/TagWrapper.kt
+++ b/core/src/main/kotlin/model/doc/TagWrapper.kt
@@ -22,7 +22,7 @@ data class Param(override val root: DocTag, override val name: String) : NamedTa
data class Return(override val root: DocTag) : TagWrapper()
data class Receiver(override val root: DocTag) : TagWrapper()
data class Constructor(override val root: DocTag) : TagWrapper()
-data class Throws(override val root: DocTag, override val name: String) : NamedTagWrapper()
+data class Throws(override val root: DocTag, override val name: String, val exceptionAddress: DRI?) : NamedTagWrapper()
data class Sample(override val root: DocTag, override val name: String) : NamedTagWrapper()
data class Deprecated(override val root: DocTag) : TagWrapper()
data class Property(override val root: DocTag, override val name: String) : NamedTagWrapper()
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index 77e6ebb2..303fa803 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -182,6 +182,7 @@ interface ContentComposite : ContentNode {
/** Tables */
data class ContentTable(
val header: List<ContentGroup>,
+ val caption: ContentGroup? = null,
override val children: List<ContentGroup>,
override val dci: DCI,
override val sourceSets: Set<DisplaySourceSet>,
@@ -343,7 +344,7 @@ enum class TextStyle : Style {
}
enum class ContentStyle : Style {
- RowTitle, TabbedContent, WithExtraAttributes, RunnableSample, InDocumentationAnchor
+ RowTitle, TabbedContent, WithExtraAttributes, RunnableSample, InDocumentationAnchor, Caption
}
object CommentTable : Style
diff --git a/plugins/base/src/main/kotlin/parsers/HtmlParser.kt b/plugins/base/src/main/kotlin/parsers/HtmlParser.kt
deleted file mode 100644
index ece3cf24..00000000
--- a/plugins/base/src/main/kotlin/parsers/HtmlParser.kt
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.jetbrains.dokka.base.parsers
-
-import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.dokka.base.parsers.factories.DocTagsFromStringFactory
-import org.jsoup.Jsoup
-import org.jsoup.nodes.Node
-import org.jsoup.select.NodeFilter
-import org.jsoup.select.NodeTraversor
-
-class HtmlParser : Parser() {
-
- inner class NodeFilterImpl : NodeFilter {
-
- private val nodesCache: MutableMap<Int, MutableList<DocTag>> = mutableMapOf()
- private var currentDepth = 0
-
- fun collect(): DocTag = nodesCache[currentDepth]!![0]
-
- override fun tail(node: Node?, depth: Int): NodeFilter.FilterResult {
- val nodeName = node!!.nodeName()
- val nodeAttributes = node.attributes()
-
- if(nodeName in listOf("#document", "html", "head"))
- return NodeFilter.FilterResult.CONTINUE
-
- val body: String
- val params: Map<String, String>
-
-
- if(nodeName != "#text") {
- body = ""
- params = nodeAttributes.map { it.key to it.value }.toMap()
- } else {
- body = nodeAttributes["#text"]
- params = emptyMap()
- }
-
- val docNode = if(depth < currentDepth) {
- DocTagsFromStringFactory.getInstance(nodeName, nodesCache.getOrDefault(currentDepth, mutableListOf()).toList(), params, body).also {
- nodesCache[currentDepth] = mutableListOf()
- currentDepth = depth
- }
- } else {
- DocTagsFromStringFactory.getInstance(nodeName, emptyList(), params, body)
- }
-
- nodesCache.getOrDefault(depth, mutableListOf()) += docNode
- return NodeFilter.FilterResult.CONTINUE
- }
-
- override fun head(node: Node?, depth: Int): NodeFilter.FilterResult {
-
- val nodeName = node!!.nodeName()
-
- if(currentDepth < depth) {
- currentDepth = depth
- nodesCache[currentDepth] = mutableListOf()
- }
-
- if(nodeName in listOf("#document", "html", "head"))
- return NodeFilter.FilterResult.CONTINUE
-
- return NodeFilter.FilterResult.CONTINUE
- }
- }
-
-
- private fun htmlToDocNode(string: String): DocTag {
- val document = Jsoup.parse(string)
- val nodeFilterImpl = NodeFilterImpl()
- NodeTraversor.filter(nodeFilterImpl, document.root())
- return nodeFilterImpl.collect()
- }
-
- private fun replaceLinksWithHrefs(javadoc: String): String = Regex("\\{@link .*?}").replace(javadoc) {
- val split = it.value.dropLast(1).split(" ")
- if(split.size !in listOf(2, 3))
- return@replace it.value
- if(split.size == 3)
- return@replace "<documentationlink href=\"${split[1]}\">${split[2]}</documentationlink>"
- else
- return@replace "<documentationlink href=\"${split[1]}\">${split[1]}</documentationlink>"
- }
-
- override fun parseStringToDocNode(extractedString: String) = htmlToDocNode(extractedString)
- override fun preparse(text: String) = replaceLinksWithHrefs(text)
-}
-
-
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
index e7a36d3f..f496d704 100644
--- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
@@ -38,6 +38,27 @@ open class MarkdownParser(
override fun preparse(text: String) = text
+ override fun parseTagWithBody(tagName: String, content: String): TagWrapper =
+ when (tagName) {
+ "see" -> {
+ val referencedName = content.substringBefore(' ')
+ See(
+ parseStringToDocNode(content.substringAfter(' ')),
+ referencedName,
+ externalDri(referencedName)
+ )
+ }
+ "throws", "exception" -> {
+ val dri = externalDri(content.substringBefore(' '))
+ Throws(
+ parseStringToDocNode(content.substringAfter(' ')),
+ dri?.fqName() ?: content.substringBefore(' '),
+ dri
+ )
+ }
+ else -> super.parseTagWithBody(tagName, content)
+ }
+
private fun headersHandler(node: ASTNode) =
DocTagsFromIElementFactory.getInstance(
node.type,
@@ -424,6 +445,12 @@ open class MarkdownParser(
DocumentationNode(emptyList())
} else {
fun parseStringToDocNode(text: String) = MarkdownParser(externalDri).parseStringToDocNode(text)
+
+ fun pointedLink(tag: KDocTag): DRI? = (parseStringToDocNode("[${tag.getSubjectName()}]")).let {
+ val link = it.children[0].children[0]
+ if (link is DocumentationLink) link.dri else null
+ }
+
DocumentationNode(
(listOf(kDocTag) + getAllKDocTags(findParent(kDocTag))).map {
when (it.knownTag) {
@@ -432,14 +459,22 @@ open class MarkdownParser(
it.name!!
)
KDocKnownTag.AUTHOR -> Author(parseStringToDocNode(it.getContent()))
- KDocKnownTag.THROWS -> Throws(
- parseStringToDocNode(it.getContent()),
- it.getSubjectName().orEmpty()
- )
- KDocKnownTag.EXCEPTION -> Throws(
- parseStringToDocNode(it.getContent()),
- it.getSubjectName().orEmpty()
- )
+ KDocKnownTag.THROWS -> {
+ val dri = pointedLink(it)
+ Throws(
+ parseStringToDocNode(it.getContent()),
+ dri?.fqName() ?: it.getSubjectName().orEmpty(),
+ dri,
+ )
+ }
+ KDocKnownTag.EXCEPTION -> {
+ val dri = pointedLink(it)
+ Throws(
+ parseStringToDocNode(it.getContent()),
+ dri?.fqName() ?: it.getSubjectName().orEmpty(),
+ dri
+ )
+ }
KDocKnownTag.PARAM -> Param(
parseStringToDocNode(it.getContent()),
it.getSubjectName().orEmpty()
@@ -449,12 +484,7 @@ open class MarkdownParser(
KDocKnownTag.SEE -> See(
parseStringToDocNode(it.getContent()),
it.getSubjectName().orEmpty(),
- (parseStringToDocNode("[${it.getSubjectName()}]"))
- .let {
- val link = it.children[0].children[0]
- if (link is DocumentationLink) link.dri
- else null
- }
+ pointedLink(it),
)
KDocKnownTag.SINCE -> Since(parseStringToDocNode(it.getContent()))
KDocKnownTag.CONSTRUCTOR -> Constructor(parseStringToDocNode(it.getContent()))
@@ -473,6 +503,9 @@ open class MarkdownParser(
}
}
+ //Horrible hack but since link resolution is passed as a function i am not able to resolve them otherwise
+ fun DRI.fqName(): String = "$packageName.$classNames"
+
private fun findParent(kDoc: PsiElement): PsiElement =
if (kDoc is KDocSection) findParent(kDoc.parent) else kDoc
diff --git a/plugins/base/src/main/kotlin/parsers/Parser.kt b/plugins/base/src/main/kotlin/parsers/Parser.kt
index 228cc88b..960d7a64 100644
--- a/plugins/base/src/main/kotlin/parsers/Parser.kt
+++ b/plugins/base/src/main/kotlin/parsers/Parser.kt
@@ -8,47 +8,44 @@ abstract class Parser {
abstract fun preparse(text: String): String
- fun parse(text: String): DocumentationNode {
-
- val list = jkdocToListOfPairs(preparse(text))
-
- val mappedList: List<TagWrapper> = list.map {
- when (it.first) {
- "description" -> Description(parseStringToDocNode(it.second))
- "author" -> Author(parseStringToDocNode(it.second))
- "version" -> Version(parseStringToDocNode(it.second))
- "since" -> Since(parseStringToDocNode(it.second))
- "see" -> See(
- parseStringToDocNode(it.second.substringAfter(' ')),
- it.second.substringBefore(' '),
- null
- )
- "param" -> Param(
- parseStringToDocNode(it.second.substringAfter(' ')),
- it.second.substringBefore(' ')
- )
- "property" -> Property(
- parseStringToDocNode(it.second.substringAfter(' ')),
- it.second.substringBefore(' ')
- )
- "return" -> Return(parseStringToDocNode(it.second))
- "constructor" -> Constructor(parseStringToDocNode(it.second))
- "receiver" -> Receiver(parseStringToDocNode(it.second))
- "throws", "exception" -> Throws(
- parseStringToDocNode(it.second.substringAfter(' ')),
- it.second.substringBefore(' ')
- )
- "deprecated" -> Deprecated(parseStringToDocNode(it.second))
- "sample" -> Sample(
- parseStringToDocNode(it.second.substringAfter(' ')),
- it.second.substringBefore(' ')
- )
- "suppress" -> Suppress(parseStringToDocNode(it.second))
- else -> CustomTagWrapper(parseStringToDocNode(it.second), it.first)
- }
+ open fun parse(text: String): DocumentationNode =
+ DocumentationNode(jkdocToListOfPairs(preparse(text)).map { (tag, content) -> parseTagWithBody(tag, content) })
+
+ open fun parseTagWithBody(tagName: String, content: String): TagWrapper =
+ when (tagName) {
+ "description" -> Description(parseStringToDocNode(content))
+ "author" -> Author(parseStringToDocNode(content))
+ "version" -> Version(parseStringToDocNode(content))
+ "since" -> Since(parseStringToDocNode(content))
+ "see" -> See(
+ parseStringToDocNode(content.substringAfter(' ')),
+ content.substringBefore(' '),
+ null
+ )
+ "param" -> Param(
+ parseStringToDocNode(content.substringAfter(' ')),
+ content.substringBefore(' ')
+ )
+ "property" -> Property(
+ parseStringToDocNode(content.substringAfter(' ')),
+ content.substringBefore(' ')
+ )
+ "return" -> Return(parseStringToDocNode(content))
+ "constructor" -> Constructor(parseStringToDocNode(content))
+ "receiver" -> Receiver(parseStringToDocNode(content))
+ "throws", "exception" -> Throws(
+ parseStringToDocNode(content.substringAfter(' ')),
+ content.substringBefore(' '),
+ null
+ )
+ "deprecated" -> Deprecated(parseStringToDocNode(content))
+ "sample" -> Sample(
+ parseStringToDocNode(content.substringAfter(' ')),
+ content.substringBefore(' ')
+ )
+ "suppress" -> Suppress(parseStringToDocNode(content))
+ else -> CustomTagWrapper(parseStringToDocNode(content), tagName)
}
- return DocumentationNode(mappedList)
- }
private fun jkdocToListOfPairs(javadoc: String): List<Pair<String, String>> =
"description $javadoc"
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
index d05979e3..a3a9ad6a 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
@@ -6,6 +6,7 @@ import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.model.toDisplaySourceSets
import org.jetbrains.dokka.pages.*
+import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
open class DocTagToContentConverter : CommentsToContentConverter {
override fun buildContent(
@@ -148,15 +149,42 @@ open class DocTagToContentConverter : CommentsToContentConverter {
)
)
is Strikethrough -> buildChildren(docTag, setOf(TextStyle.Strikethrough))
- is Table -> listOf(
- ContentTable(
- buildTableRows(docTag.children.filterIsInstance<Th>(), CommentTable),
- buildTableRows(docTag.children.filterIsInstance<Tr>(), CommentTable),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + CommentTable
- )
- )
+ is Table -> {
+ //https://html.spec.whatwg.org/multipage/tables.html#the-caption-element
+ if (docTag.children.any { it is TBody }) {
+ val head = docTag.children.filterIsInstance<THead>().flatMap { it.children }
+ val body = docTag.children.filterIsInstance<TBody>().flatMap { it.children }
+ listOf(
+ ContentTable(
+ header = buildTableRows(head.filterIsInstance<Th>(), CommentTable),
+ caption = docTag.children.firstIsInstanceOrNull<Caption>()?.let {
+ ContentGroup(
+ buildContent(it, dci, sourceSets),
+ dci,
+ sourceSets.toDisplaySourceSets(),
+ styles,
+ extra
+ )
+ },
+ buildTableRows(body.filterIsInstance<Tr>(), CommentTable),
+ dci,
+ sourceSets.toDisplaySourceSets(),
+ styles + CommentTable
+ )
+ )
+ } else {
+ listOf(
+ ContentTable(
+ header = buildTableRows(docTag.children.filterIsInstance<Th>(), CommentTable),
+ caption = null,
+ buildTableRows(docTag.children.filterIsInstance<Tr>(), CommentTable),
+ dci,
+ sourceSets.toDisplaySourceSets(),
+ styles + CommentTable
+ )
+ )
+ }
+ }
is Th,
is Tr -> listOf(
ContentGroup(
@@ -190,6 +218,15 @@ open class DocTagToContentConverter : CommentsToContentConverter {
} else {
buildChildren(docTag)
}
+ is Caption -> listOf(
+ ContentGroup(
+ buildChildren(docTag),
+ dci,
+ sourceSets.toDisplaySourceSets(),
+ styles + ContentStyle.Caption,
+ extra = extra
+ )
+ )
else -> buildChildren(docTag)
}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
index 069d1125..2c6d301c 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -62,14 +62,14 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
) {
header(2, "Sources", kind = ContentKind.Source)
+ContentTable(
- emptyList(),
- sources.map {
+ header = emptyList(),
+ children = sources.map {
buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source, extra = mainExtra + SymbolAnchorHint(it.second, ContentKind.Source)) {
link("(source)", it.second)
}
},
- DCI(node.dri, ContentKind.Source),
- node.documentable!!.sourceSets.toDisplaySourceSets(),
+ dci = DCI(node.dri, ContentKind.Source),
+ sourceSets = node.documentable!!.sourceSets.toDisplaySourceSets(),
style = emptySet(),
extra = mainExtra + SimpleAttr.header("Sources")
)
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index b2a9d5d2..e0ced0aa 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -179,10 +179,10 @@ open class DefaultPageCreator(
if (map.values.any()) {
header(2, "Inheritors") { }
+ContentTable(
- listOf(contentBuilder.contentFor(mainDRI, mainSourcesetData) {
+ header = listOf(contentBuilder.contentFor(mainDRI, mainSourcesetData) {
text("Name")
}),
- map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } }
+ children = map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } }
.groupBy({ it.second }, { it.first }).map { (classlike, platforms) ->
val label = classlike.classNames?.substringBeforeLast(".") ?: classlike.toString()
.also { logger.warn("No class name found for DRI $classlike") }
@@ -190,8 +190,8 @@ open class DefaultPageCreator(
link(label, classlike)
}
},
- DCI(setOf(dri), ContentKind.Inheritors),
- sourceSets.toDisplaySourceSets(),
+ dci = DCI(setOf(dri), ContentKind.Inheritors),
+ sourceSets = sourceSets.toDisplaySourceSets(),
style = emptySet(),
extra = mainExtra + SimpleAttr.header("Inheritors")
)
@@ -429,6 +429,30 @@ open class DefaultPageCreator(
}
}
}
+ fun DocumentableContentBuilder.contentForThrows() {
+ val throws = tags.withTypeNamed<Throws>()
+ if (throws.isNotEmpty()) {
+ header(4, "Throws")
+ sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) {
+ platforms.forEach { sourceset ->
+ table(kind = ContentKind.Main, sourceSets = setOf(sourceset)) {
+ throws.entries.mapNotNull { entry ->
+ entry.value[sourceset]?.let { throws ->
+ buildGroup(sourceSets = setOf(sourceset)) {
+ group(styles = mainStyles + ContentStyle.RowTitle) {
+ throws.exceptionAddress?.let {
+ link(text = entry.key, address = it)
+ } ?: text(entry.key)
+ }
+ comment(throws.root)
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
fun DocumentableContentBuilder.contentForSamples() {
val samples = tags.withTypeNamed<Sample>()
@@ -461,6 +485,7 @@ open class DefaultPageCreator(
contentForSamples()
contentForSeeAlso()
contentForParams()
+ contentForThrows()
}
}.children
}
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 1865f276..9fee60cb 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -154,6 +154,7 @@ open class PageContentBuilder(
) {
contents += ContentTable(
defaultHeaders,
+ null,
operation(),
DCI(mainDRI, kind),
sourceSets.toDisplaySourceSets(), styles, extra
@@ -177,8 +178,8 @@ open class PageContentBuilder(
if (renderWhenEmpty || elements.any()) {
header(level, name, kind = kind) { }
contents += ContentTable(
- headers ?: defaultHeaders,
- elements
+ header = headers ?: defaultHeaders,
+ children = elements
.let {
if (needsSorting)
it.sortedWith(compareBy(nullsLast(String.CASE_INSENSITIVE_ORDER)) { it.name })
@@ -190,8 +191,10 @@ open class PageContentBuilder(
operation(it)
}
},
- DCI(mainDRI, kind),
- sourceSets.toDisplaySourceSets(), styles, extra
+ dci = DCI(mainDRI, kind),
+ sourceSets = sourceSets.toDisplaySourceSets(),
+ style = styles,
+ extra = extra
)
}
}
diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
index fad5ff36..782f792a 100644
--- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
@@ -8,12 +8,16 @@ import com.intellij.psi.javadoc.*
import com.intellij.psi.util.PsiTreeUtil
import org.intellij.markdown.MarkdownElementTypes
import org.jetbrains.dokka.analysis.from
+import org.jetbrains.dokka.base.parsers.factories.DocTagsFromStringFactory
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.doc.Deprecated
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
+import org.jetbrains.kotlin.psi.psiUtil.siblings
+import org.jetbrains.kotlin.tools.projectWizard.core.ParsingState
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jsoup.Jsoup
@@ -36,12 +40,27 @@ class JavadocParser(
nodes.addAll(docComment.tags.mapNotNull { tag ->
when (tag.name) {
"param" -> Param(
- wrapTagIfNecessary(convertJavadocElements(tag.contentElements())),
- tag.children.firstIsInstanceOrNull<PsiDocParamRef>()?.text.orEmpty()
+ wrapTagIfNecessary(convertJavadocElements(tag.contentElementsWithSiblingIfNeeded().drop(1))),
+ tag.dataElements.firstOrNull()?.text.orEmpty()
)
- "throws" -> Throws(wrapTagIfNecessary(convertJavadocElements(tag.contentElements())), tag.text)
- "return" -> Return(wrapTagIfNecessary(convertJavadocElements(tag.contentElements())))
- "author" -> Author(wrapTagIfNecessary(convertJavadocElements(tag.authorContentElements()))) // Workaround: PSI returns first word after @author tag as a `DOC_TAG_VALUE_ELEMENT`, then the rest as a `DOC_COMMENT_DATA`, so for `Name Surname` we get them parted
+ "throws" -> {
+ val resolved = tag.resolveException()
+ val dri = resolved?.let { DRI.from(it) }
+ Throws(
+ root = wrapTagIfNecessary(convertJavadocElements(tag.dataElements.drop(1))),
+ /* we always would like to have a fully qualified name as name,
+ * because it will be used as a display name later and we would like to have those unified
+ * even if documentation states shortened version
+ *
+ * Only if dri search fails we should use the provided phrase (since then we are not able to get a fq name)
+ * */
+ name = resolved?.getKotlinFqName()?.asString()
+ ?: tag.dataElements.firstOrNull()?.text.orEmpty(),
+ exceptionAddress = dri
+ )
+ }
+ "return" -> Return(wrapTagIfNecessary(convertJavadocElements(tag.contentElementsWithSiblingIfNeeded())))
+ "author" -> Author(wrapTagIfNecessary(convertJavadocElements(tag.contentElementsWithSiblingIfNeeded()))) // Workaround: PSI returns first word after @author tag as a `DOC_TAG_VALUE_ELEMENT`, then the rest as a `DOC_COMMENT_DATA`, so for `Name Surname` we get them parted
"see" -> getSeeTagElementContent(tag).let {
See(
wrapTagIfNecessary(it.first),
@@ -49,13 +68,16 @@ class JavadocParser(
it.second
)
}
- "deprecated" -> Deprecated(wrapTagIfNecessary(convertJavadocElements(tag.dataElements.toList())))
+ "deprecated" -> Deprecated(wrapTagIfNecessary(convertJavadocElements(tag.contentElementsWithSiblingIfNeeded())))
else -> null
}
})
return DocumentationNode(nodes)
}
+ private fun PsiDocTag.resolveException(): PsiElement? =
+ dataElements.firstOrNull()?.firstChild?.referenceElementOrSelf()?.resolveToGetDri()
+
private fun wrapTagIfNecessary(list: List<DocTag>): CustomDocTag =
if (list.size == 1 && (list.first() as? CustomDocTag)?.name == MarkdownElementTypes.MARKDOWN_FILE.name)
list.first() as CustomDocTag
@@ -145,20 +167,99 @@ class JavadocParser(
}
}
+ private data class ParserState(