aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt20
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt8
-rw-r--r--core/testdata/format/multiplatform/merge/multiplatform.package.md2
-rw-r--r--core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.index.md8
-rw-r--r--core/testdata/format/multiplatform/packagePlatformsFromMembers/multiplatform.package.md10
-rw-r--r--core/testdata/format/sinceKotlin.package.md2
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 &lt;root&gt;
+**Platform and version requirements:** Kotlin 1.1
+
### Types
| [Since1.1](test/-since1.1/index)<br>(Kotlin 1.1) | `class Since1.1`<br>Useful |