Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Javadoc] Ignore Kotlin samples #3473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import org.jetbrains.dokka.analysis.kotlin.sample.SampleSnippet

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

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

private val sampleAnalysisEnvironment: SampleAnalysisEnvironmentCreator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public class JavadocPlugin : DokkaPlugin() {
javadocPreprocessors with DeprecatedPageCreator order { before(rootCreator) }
}

// defaultSamplesTransformer knows nothing about Javadoc's content model
internal val emptySampleTransformer: Extension<PageTransformer, *, *> by extending {
CoreExtensions.pageTransformer providing {
PageTransformer { it }
} override dokkaBasePlugin.defaultSamplesTransformer
}

internal val alphaVersionNotifier by extending {
CoreExtensions.postActions providing { ctx ->
PostAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
}
}

@Test
fun `single class should not render Kotlin sample`() {
dualTestTemplateMapInline(
kotlin =
"""
/src/source0.kt
/**
* some doc
* @sample [sample]
*/
class Test {
}

fun sample(){
val a = 0
}
"""
) {
assertEquals(0, context.logger.errorsCount)
assertEquals(0, context.logger.warningsCount)
val map = allPagesOfType<JavadocClasslikePageNode>().first{ it.name == "Test" }.templateMap
assertEquals("Test", map["name"])
assertEquals("<p>some doc</p>", map["classlikeDocumentation"])
}
}

@Test
fun `single function`() {
dualTestTemplateMapInline(
Expand Down
Loading