From 2fd8e9096706545f8b77e1e66bcc876d7e29f82c Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Tue, 8 Aug 2023 17:15:51 +0300 Subject: Fix and refactor Sample Transformer (#3102) --- .../internal/InternalKotlinAnalysisPlugin.kt | 2 ++ .../analysis/kotlin/internal/SampleProvider.kt | 30 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider.kt (limited to 'subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka') diff --git a/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/InternalKotlinAnalysisPlugin.kt b/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/InternalKotlinAnalysisPlugin.kt index 330522f3..30c2c2f8 100644 --- a/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/InternalKotlinAnalysisPlugin.kt +++ b/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/InternalKotlinAnalysisPlugin.kt @@ -26,6 +26,8 @@ class InternalKotlinAnalysisPlugin : DokkaPlugin() { val documentableSourceLanguageParser by extensionPoint() + val sampleProviderFactory by extensionPoint() + @OptIn(DokkaPluginApiPreview::class) override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement = PluginApiPreviewAcknowledgement } diff --git a/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider.kt b/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider.kt new file mode 100644 index 00000000..195f3c35 --- /dev/null +++ b/subprojects/analysis-kotlin-api/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka.analysis.kotlin.internal + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.InternalDokkaApi + +@InternalDokkaApi +interface SampleProviderFactory { + /** + * [SampleProvider] is a short-lived closeable instance. + * It assumes that [SampleProvider] scope of use is not big. + * Otherwise, it can lead to high memory consumption / leaks during Dokka running. + */ + fun build(): SampleProvider +} + +/** + * It is closeable. + * Otherwise, there is a chance of high memory consumption / leak. + * In general case, it creates a separate project to analysis samples directories. + */ +@InternalDokkaApi +interface SampleProvider: AutoCloseable { + class SampleSnippet(val imports: String, val body:String) + + + /** + * @return [SampleSnippet] or null if it has not found by [fqLink] + */ + fun getSample(sourceSet: DokkaConfiguration.DokkaSourceSet, fqLink: String): SampleSnippet? +} \ No newline at end of file -- cgit