diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-02-27 20:08:31 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-02-27 20:08:31 +0300 |
commit | bc71b31be28ed558e022babcf40ec1fd3bff923a (patch) | |
tree | 2c6520c7286432f22f3b804c8dea9147c6d26c42 /core | |
parent | ef753c8a1b9f02d9f6f026d555d628fbb207c574 (diff) | |
download | dokka-bc71b31be28ed558e022babcf40ec1fd3bff923a.tar.gz dokka-bc71b31be28ed558e022babcf40ec1fd3bff923a.tar.bz2 dokka-bc71b31be28ed558e022babcf40ec1fd3bff923a.zip |
Platform and version requirements for packages.
Fixed tests.
Post review.
Diffstat (limited to 'core')
6 files changed, 39 insertions, 11 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index 79ebabe0..a7b696eb 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -263,6 +263,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, val packageName = if (singleNode.name.isEmpty()) "<root>" else singleNode.name appendHeader(2) { appendText("Package $packageName") } } + singleNode.appendPlatforms() appendContent(singleNode.content) } else { val breakdownByName = nodes.groupBy { node -> node.name } @@ -354,13 +355,25 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } private fun DocumentationNode.appendPlatforms() { - val platforms = platformsToShow.ifEmpty { return } + val platforms = if (isModuleOrPackage()) + platformsToShow.toSet() + platformsOfItems(members) + else + platformsToShow + + if(platforms.isEmpty()) return + appendParagraph { appendStrong { to.append("Platform and version requirements:") } to.append(" " + platforms.joinToString()) } } + protected fun platformsOfItems(items: List<DocumentationNode>): Set<String> = + items.foldRight(items.first().platformsToShow.toSet()) { + node, platforms -> + platforms.intersect(node.platformsToShow) + } + val DocumentationNode.platformsToShow: List<String> get() = platforms.let { if (it.containsAll(impliedPlatforms)) it - impliedPlatforms else it } @@ -501,10 +514,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } private fun platformsOfItems(items: List<DocumentationNode>, omitSamePlatforms: Boolean = true): Set<String> { - val platforms = items.foldRight(items.first().platformsToShow.toSet()) { - node, platforms -> - platforms.intersect(node.platformsToShow) - } + val platforms = platformsOfItems(items) if (platforms.isNotEmpty() && (platforms != node.platformsToShow.toSet() || !omitSamePlatforms)) { return platforms } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index e87811ee..d21528b5 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -284,15 +284,19 @@ class MarkdownFormatTest { } } - @Test fun multiplePlatformsPackagePlatformFromMembers() { + @Test fun multiplePlatformsPackagePlatformFromMembersIndex() { val module = buildMultiplePlatforms("multiplatform/packagePlatformsFromMembers") verifyModelOutput(module, ".md", "testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.kt") { model, output -> MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) - .createOutputBuilder(output, tempLocation).appendNodes(model.members) + .createOutputBuilder(output, tempLocation).appendNodes(listOf(model)) } } + @Test fun multiplePlatformsPackagePlatformFromMembers() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/packagePlatformsFromMembers"), "multiplatform/packagePlatformsFromMembers") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false) diff --git a/core/testdata/format/multiplatform/merge/multiplatform.package.md b/core/testdata/format/multiplatform/merge/multiplatform.package.md index a423f603..8e463327 100644 --- a/core/testdata/format/multiplatform/merge/multiplatform.package.md +++ b/core/testdata/format/multiplatform/merge/multiplatform.package.md @@ -2,6 +2,8 @@ ## Package foo +**Platform and version requirements:** JVM, JS + ### Types | [Foo](test/foo/-foo/index)<br>(JVM, JS) | `class Foo`<br>This is a foo. | diff --git a/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.md b/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.md index 0440bb1d..294513ed 100644 --- a/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.md +++ b/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.md @@ -1,8 +1,8 @@ -[test](test/index) / [foo.bar](test/foo.bar/index) +[test](test/index) -## Package foo.bar +### Packages -### Functions +| [foo.bar](test/foo.bar/index)<br>(JVM, JS) | | -| [buz](test/foo.bar/buz)<br>(JVM, JS) | `fun buz(): Unit` | +### Index diff --git a/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.package.md b/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.package.md new file mode 100644 index 00000000..2921cdd1 --- /dev/null +++ b/core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.package.md @@ -0,0 +1,10 @@ +[test](test/index) / [foo.bar](test/foo.bar/index) + +## Package foo.bar + +**Platform and version requirements:** JVM, JS + +### Functions + +| [buz](test/foo.bar/buz)<br>(JVM, JS) | `fun buz(): Unit` | + diff --git a/core/testdata/format/sinceKotlin.package.md b/core/testdata/format/sinceKotlin.package.md index 2af0c9ee..c811749c 100644 --- a/core/testdata/format/sinceKotlin.package.md +++ b/core/testdata/format/sinceKotlin.package.md @@ -2,6 +2,8 @@ ## Package <root> +**Platform and version requirements:** Kotlin 1.1 + ### Types | [Since1.1](test/-since1.1/index)<br>(Kotlin 1.1) | `class Since1.1`<br>Useful | |