aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt22
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt7
-rw-r--r--core/testdata/format/multiplatformMergeMembers/foo.md6
-rw-r--r--core/testdata/format/multiplatformOmitRedundant/foo.md22
-rw-r--r--core/testdata/format/multiplatformOmitRedundant/js.kt2
-rw-r--r--core/testdata/format/multiplatformOmitRedundant/jvm.kt11
6 files changed, 57 insertions, 13 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index de2ef3ed..3cfc96a2 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -406,15 +406,15 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
appendSection("Exceptions", node.members(NodeKind.Exception))
appendSection("Type Aliases", node.members(NodeKind.TypeAlias))
appendSection("Extensions for External Classes", node.members(NodeKind.ExternalClass))
- appendSection("Enum Values", node.members(NodeKind.EnumItem), sortMembers = false)
- appendSection("Constructors", node.members(NodeKind.Constructor))
- appendSection("Properties", node.members(NodeKind.Property))
+ appendSection("Enum Values", node.members(NodeKind.EnumItem), sortMembers = false, omitSamePlatforms = true)
+ appendSection("Constructors", node.members(NodeKind.Constructor), omitSamePlatforms = true)
+ appendSection("Properties", node.members(NodeKind.Property), omitSamePlatforms = true)
appendSection("Inherited Properties", node.inheritedMembers(NodeKind.Property))
- appendSection("Functions", node.members(NodeKind.Function))
+ appendSection("Functions", node.members(NodeKind.Function), omitSamePlatforms = true)
appendSection("Inherited Functions", node.inheritedMembers(NodeKind.Function))
- appendSection("Companion Object Properties", node.members(NodeKind.CompanionObjectProperty))
+ appendSection("Companion Object Properties", node.members(NodeKind.CompanionObjectProperty), omitSamePlatforms = true)
appendSection("Inherited Companion Object Properties", node.inheritedCompanionObjectMembers(NodeKind.Property))
- appendSection("Companion Object Functions", node.members(NodeKind.CompanionObjectFunction))
+ appendSection("Companion Object Functions", node.members(NodeKind.CompanionObjectFunction), omitSamePlatforms = true)
appendSection("Inherited Companion Object Functions", node.inheritedCompanionObjectMembers(NodeKind.Function))
appendSection("Other members", node.members.filter {
it.kind !in setOf(
@@ -453,7 +453,9 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun appendSection(caption: String, members: List<DocumentationNode>, sortMembers: Boolean = true) {
+ private fun appendSection(caption: String, members: List<DocumentationNode>,
+ sortMembers: Boolean = true,
+ omitSamePlatforms: Boolean = false) {
if (members.isEmpty()) return
appendHeader(3) { appendText(caption) }
@@ -467,7 +469,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
appendTableRow {
appendTableCell {
appendLink(memberLocation)
- appendPlatforms(members)
+ appendPlatforms(members, omitSamePlatforms)
}
appendTableCell {
val breakdownBySummary = members.groupBy { it.summary }
@@ -502,11 +504,11 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun appendPlatforms(items: List<DocumentationNode>) {
+ private fun appendPlatforms(items: List<DocumentationNode>, omitSamePlatforms: Boolean) {
val platforms = items.foldRight(items.first().platformsToShow.toSet()) {
node, platforms -> platforms.intersect(node.platformsToShow)
}
- if (platforms.isNotEmpty()) {
+ if (platforms.isNotEmpty() && (platforms != node.platformsToShow.toSet() || !omitSamePlatforms)) {
appendLine()
to.append("(${platforms.joinToString()})")
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 7c1cc8b3..fb202b81 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -265,6 +265,13 @@ class MarkdownFormatTest {
}
}
+ @Test fun multiplePlatformsOmitRedundant() {
+ val module = buildMultiplePlatforms("multiplatformOmitRedundant")
+ verifyModelOutput(module, ".md", "testdata/format/multiplatformOmitRedundant/foo.kt") { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
+ }
+ }
+
@Test fun multiplePlatformsImplied() {
val module = buildMultiplePlatforms("multiplatformImplied")
verifyModelOutput(module, ".md", "testdata/format/multiplatformImplied/foo.kt") { model, output ->
diff --git a/core/testdata/format/multiplatformMergeMembers/foo.md b/core/testdata/format/multiplatformMergeMembers/foo.md
index 3bf19fe1..7490c878 100644
--- a/core/testdata/format/multiplatformMergeMembers/foo.md
+++ b/core/testdata/format/multiplatformMergeMembers/foo.md
@@ -10,17 +10,17 @@ This is a foo.
### Constructors
-| [&lt;init&gt;](test/foo/-foo/-init-)<br>(JVM, JS) | `Foo()`<br>This is a foo. |
+| [&lt;init&gt;](test/foo/-foo/-init-) | `Foo()`<br>This is a foo. |
### Properties
| [propJs](test/foo/-foo/prop-js)<br>(JS) | `val propJs: String` |
| [propJvm](test/foo/-foo/prop-jvm)<br>(JVM) | `val propJvm: String` |
-| [propJvmAndJs](test/foo/-foo/prop-jvm-and-js)<br>(JVM, JS) | `val propJvmAndJs: Int` |
+| [propJvmAndJs](test/foo/-foo/prop-jvm-and-js) | `val propJvmAndJs: Int` |
### Functions
-| [bothJvmAndJs](test/foo/-foo/both-jvm-and-js)<br>(JVM, JS) | `fun bothJvmAndJs(): Unit` |
+| [bothJvmAndJs](test/foo/-foo/both-jvm-and-js) | `fun bothJvmAndJs(): Unit` |
| [js](test/foo/-foo/js)<br>(JS) | `fun js(): Unit` |
| [jvm](test/foo/-foo/jvm)<br>(JVM) | `fun jvm(): Unit` |
diff --git a/core/testdata/format/multiplatformOmitRedundant/foo.md b/core/testdata/format/multiplatformOmitRedundant/foo.md
new file mode 100644
index 00000000..088ced2c
--- /dev/null
+++ b/core/testdata/format/multiplatformOmitRedundant/foo.md
@@ -0,0 +1,22 @@
+[test](test/index) / [foo](test/foo/index) / [Foo](test/foo/-foo/index)
+
+# Foo
+
+`class Foo`
+
+**Platform and version requirements:** JVM
+
+This is a foo.
+
+### Constructors
+
+| [&lt;init&gt;](test/foo/-foo/-init-) | `Foo()`<br>This is a foo. |
+
+### Properties
+
+| [propJvm](test/foo/-foo/prop-jvm) | `val propJvm: String` |
+
+### Functions
+
+| [jvm](test/foo/-foo/jvm) | `fun jvm(): Unit` |
+
diff --git a/core/testdata/format/multiplatformOmitRedundant/js.kt b/core/testdata/format/multiplatformOmitRedundant/js.kt
new file mode 100644
index 00000000..d1b1429c
--- /dev/null
+++ b/core/testdata/format/multiplatformOmitRedundant/js.kt
@@ -0,0 +1,2 @@
+package foo
+
diff --git a/core/testdata/format/multiplatformOmitRedundant/jvm.kt b/core/testdata/format/multiplatformOmitRedundant/jvm.kt
new file mode 100644
index 00000000..35e3c08d
--- /dev/null
+++ b/core/testdata/format/multiplatformOmitRedundant/jvm.kt
@@ -0,0 +1,11 @@
+package foo
+
+/**
+ * This is a foo.
+ */
+class Foo {
+ fun jvm() {
+ }
+
+ val propJvm = "abc"
+}