Skip to content

Commit 9d11031

Browse files
vmishenevIgnatBeresnev
authored andcommitted
[Javadoc] Ignore Kotlin samples (#3473)
* [Javadoc] Ignore Kotlin samples This is a laconic solution to avoid an error message (#3466) for Kotlin samples in unstable Javadoc format. There are 2 problems. 1. Javadoc's content model does not contain samples links at all. It should contain something like `samplesSectionContent` in the base plugin. 2. Sample Transformer from the base plugin knows nothing about Javadoc's content model. see `DefaultSamplesTransformer.dfs`, e.g. `JavadocContentGroup` is unavailable from the base plugin. (cherry picked from commit e502b2c)
1 parent b8ef2dd commit 9d11031

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/transformers/pages/DefaultSamplesTransformer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import org.jetbrains.dokka.analysis.kotlin.sample.SampleSnippet
1919

2020
internal const val KOTLIN_PLAYGROUND_SCRIPT = "https://unpkg.com/kotlin-playground@1/dist/playground.min.js"
2121

22+
/**
23+
* It works ONLY with a content model from the base plugin.
24+
*/
2225
internal class DefaultSamplesTransformer(val context: DokkaContext) : PageTransformer {
2326

2427
private val sampleAnalysisEnvironment: SampleAnalysisEnvironmentCreator =

dokka-subprojects/plugin-javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ public class JavadocPlugin : DokkaPlugin() {
9494
javadocPreprocessors with DeprecatedPageCreator order { before(rootCreator) }
9595
}
9696

97+
// defaultSamplesTransformer knows nothing about Javadoc's content model
98+
internal val emptySampleTransformer: Extension<PageTransformer, *, *> by extending {
99+
CoreExtensions.pageTransformer providing {
100+
PageTransformer { it }
101+
} override dokkaBasePlugin.defaultSamplesTransformer
102+
}
103+
97104
internal val alphaVersionNotifier by extending {
98105
CoreExtensions.postActions providing { ctx ->
99106
PostAction {

dokka-subprojects/plugin-javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/JavadocClasslikeTemplateMapTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
4242
}
4343
}
4444

45+
@Test
46+
fun `single class should not render Kotlin sample`() {
47+
dualTestTemplateMapInline(
48+
kotlin =
49+
"""
50+
/src/source0.kt
51+
/**
52+
* some doc
53+
* @sample [sample]
54+
*/
55+
class Test {
56+
}
57+
58+
fun sample(){
59+
val a = 0
60+
}
61+
"""
62+
) {
63+
assertEquals(0, context.logger.errorsCount)
64+
assertEquals(0, context.logger.warningsCount)
65+
val map = allPagesOfType<JavadocClasslikePageNode>().first{ it.name == "Test" }.templateMap
66+
assertEquals("Test", map["name"])
67+
assertEquals("<p>some doc</p>", map["classlikeDocumentation"])
68+
}
69+
}
70+
4571
@Test
4672
fun `single function`() {
4773
dualTestTemplateMapInline(

0 commit comments

Comments
 (0)