diff options
author | Filip Zybała <fzybala@virtuslab.com> | 2020-04-02 12:54:19 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-04-06 14:23:54 +0200 |
commit | 69b8591126833cf1437611972c7407702a1c986a (patch) | |
tree | f23f92230747ddb27bcc08a812383678a7ba8e9b | |
parent | 2b921897aa90216d78e05165d5ce122814ead74c (diff) | |
download | dokka-69b8591126833cf1437611972c7407702a1c986a.tar.gz dokka-69b8591126833cf1437611972c7407702a1c986a.tar.bz2 dokka-69b8591126833cf1437611972c7407702a1c986a.zip |
Modified MarkdownParser to fit new See structure. Fixed minor errors in tests.
4 files changed, 329 insertions, 4 deletions
diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index 782a6504..b567bbe7 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -366,7 +366,8 @@ class MarkdownParser( it.getSubjectName().orEmpty(), parseStringToDocNode("[${it.getSubjectName()}]") .let { - if(it is DocumentationLink) it.dri + val link = it.children[0] + if(link is DocumentationLink) link.dri else null } ) diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index e8cdb2cf..67284b22 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -16,7 +16,7 @@ import kotlin.reflect.full.isSubclassOf private typealias GroupedTags = Map<KClass<out TagWrapper>, List<Pair<PlatformData?, TagWrapper>>> private val specialTags: Set<KClass<out TagWrapper>> = - setOf(Property::class, Description::class, Constructor::class, Receiver::class, Param::class) + setOf(Property::class, Description::class, Constructor::class, Receiver::class, Param::class, See::class) open class DefaultPageCreator( @@ -253,7 +253,7 @@ open class DefaultPageCreator( platforms.flatMap { platform -> seeAlsoTags.mapNotNull { (_, see) -> see.getOrExpect(platform)?.let { - buildGroup { + buildGroup(platformData = setOf(platform)) { if (it.address != null) link(it.name, it.address!!) else text(it.name) comment(it.root) diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt index 0e446e51..2698fd0a 100644 --- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt @@ -35,7 +35,7 @@ class JavadocParser( "throws" -> Throws(P(convertJavadocElements(tag.dataElements.toList())), tag.text) "return" -> Return(P(convertJavadocElements(tag.dataElements.toList()))) "author" -> Author(P(convertJavadocElements(tag.dataElements.toList()))) - "see" -> See(P(getSeeTagElementContent(tag)), tag.referenceElement()?.text.orEmpty()) + "see" -> See(P(getSeeTagElementContent(tag)), tag.referenceElement()?.text.orEmpty(), null) "deprecated" -> Deprecated(P(convertJavadocElements(tag.dataElements.toList()))) else -> null } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt new file mode 100644 index 00000000..ae53a848 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -0,0 +1,324 @@ +package content.seealso +import matchers.content.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import utils.pWrapped +import utils.signature +import utils.unnamedTag + +class ContentForSeeAlsoTest : AbstractCoreTest() { + private val testConfiguration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + targets = listOf("jvm") + } + } + } + + @Test + fun `undocumented function`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + } + } + } + } + + @Test + fun `undocumented seealso`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"abc" } + group { } + } + } + } + } + } + } + } + + @Test + fun `documented seealso`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc Comment to abc + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"abc" } + group { +"Comment to abc" } + } + } + } + } + } + } + } + + @Test + fun `undocumented seealso with stdlib link`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see Collection + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "kotlin.collections/Collection////" + link{ +"Collection"} + group { } + } + } + } + } + } + } + } + + @Test + fun `documented seealso with stdlib link`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see Collection Comment to stdliblink + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"Collection" } + group { +"Comment to stdliblink" } + } + } + } + } + } + } + } + + @Test + fun `documented seealso with stdlib link with other tags`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * random comment + | * @see Collection Comment to stdliblink + | * @author pikinier20 + | * @since 0.11 + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + pWrapped("random comment") + unnamedTag("Author") { +"pikinier20" } + unnamedTag("Since") { +"0.11" } + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"Collection" } + group { +"Comment to stdliblink" } + } + } + } + } + } + } + } + + @Test + fun `documented multiple see also`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc Comment to abc1 + | * @see abc Comment to abc2 + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"abc" } + group { +"Comment to abc2" } + } + } + } + } + } + } + } + + @Test + fun `documented multiple see also mixed source`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | /** + | * @see abc Comment to abc1 + | * @see[Collection] Comment to collection + | */ + |fun function(abc: String) { + | println(abc) + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + signature("function", null, "abc" to "String") + } + header(3) { +"Description" } + platformHinted { + header(4) { +"See also" } + table { + group { + //DRI should be "test//abc/#/-1/" + link{ +"abc" } + group { +"Comment to abc1" } + } + group { + //DRI should be "test//abc/#/-1/" + link{ +"Collection" } + group { +"Comment to collection" } + } + } + } + } + } + } + } +}
\ No newline at end of file |