From 3f2a790190da4f40ea6d8a976aa1929b2a1b002b Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 May 2020 17:45:12 +0200 Subject: Changing approach from platform-driven to source-set-driven --- .../renderers/html/SourceSetDependentHintTest.kt | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt (limited to 'plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt') diff --git a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt new file mode 100644 index 00000000..f774a09b --- /dev/null +++ b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt @@ -0,0 +1,121 @@ +package renderers.html + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.SourceRootImpl +import org.jetbrains.dokka.base.renderers.html.HtmlRenderer +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.pages.TextStyle +import org.junit.jupiter.api.Test +import renderers.Div +import renderers.RenderingOnlyTestBase +import renderers.TestPage +import renderers.match + +class SourceSetDependentHintTest : RenderingOnlyTestBase() { + private val pl1 = SourceSetData("root", "pl1", Platform.js, listOf(SourceRootImpl("pl1"))) + private val pl2 = SourceSetData("root","pl2", Platform.jvm, listOf(SourceRootImpl("pl1"))) + private val pl3 = SourceSetData("root","pl3", Platform.native, listOf(SourceRootImpl("pl1"))) + + @Test + fun platformIndependentCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a") + text("b") + text("c") + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div("abc")))) + } + + @Test + fun completelyDivergentCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl2)) + text("c", sourceSets = setOf(pl3)) + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div("a")), Div(Div("b")), Div(Div("c")))) + } + + @Test + fun overlappingCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl1, pl2)) + text("c", sourceSets = setOf(pl2)) + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div("ab")), Div(Div("bc")))) + } + + @Test + fun caseThatCanBeSimplified() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl2)) + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div("ab")))) + } + + @Test + fun caseWithGroupBreakingSimplification() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + group(styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + } + text("b", sourceSets = setOf(pl2)) + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div(Div("ab"))), Div(Div(Div("a"), "b")))) + } + + @Test + fun caseWithGroupNotBreakingSimplification() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2)) { + group { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + } + text("b", sourceSets = setOf(pl2)) + } + } + + HtmlRenderer(context).render(page) + println(renderedContent) + renderedContent.match(Div(Div("ab"))) + } + + @Test + fun partiallyUnifiedCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("a", sourceSets = setOf(pl2)) + text("b", sourceSets = setOf(pl3)) + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div(Div("a")), Div(Div("b")))) + } +} \ No newline at end of file -- cgit From 5f9299b074355e3f636da6eb6e1f9283f06ab8c7 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 21 May 2020 14:51:55 +0200 Subject: Return types links in inner classes with generic parents --- .../DefaultDescriptorToDocumentableTranslator.kt | 15 ++++++-- plugins/base/src/test/kotlin/basic/DRITest.kt | 40 +++++++++++++++++++- .../kotlin/linkableContent/LinkableContentTest.kt | 43 +++++++++++++++++++++- plugins/base/src/test/kotlin/markdown/LinkTest.kt | 7 ++-- .../test/kotlin/renderers/RenderingOnlyTestBase.kt | 17 --------- .../renderers/html/SourceSetDependentHintTest.kt | 1 - 6 files changed, 97 insertions(+), 26 deletions(-) (limited to 'plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt') diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 65b83200..60182ba9 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -101,8 +101,7 @@ private class DokkaDescriptorVisitor( descriptor: PackageFragmentDescriptor, parent: DRIWithPlatformInfo ): DPackage { - val name = descriptor.fqName.asString().takeUnless { it.isBlank() } ?: - "[${sourceSet.sourceSetName} root]"// TODO: error-prone, find a better way to do it + val name = descriptor.fqName.asString().takeUnless { it.isBlank() } ?: fallbackPackageName() val driWithPlatform = DRI(packageName = name).withEmptyInfo() val scope = descriptor.getMemberScope() @@ -544,7 +543,7 @@ private class DokkaDescriptorVisitor( is DynamicType -> Dynamic else -> when (val ctor = constructor.declarationDescriptor) { is TypeParameterDescriptor -> OtherParameter( - declarationDRI = DRI.from(ctor.containingDeclaration), + declarationDRI = DRI.from(ctor.containingDeclaration).withPackageFallbackTo(fallbackPackageName()), name = ctor.name.asString() ) else -> TypeConstructor( @@ -694,4 +693,14 @@ private class DokkaDescriptorVisitor( private fun ConstantsEnumValue.fullEnumEntryName() = "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" + + private fun fallbackPackageName(): String = "[${sourceSet.sourceSetName} root]"// TODO: error-prone, find a better way to do it +} + +private fun DRI.withPackageFallbackTo(fallbackPackage: String): DRI { + return if(packageName.isNullOrBlank()){ + copy(packageName = fallbackPackage) + } else { + this + } } diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt index 1ac05177..b09932fe 100644 --- a/plugins/base/src/test/kotlin/basic/DRITest.kt +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.links.* import org.jetbrains.dokka.model.DClass import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.DParameter +import org.jetbrains.dokka.model.OtherParameter import org.jetbrains.dokka.pages.* import org.junit.jupiter.api.Assertions.assertEquals import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest @@ -212,7 +213,7 @@ class DRITest : AbstractCoreTest() { |package example | |class Sample(first: S){ - | fun genericFun(param1: String): Triple = TODO() + | fun genericFun(param1: String): Tuple = TODO() |} | | @@ -238,6 +239,43 @@ class DRITest : AbstractCoreTest() { } } + @Test + fun driForFunctionNestedInsideInnerClass() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + classpath = listOfNotNull(jvmStdlibPath) + } + } + } + testInline( + """ + |/src/main/kotlin/Test.kt + |package example + | + |class Sample(first: S){ + | inner class SampleInner { + | fun foo(): S = TODO() + | } + |} + | + | + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { module -> + val sampleClass = module.dfs { it.name == "Sample" } as ClasslikePageNode + val sampleInner = sampleClass.children.first { it.name == "SampleInner" } as ClasslikePageNode + val foo = sampleInner.children.first { it.name == "foo" } as MemberPageNode + val documentable = foo.documentable as DFunction + + assertEquals(sampleClass.dri.first().toString(), (documentable.type as OtherParameter).declarationDRI.toString()) + assertEquals(0, documentable.generics.size) + } + } + } + @Test fun driForGenericExtensionFunction(){ val configuration = dokkaConfiguration { diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index c34fa909..33d3f64c 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -11,7 +11,6 @@ import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import java.nio.file.Paths @@ -182,4 +181,46 @@ class LinkableContentTest : AbstractCoreTest() { } } } + + @Test + fun `Documenting return type for a function in inner class with generic parent`(){ + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |class Sample(first: S){ + | inner class SampleInner { + | fun foo(): S = TODO() + | } + |} + | + """.trimIndent(), + dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + targets = listOf("jvm") + } + } + } + ) { + renderingStage = { module, _ -> + val sample = module.children.single { it.name == "test" } + .children.single { it.name == "Sample" }.cast() + val foo = sample + .children.single { it.name == "SampleInner" }.cast() + .children.single { it.name == "foo" }.cast() + + val returnTypeNode = foo.content.dfs { + val link = it.safeAs()?.children + val child = link?.first().safeAs() + child?.text == "S" + }?.safeAs() + + Assertions.assertEquals(sample.dri.first(), returnTypeNode?.address) + } + } + } } \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/markdown/LinkTest.kt b/plugins/base/src/test/kotlin/markdown/LinkTest.kt index bf234b6b..fe5b573a 100644 --- a/plugins/base/src/test/kotlin/markdown/LinkTest.kt +++ b/plugins/base/src/test/kotlin/markdown/LinkTest.kt @@ -51,14 +51,14 @@ class LinkTest : AbstractCoreTest() { val configuration = dokkaConfiguration { passes { pass { - sourceRoots = listOf("src/main/kotlin/parser") + sourceRoots = listOf("src/main/kotlin") } } } + //This does not contain a package to check for situation when the package has to be artificially generated testInline( """ |/src/main/kotlin/parser/Test.kt - |package parser | |class Outer { | inner class Inner { @@ -73,7 +73,8 @@ class LinkTest : AbstractCoreTest() { val innerClass = root.children.first { it is ClasslikePageNode } val foo = innerClass.children.first { it.name == "foo" } as MemberPageNode - assertNotNull(foo.content.dfs { it is ContentDRILink && it.address.toString() == "parser/Outer///PointingToDeclaration/" } ) + assertEquals(root.dri.first().toString(), "[main root]/Outer///PointingToDeclaration/") + assertNotNull(foo.content.dfs { it is ContentDRILink && it.address.toString() == root.dri.first().toString() } ) } } } diff --git a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt index dd4d1ee0..08d4a7b6 100644 --- a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt @@ -112,21 +112,4 @@ internal object EmptyCommentConverter : CommentsToContentConverter { styles: Set