File tree Expand file tree Collapse file tree 4 files changed +37
-1
lines changed
dokka-subprojects/plugin-base/src
main/kotlin/org/jetbrains/dokka/base/transformers/pages
resources/linkable/samples Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,38 @@ internal class DefaultSamplesTransformer(val context: DokkaContext) : PageTransf
58
58
return dfs(fqLink, node)
59
59
}
60
60
61
+ /* *
62
+ * If both [imports] and [body] are present, it should return
63
+ *
64
+ * ```kotlin
65
+ * import com.example.One
66
+ * import com.example.Two
67
+ *
68
+ * fun main() {
69
+ * //sampleStart
70
+ * println("Sample function body")
71
+ * println("Another line")
72
+ * //sampleEnd
73
+ * }
74
+ * ```
75
+ *
76
+ * If [imports] are empty, it should return:
77
+ *
78
+ * ```kotlin
79
+ * fun main() {
80
+ * //sampleStart
81
+ * println("Sample function body")
82
+ * println("Another line")
83
+ * //sampleEnd
84
+ * }
85
+ * ```
86
+ *
87
+ * Notice the presence/absence of the new line before the body.
88
+ */
61
89
private fun createSampleBody (imports : List <String >, body : String ) =
62
- """ |${imports.takeIf { it.isNotEmpty() }?.joinToString { " import $it \n " } ? : " " }
90
+ // takeIf {} is needed so that joinToString's postfix is not added for empty lists,
91
+ // and trimMargin() then removes the first empty line
92
+ """ |${imports.takeIf { it.isNotEmpty() }?.joinToString(separator = " \n " , postfix = " \n " ) { " import $it " } ? : " " }
63
93
|fun main() {
64
94
| //sampleStart
65
95
| $body
Original file line number Diff line number Diff line change @@ -213,6 +213,8 @@ class LinkableContentTest : BaseAbstractTest() {
213
213
assertEquals(
214
214
"""
215
215
|import p2.${name} Class
216
+ |import kotlin.collections.List
217
+ |import kotlin.collections.Map
216
218
|
217
219
|fun main() {
218
220
| //sampleStart
Original file line number Diff line number Diff line change 5
5
package samples
6
6
7
7
import p2.JsClass
8
+ import kotlin.collections.List
9
+ import kotlin.collections.Map
8
10
9
11
class SamplesJs {
10
12
Original file line number Diff line number Diff line change 5
5
package samples
6
6
7
7
import p2.JvmClass
8
+ import kotlin.collections.List
9
+ import kotlin.collections.Map
8
10
9
11
class SamplesJvm {
10
12
You can’t perform that action at this time.
0 commit comments