From 6166ddfeb6ee977a302d4cacc80dac23cc7e2baf Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 10 Apr 2020 16:59:25 +0200 Subject: Working tests for includes, sources and samples. Minor bugfixes --- .../kotlin/linkableContent/LinkableContentTest.kt | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt (limited to 'plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt') diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt new file mode 100644 index 00000000..71854035 --- /dev/null +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -0,0 +1,161 @@ +package linkableContent + +import org.jetbrains.dokka.SourceLinkDefinitionImpl +import org.jetbrains.dokka.base.transformers.pages.samples.DefaultSamplesTransformer +import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class LinkableContentTest : AbstractCoreTest() { + + @Test + fun `Include module and package documentation`() { + + val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() + val includesDir = getTestDataDir("linkable/includes").toAbsolutePath() + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + targets = listOf("js") + sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { + "$testDataDir/$it/kotlin" + } + includes = listOf("$includesDir/include2.md") + } + pass { + moduleName = "example" + analysisPlatform = "jvm" + targets = listOf("jvm") + sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + "$testDataDir/$it/kotlin" + } + includes = listOf("$includesDir/include1.md") + } + } + } + + testFromData(configuration) { + documentablesMergingStage = { + Assertions.assertEquals(2, it.documentation.size) + Assertions.assertEquals(2, it.packages.size) + Assertions.assertEquals(1, it.packages.first().documentation.size) + Assertions.assertEquals(1, it.packages.last().documentation.size) + } + } + + } + + @Test + fun `Sources multiplatform class documentation`() { + + val testDataDir = getTestDataDir("linkable/sources").toAbsolutePath() + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + targets = listOf("js") + sourceRoots = listOf("$testDataDir/jsMain/kotlin") + sourceLinks = listOf( + SourceLinkDefinitionImpl( + path = "jsMain/kotlin", + url = "https://github.com/user/repo/tree/master/src/jsMain/kotlin", + lineSuffix = "#L" + ) + ) + } + pass { + moduleName = "example" + analysisPlatform = "jvm" + targets = listOf("jvm") + sourceRoots = listOf("$testDataDir/jvmMain/kotlin") + sourceLinks = listOf( + SourceLinkDefinitionImpl( + path = "jvmMain/kotlin", + url = "https://github.com/user/repo/tree/master/src/jvmMain/kotlin", + lineSuffix = "#L" + ) + ) + } + } + } + + testFromData(configuration) { + renderingStage = { rootPageNode, dokkaContext -> + val newRoot = SourceLinksTransformer(dokkaContext).invoke(rootPageNode) + + val moduleChildren = newRoot.children + Assertions.assertEquals(1, moduleChildren.size) + val packageChildren = moduleChildren.first().children + Assertions.assertEquals(2, packageChildren.size) + packageChildren.forEach { + val name = it.name.substringBefore("Class") + val crl = it.safeAs()?.content?.safeAs()?.children?.last() + ?.safeAs()?.children?.singleOrNull().safeAs() + Assertions.assertEquals( + "https://github.com/user/repo/tree/master/src/${name.toLowerCase()}Main/kotlin/${name}Class.kt#L3", + crl?.address + ) + } + } + } + } + + @Test + fun `Samples multiplatform documentation`() { + + val testDataDir = getTestDataDir("linkable/samples").toAbsolutePath() + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + targets = listOf("js") + sourceRoots = listOf("$testDataDir/jsMain/kotlin") + samples = listOf("$testDataDir/jsMain/resources/Samples.kt") + } + pass { + moduleName = "example" + analysisPlatform = "jvm" + targets = listOf("jvm") + sourceRoots = listOf("$testDataDir/jvmMain/kotlin") + samples = listOf("$testDataDir/jvmMain/resources/Samples.kt") + } + } + } + + testFromData(configuration) { + renderingStage = { rootPageNode, dokkaContext -> + val newRoot = DefaultSamplesTransformer(dokkaContext).invoke(rootPageNode) + + val moduleChildren = newRoot.children + Assertions.assertEquals(1, moduleChildren.size) + val packageChildren = moduleChildren.first().children + Assertions.assertEquals(2, packageChildren.size) + packageChildren.forEach { + val name = it.name.substringBefore("Class") + val classChildren = it.children + Assertions.assertEquals(2, classChildren.size) + val function = classChildren.find { it.name == "printWithExclamation" } + val text = function.safeAs()?.content?.safeAs()?.children?.last() + ?.safeAs()?.children?.singleOrNull() + ?.safeAs()?.children?.singleOrNull()?.safeAs()?.children?.last() + ?.safeAs()?.children?.singleOrNull() + ?.safeAs()?.children?.singleOrNull()?.safeAs()?.text + Assertions.assertEquals( + "${name}Class().printWithExclamation(\"Hi, $name\")", + text + ) + } + } + } + } +} \ No newline at end of file -- cgit From bbfb105c1e697eb792301b9fa9d9823344734aeb Mon Sep 17 00:00:00 2001 From: Filip Zybała Date: Tue, 28 Apr 2020 14:23:23 +0200 Subject: SourceLinksTransformer: Fixed invalid cast exception, platform tags in sources table, splitted invoke function to methods. --- .../pages/sourcelinks/SourceLinksTransformer.kt | 105 +++++++++++++-------- .../kotlin/linkableContent/LinkableContentTest.kt | 15 ++- 2 files changed, 77 insertions(+), 43 deletions(-) (limited to 'plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt') 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 bf411a1f..58e52c43 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -5,6 +5,8 @@ import com.intellij.psi.PsiDocumentManager import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.DescriptorDocumentableSource +import org.jetbrains.dokka.model.DocumentableSource +import org.jetbrains.dokka.model.PsiDocumentableSource import org.jetbrains.dokka.model.WithExpectActual import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -15,52 +17,75 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs class SourceLinksTransformer(val context: DokkaContext, val builder: PageContentBuilder) : PageTransformer { + private val sourceLinks = getSourceLinks() - override fun invoke(input: RootPageNode): RootPageNode { + override fun invoke(input: RootPageNode) = + input.transformContentPagesTree { node -> + when(val documentable = node.documentable){ + is WithExpectActual -> resolveSources(documentable) + .takeIf{ it.isNotEmpty() } + ?.let { node.addSourcesContent(it) } + ?: node + else -> node + } + } - val sourceLinks = context.configuration.passesConfigurations - .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, it.platformData) } } + private fun getSourceLinks() = context.configuration.passesConfigurations + .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, it.platformData) } } - return input.transformContentPagesTree { node -> - node.documentable.safeAs()?.sources?.map?.entries?.let { entries -> - val resolvedSources = entries.mapNotNull { entry -> - sourceLinks.find { entry.value.path.contains(it.path) && it.platformData == entry.key }?.let { - Pair( - entry.key, - entry.value.cast().toLink(it) - ) - } - } - if (resolvedSources.isNotEmpty()) { - val table = builder.contentFor(node.dri.first(), node.documentable!!.platformData.toSet()) { - header(2) { text("Sources") } - +ContentTable( - emptyList(), - resolvedSources.map { - buildGroup(node.dri.first(), setOf(it.first), ContentKind.Source) { - platformDependentHint(node.dri.first(), setOf(it.first)) { - +link("(source)", it.second, ContentKind.Source, mainPlatformData, mainStyles, mainExtra) - } - } - }, - DCI(node.dri, ContentKind.Subtypes), - node.documentable!!.platformData.toSet(), - style = emptySet() - ) + private fun resolveSources(documentable: WithExpectActual) = documentable.sources.map.entries + .mapNotNull { entry -> + sourceLinks.find { entry.value.path.contains(it.path) && it.platformData == entry.key }?.let { + Pair( + entry.key, + entry.value.toLink(it) + ) + } + } + + private fun ContentPage.addSourcesContent(sources: List>) = builder + .buildSourcesContent(this, sources) + .let { + this.modified( + content = this.content.addTable(it) + ) + } + + private fun PageContentBuilder.buildSourcesContent( + node: ContentPage, + sources: List> + ) = contentFor( + node.dri.first(), + node.documentable!!.platformData.toSet() + ) { + header(2) { text("Sources") } + +ContentTable( + emptyList(), + sources.map { + buildGroup(node.dri.first(), setOf(it.first)) { + +link("(source)", it.second) } - node.modified(content = node.content.addTable(table)) - } else { - node - } - } ?: node + }, + DCI(node.dri, ContentKind.Source), + node.documentable!!.platformData.toSet(), + style = emptySet() + ) } - } - private fun DescriptorDocumentableSource.toLink(sourceLink: SourceLink): String = - sourceLink.url + - this.path.split(sourceLink.path)[1] + - sourceLink.lineSuffix + - "${this.descriptor.cast().source.getPsi()?.lineNumber() ?: 1}" + private fun DocumentableSource.toLink(sourceLink: SourceLink): String { + val lineNumber = when(this){ + is DescriptorDocumentableSource -> this.descriptor + .cast() + .source.getPsi() + ?.lineNumber() + is PsiDocumentableSource -> this.psi.lineNumber() + else -> null + } + return sourceLink.url + + this.path.split(sourceLink.path)[1] + + sourceLink.lineSuffix + + "${lineNumber ?: 1}" + } private fun ContentNode.addTable(table: ContentGroup): ContentNode = when (this) { diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 71854035..bf1d52d8 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -1,9 +1,12 @@ package linkableContent import org.jetbrains.dokka.SourceLinkDefinitionImpl +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.transformers.pages.samples.DefaultSamplesTransformer import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer +import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Assertions @@ -89,8 +92,13 @@ class LinkableContentTest : AbstractCoreTest() { testFromData(configuration) { renderingStage = { rootPageNode, dokkaContext -> - val newRoot = SourceLinksTransformer(dokkaContext).invoke(rootPageNode) - + val newRoot = SourceLinksTransformer(dokkaContext, + PageContentBuilder( + dokkaContext.single(dokkaContext.plugin().commentsToContentConverter), + dokkaContext.single(dokkaContext.plugin().signatureProvider), + dokkaContext.logger + ) + ).invoke(rootPageNode) val moduleChildren = newRoot.children Assertions.assertEquals(1, moduleChildren.size) val packageChildren = moduleChildren.first().children @@ -98,7 +106,8 @@ class LinkableContentTest : AbstractCoreTest() { packageChildren.forEach { val name = it.name.substringBefore("Class") val crl = it.safeAs()?.content?.safeAs()?.children?.last() - ?.safeAs()?.children?.singleOrNull().safeAs() + ?.safeAs()?.children?.last()?.safeAs()?.children?.singleOrNull() + ?.safeAs()?.children?.singleOrNull()?.safeAs() Assertions.assertEquals( "https://github.com/user/repo/tree/master/src/${name.toLowerCase()}Main/kotlin/${name}Class.kt#L3", crl?.address -- cgit 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 --- .idea/compiler.xml | 36 +++ core/src/main/kotlin/DokkaGenerator.kt | 36 +-- core/src/main/kotlin/configuration.kt | 6 +- core/src/main/kotlin/defaultConfiguration.kt | 2 + core/src/main/kotlin/model/Documentable.kt | 168 ++++++-------- core/src/main/kotlin/model/SourceSetData.kt | 23 ++ core/src/main/kotlin/model/aditionalExtras.kt | 4 +- core/src/main/kotlin/model/documentableUtils.kt | 15 +- core/src/main/kotlin/pages/ContentNodes.kt | 29 +-- core/src/main/kotlin/pages/PageNodes.kt | 5 +- core/src/main/kotlin/plugability/DokkaContext.kt | 14 +- .../PreMergeDocumentableTransformer.kt | 2 +- .../sources/SourceToDocumentableTranslator.kt | 4 +- plugins/base/src/main/kotlin/DokkaBase.kt | 6 +- .../src/main/kotlin/renderers/DefaultRenderer.kt | 21 +- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 58 ++--- .../main/kotlin/renderers/html/NavigationPage.kt | 4 +- .../resolvers/local/DefaultLocationProvider.kt | 9 +- .../kotlin/resolvers/local/LocationProvider.kt | 4 +- .../kotlin/signatures/KotlinSignatureProvider.kt | 35 ++- .../documentables/ActualTypealiasAdder.kt | 8 +- .../documentables/DefaultDocumentableMerger.kt | 233 ++++++++----------- .../documentables/DocumentableVisibilityFilter.kt | 55 +++-- .../InheritorsExtractorTransformer.kt | 23 +- .../ModuleAndPackageDocumentationTransformer.kt | 42 ++-- .../pages/comments/CommentsToContentConverter.kt | 3 +- .../pages/comments/DocTagToContentConverter.kt | 33 +-- .../merger/SameMethodNamePageMergerStrategy.kt | 2 +- .../pages/samples/SamplesTransformer.kt | 25 +- .../pages/sourcelinks/SourceLinksTransformer.kt | 23 +- .../DefaultDescriptorToDocumentableTranslator.kt | 252 ++++++++++----------- .../documentables/DefaultPageCreator.kt | 111 +++++---- .../documentables/PageContentBuilder.kt | 98 ++++---- .../psi/DefaultPsiToDocumentableTranslator.kt | 57 +++-- .../src/test/kotlin/expect/AbstractExpectTest.kt | 2 +- .../kotlin/linkableContent/LinkableContentTest.kt | 6 + plugins/base/src/test/kotlin/model/ClassesTest.kt | 20 +- .../base/src/test/kotlin/model/InheritorsTest.kt | 10 +- plugins/base/src/test/kotlin/model/JavaTest.kt | 4 +- plugins/base/src/test/kotlin/model/PackagesTest.kt | 4 +- .../test/kotlin/renderers/RenderingOnlyTestBase.kt | 7 +- .../renderers/html/PlatformDependentHintTest.kt | 120 ---------- .../renderers/html/SourceSetDependentHintTest.kt | 121 ++++++++++ .../annotatedFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../annotatedFunction/out/html/root/index.html | 4 +- .../annotatedFunction/out/html/root/package-list | 4 +- .../annotatedFunction/out/html/scripts/pages.js | 0 .../out/html/navigation.html | 10 +- .../out/html/root/[jvm root]/-fancy/-init-.html | 32 --- .../out/html/root/[jvm root]/-fancy/equals.html | 32 --- .../out/html/root/[jvm root]/-fancy/hash-code.html | 32 --- .../out/html/root/[jvm root]/-fancy/index.html | 102 --------- .../out/html/root/[jvm root]/-fancy/to-string.html | 32 --- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 69 ------ .../out/html/root/[main root]/-fancy/-init-.html | 32 +++ .../out/html/root/[main root]/-fancy/equals.html | 32 +++ .../html/root/[main root]/-fancy/hash-code.html | 32 +++ .../out/html/root/[main root]/-fancy/index.html | 102 +++++++++ .../html/root/[main root]/-fancy/to-string.html | 32 +++ .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 69 ++++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 10 +- .../expect/function/out/html/navigation.html | 6 +- .../function/out/html/root/[jvm root]/fn.html | 34 --- .../function/out/html/root/[jvm root]/index.html | 50 ---- .../function/out/html/root/[main root]/fn.html | 34 +++ .../function/out/html/root/[main root]/index.html | 50 ++++ .../expect/function/out/html/root/index.html | 4 +- .../expect/function/out/html/root/package-list | 4 +- .../out/html/navigation.html | 10 +- .../out/html/root/[jvm root]/-fancy/-init-.html | 32 --- .../out/html/root/[jvm root]/-fancy/equals.html | 32 --- .../out/html/root/[jvm root]/-fancy/hash-code.html | 32 --- .../out/html/root/[jvm root]/-fancy/index.html | 83 ------- .../out/html/root/[jvm root]/-fancy/to-string.html | 32 --- .../out/html/root/[jvm root]/function.html | 32 --- .../out/html/root/[jvm root]/index.html | 69 ------ .../out/html/root/[main root]/-fancy/-init-.html | 32 +++ .../out/html/root/[main root]/-fancy/equals.html | 32 +++ .../html/root/[main root]/-fancy/hash-code.html | 32 +++ .../out/html/root/[main root]/-fancy/index.html | 83 +++++++ .../html/root/[main root]/-fancy/to-string.html | 32 +++ .../out/html/root/[main root]/function.html | 32 +++ .../out/html/root/[main root]/index.html | 69 ++++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 10 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/function.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/function.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../functionWithParams/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/function.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/function.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../functionWithParams/out/html/root/index.html | 4 +- .../functionWithParams/out/html/root/package-list | 4 +- .../functionWithReceiver/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/fn.html | 40 ---- .../out/html/root/[jvm root]/index.html | 66 ------ .../out/html/root/[main root]/fn.html | 40 ++++ .../out/html/root/[main root]/index.html | 66 ++++++ .../functionWithReceiver/out/html/root/index.html | 4 +- .../out/html/root/package-list | 6 +- .../genericFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/generic.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/generic.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../genericFunction/out/html/root/index.html | 4 +- .../genericFunction/out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/generic.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/generic.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../expect/inlineFunction/out/html/navigation.html | 6 +- .../inlineFunction/out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../expect/inlineFunction/out/html/root/index.html | 4 +- .../inlineFunction/out/html/root/package-list | 4 +- .../inlineSuspendFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../inlineSuspendFunction/out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../expect/signatureTest/out/html/root/index.html | 2 +- .../out/html/root/signatureTest/index.html | 8 +- .../out/html/root/signatureTest/test.html | 2 +- .../out/html/root/signatureTest/test2.html | 2 +- .../expect/sinceKotlin/out/html/navigation.html | 6 +- .../html/root/[jvm root]/available-since1.1.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../html/root/[main root]/available-since1.1.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../expect/sinceKotlin/out/html/root/index.html | 4 +- .../expect/sinceKotlin/out/html/root/package-list | 4 +- .../suspendFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../suspendFunction/out/html/root/index.html | 4 +- .../suspendFunction/out/html/root/package-list | 4 +- .../suspendInlineFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../suspendInlineFunction/out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- plugins/gfm/src/main/kotlin/GfmPlugin.kt | 11 +- .../kotlin/converters/KotlinToJavaConverter.kt | 86 +++---- .../kotlin/signatures/JavaSignatureProvider.kt | 4 +- runners/cli/src/main/kotlin/cli/main.kt | 11 + .../dokka/gradle/ConfigurationExtractor.kt | 144 ++++++------ .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 47 ++-- .../dokka/gradle/configurationImplementations.kt | 2 + .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 4 +- .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 14 +- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 7 +- .../src/main/kotlin/testApi/context/MockContext.kt | 12 +- .../testApi/testRunner/DokkaTestGenerator.kt | 11 +- .../main/kotlin/testApi/testRunner/TestRunner.kt | 10 +- 193 files changed, 3010 insertions(+), 3003 deletions(-) create mode 100644 core/src/main/kotlin/model/SourceSetData.kt delete mode 100644 plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt create mode 100644 plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[main root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/scripts/pages.js delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/-init-.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/equals.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/hash-code.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/to-string.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/-init-.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/equals.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/hash-code.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/to-string.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[jvm root]/fn.html delete mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[main root]/fn.html create mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/-init-.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/equals.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/hash-code.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/to-string.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/-init-.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/equals.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/hash-code.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/to-string.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[jvm root]/fn.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[main root]/fn.html create mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[jvm root]/generic.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[main root]/generic.html create mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[jvm root]/generic.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[main root]/generic.html create mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[jvm root]/available-since1.1.html delete mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[main root]/available-since1.1.html create mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[main root]/index.html (limited to 'plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt') diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7ee14d19..a7e03ba2 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -16,8 +16,14 @@ + + + + + + @@ -78,14 +84,24 @@ + + + + + + + + + + @@ -101,6 +117,8 @@ + + @@ -110,6 +128,10 @@ + + + + @@ -126,6 +148,8 @@ + + @@ -150,6 +174,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 053b4cb6..6e62c033 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -1,23 +1,20 @@ package org.jetbrains.dokka -import com.intellij.openapi.vfs.VirtualFileManager -import com.intellij.psi.PsiJavaFile -import com.intellij.psi.PsiManager import org.jetbrains.dokka.analysis.AnalysisEnvironment import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.model.SourceSetCache +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.model.sourceSet import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.utilities.DokkaLogger -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.utils.PathUtil import java.io.File @@ -31,13 +28,14 @@ class DokkaGenerator( ) { fun generate() = timed { report("Setting up analysis environments") - val platforms: Map = setUpAnalysis(configuration) + val sourceSetsCache = SourceSetCache() + val sourceSets: Map = setUpAnalysis(configuration, sourceSetsCache) report("Initializing plugins") - val context = initializePlugins(configuration, logger, platforms) + val context = initializePlugins(configuration, logger, sourceSets, sourceSetsCache) report("Creating documentation models") - val modulesFromPlatforms = createDocumentationModels(platforms, context) + val modulesFromPlatforms = createDocumentationModels(sourceSets, context) report("Transforming documentation model before merging") val transformedDocumentationBeforeMerge = transformDocumentationModelBeforeMerge(modulesFromPlatforms, context) @@ -62,27 +60,31 @@ class DokkaGenerator( logger.report() }.dump("\n\n === TIME MEASUREMENT ===\n") - fun setUpAnalysis(configuration: DokkaConfiguration): Map = + fun setUpAnalysis( + configuration: DokkaConfiguration, + sourceSetsCache: SourceSetCache + ): Map = configuration.passesConfigurations.map { - it.platformData to createEnvironmentAndFacade(it) + sourceSetsCache.getSourceSet(it) to createEnvironmentAndFacade(it) }.toMap() fun initializePlugins( configuration: DokkaConfiguration, logger: DokkaLogger, - platforms: Map, + sourceSets: Map, + sourceSetsCache: SourceSetCache, pluginOverrides: List = emptyList() - ) = DokkaContext.create(configuration, logger, platforms, pluginOverrides) + ) = DokkaContext.create(configuration, logger, sourceSets, sourceSetsCache, pluginOverrides) fun createDocumentationModels( - platforms: Map, + platforms: Map, context: DokkaContext ) = platforms.flatMap { (pdata, _) -> translateSources(pdata, context) } fun transformDocumentationModelBeforeMerge( modulesFromPlatforms: List, context: DokkaContext - ) = context[CoreExtensions.preMergeDocumentableTransformer].fold(modulesFromPlatforms) { acc, t -> t(acc, context) } + ) = context[CoreExtensions.preMergeDocumentableTransformer].fold(modulesFromPlatforms) { acc, t -> t(acc) } fun mergeDocumentationModels( modulesFromPlatforms: List, @@ -119,7 +121,7 @@ class DokkaGenerator( } pass.classpath.forEach { addClasspath(File(it)) } - addSources(pass.sourceRoots.map { it.path }) + addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path }) loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion) @@ -128,7 +130,7 @@ class DokkaGenerator( EnvironmentAndFacade(environment, facade) } - private fun translateSources(platformData: PlatformData, context: DokkaContext) = + private fun translateSources(platformData: SourceSetData, context: DokkaContext) = context[CoreExtensions.sourceToDocumentableTranslator].map { it.invoke(platformData, context) } diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 34671c4e..88924924 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.pages.PlatformData import java.io.File import java.net.URL @@ -37,8 +36,10 @@ interface DokkaConfiguration { interface PassConfiguration { val moduleName: String + val sourceSetName: String val classpath: List val sourceRoots: List + val dependentSourceRoots: List val samples: List val includes: List val includeNonPublic: Boolean @@ -59,9 +60,6 @@ interface DokkaConfiguration { val analysisPlatform: Platform val targets: List val sinceKotlin: String? - - val platformData: PlatformData - get() = PlatformData(moduleName, analysisPlatform, targets) } interface SourceRoot { diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index ae674ea1..08f70b45 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -16,8 +16,10 @@ data class DokkaConfigurationImpl( data class PassConfigurationImpl ( override val moduleName: String, + override val sourceSetName: String, override val classpath: List, override val sourceRoots: List, + override val dependentSourceRoots: List, override val samples: List, override val includes: List, override val includeNonPublic: Boolean, diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 313f4cd4..85487725 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,11 +1,12 @@ package org.jetbrains.dokka.model import com.intellij.psi.PsiNamedElement +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.load.kotlin.toSourceElement @@ -13,8 +14,9 @@ abstract class Documentable { abstract val name: String? abstract val dri: DRI abstract val children: List - abstract val documentation: PlatformDependent - abstract val platformData: List + abstract val documentation: SourceSetDependent + abstract val sourceSets: List + abstract val expectPresentInSet: SourceSetData? override fun toString(): String = "${javaClass.simpleName}($dri)" @@ -25,45 +27,10 @@ abstract class Documentable { override fun hashCode() = dri.hashCode() } -data class PlatformDependent( - val map: Map, - val expect: T? = null -) : Map by map { - val prevalentValue: T? - get() = map.values.distinct().singleOrNull() - - val allValues: Sequence = sequence { - expect?.also { yield(it) } - yieldAll(map.values) - } - - val allEntries: Sequence> = sequence { - expect?.also { yield(null to it) } - map.forEach { (k, v) -> yield(k to v) } - } - - fun getOrExpect(platform: PlatformData): T? = map[platform] ?: expect - - companion object { - fun empty(): PlatformDependent = PlatformDependent(emptyMap()) - - fun from(platformData: PlatformData, element: T) = PlatformDependent(mapOf(platformData to element)) - - @Suppress("UNCHECKED_CAST") - fun from(pairs: Iterable>) = - PlatformDependent( - pairs.filter { it.first != null }.toMap() as Map, - pairs.firstOrNull { it.first == null }?.second - ) - - fun from(vararg pairs: Pair) = from(pairs.asIterable()) - - fun expectFrom(element: T) = PlatformDependent(map = emptyMap(), expect = element) - } -} +typealias SourceSetDependent = Map interface WithExpectActual { - val sources: PlatformDependent + val sources: SourceSetDependent } interface WithScope { @@ -73,7 +40,7 @@ interface WithScope { } interface WithVisibility { - val visibility: PlatformDependent + val visibility: SourceSetDependent } interface WithType { @@ -81,7 +48,7 @@ interface WithType { } interface WithAbstraction { - val modifier: PlatformDependent + val modifier: SourceSetDependent } sealed class Modifier(val name: String) @@ -112,7 +79,7 @@ interface WithGenerics { } interface WithSupertypes { - val supertypes: PlatformDependent> + val supertypes: SourceSetDependent> } interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual { @@ -124,8 +91,9 @@ sealed class DClasslike : Documentable(), WithScope, WithVisibility, WithExpectA data class DModule( override val name: String, val packages: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val dri: DRI = DRI.topLevel @@ -141,8 +109,9 @@ data class DPackage( override val properties: List, override val classlikes: List, val typealiases: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() @@ -159,14 +128,15 @@ data class DClass( override val functions: List, override val properties: List, override val classlikes: List, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val documentation: PlatformDependent, - override val modifier: PlatformDependent, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, WithExtraProperties { @@ -181,16 +151,17 @@ data class DEnum( override val dri: DRI, override val name: String, val entries: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { override val children: List @@ -202,11 +173,12 @@ data class DEnum( data class DEnumEntry( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, override val functions: List, override val properties: List, override val classlikes: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val children: List @@ -220,14 +192,15 @@ data class DFunction( override val name: String, val isConstructor: Boolean, val parameters: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val generics: List, override val receiver: DParameter?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { override val children: List @@ -239,16 +212,17 @@ data class DFunction( data class DInterface( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { override val children: List @@ -260,14 +234,15 @@ data class DInterface( data class DObject( override val name: String?, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val visibility: SourceSetDependent, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithSupertypes, WithExtraProperties { override val children: List @@ -279,15 +254,16 @@ data class DObject( data class DAnnotation( override val name: String, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties { override val children: List @@ -299,15 +275,16 @@ data class DAnnotation( data class DProperty( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val receiver: DParameter?, val setter: DFunction?, val getter: DFunction?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val generics: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties, WithGenerics { @@ -321,9 +298,10 @@ data class DProperty( data class DParameter( override val dri: DRI, override val name: String?, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val type: Bound, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -335,9 +313,10 @@ data class DParameter( data class DTypeParameter( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val bounds: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -350,10 +329,11 @@ data class DTypeAlias( override val dri: DRI, override val name: String, override val type: Bound, - val underlyingType: PlatformDependent, - override val visibility: PlatformDependent, - override val documentation: PlatformDependent, - override val platformData: List, + val underlyingType: SourceSetDependent, + override val visibility: SourceSetDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithType, WithVisibility, WithExtraProperties { override val children: List @@ -417,7 +397,7 @@ sealed class JavaVisibility(name: String) : Visibility(name) { object Default : JavaVisibility("") } -fun PlatformDependent?.orEmpty(): PlatformDependent = this ?: PlatformDependent.empty() +fun SourceSetDependent?.orEmpty(): SourceSetDependent = this ?: emptyMap() interface DocumentableSource { val path: String @@ -429,4 +409,4 @@ class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : Docu class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource { override val path = psi.containingFile.virtualFile.path -} +} \ No newline at end of file diff --git a/core/src/main/kotlin/model/SourceSetData.kt b/core/src/main/kotlin/model/SourceSetData.kt new file mode 100644 index 00000000..8f67f272 --- /dev/null +++ b/core/src/main/kotlin/model/SourceSetData.kt @@ -0,0 +1,23 @@ +package org.jetbrains.dokka.model + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.plugability.DokkaContext + +data class SourceSetData( + val moduleName: String, + val sourceSetName: String, + val platform: Platform, + val sourceRoots: List = emptyList() +) + +class SourceSetCache { + private val sourceSets = HashMap() + + fun getSourceSet(pass: DokkaConfiguration.PassConfiguration) = + sourceSets.getOrPut("${pass.moduleName}/${pass.sourceSetName}", + { SourceSetData(pass.moduleName, pass.sourceSetName, pass.analysisPlatform, pass.sourceRoots) } + ) +} + +fun DokkaContext.sourceSet(pass: DokkaConfiguration.PassConfiguration) : SourceSetData = sourceSetCache.getSourceSet(pass) \ No newline at end of file diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index 58209939..27ad8a55 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -41,13 +41,13 @@ object PrimaryConstructorExtra : ExtraProperty, ExtraProperty.Key = this } -data class ActualTypealias(val underlyingType: PlatformDependent) : ExtraProperty { +data class ActualTypealias(val underlyingType: SourceSetDependent) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor( left: ActualTypealias, right: ActualTypealias ) = - MergeStrategy.Replace(ActualTypealias(PlatformDependent(left.underlyingType + right.underlyingType))) + MergeStrategy.Replace(ActualTypealias(left.underlyingType + right.underlyingType)) } override val key: ExtraProperty.Key = ActualTypealias diff --git a/core/src/main/kotlin/model/documentableUtils.kt b/core/src/main/kotlin/model/documentableUtils.kt index 7f946344..b09260ee 100644 --- a/core/src/main/kotlin/model/documentableUtils.kt +++ b/core/src/main/kotlin/model/documentableUtils.kt @@ -1,21 +1,18 @@ package org.jetbrains.dokka.model -import org.jetbrains.dokka.pages.PlatformData +fun SourceSetDependent.filtered(platformDataList: List) = filter { it.key in platformDataList } +fun SourceSetData?.filtered(platformDataList: List) = takeIf { this in platformDataList } -fun PlatformDependent.filtered(platformDataList: List) = PlatformDependent( - map.filter { it.key in platformDataList }, - expect -) - -fun DTypeParameter.filter(filteredData: List) = - if (filteredData.containsAll(platformData)) this +fun DTypeParameter.filter(filteredData: List) = + if (filteredData.containsAll(sourceSets)) this else { - val intersection = filteredData.intersect(platformData).toList() + val intersection = filteredData.intersect(sourceSets).toList() if (intersection.isEmpty()) null else DTypeParameter( dri, name, documentation.filtered(intersection), + expectPresentInSet?.takeIf { intersection.contains(expectPresentInSet) }, bounds, intersection, extra diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt index 26bcdf77..bb669199 100644 --- a/core/src/main/kotlin/pages/ContentNodes.kt +++ b/core/src/main/kotlin/pages/ContentNodes.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.pages import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties @@ -10,7 +11,7 @@ data class DCI(val dri: Set, val kind: Kind) { interface ContentNode : WithExtraProperties { val dci: DCI - val platforms: Set + val sourceSets: Set val style: Set