diff options
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/DokkaBase.kt | 9 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt | 61 |
2 files changed, 29 insertions, 41 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index ddc06fe0..456a587b 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -4,6 +4,7 @@ package org.jetbrains.dokka.base import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.analysis.KotlinAnalysis +import org.jetbrains.dokka.analysis.ProjectKotlinAnalysis import org.jetbrains.dokka.base.renderers.* import org.jetbrains.dokka.base.renderers.html.* import org.jetbrains.dokka.base.renderers.html.command.consumers.PathToRootConsumer @@ -36,6 +37,8 @@ import org.jetbrains.dokka.base.translators.descriptors.ExternalClasslikesTransl import org.jetbrains.dokka.base.translators.descriptors.ExternalDocumentablesProvider import org.jetbrains.dokka.base.utils.NoopIntellijLoggerFactory import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.renderers.PostAction import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -189,7 +192,7 @@ class DokkaBase : DokkaPlugin() { val defaultKotlinAnalysis by extending { kotlinAnalysis providing { ctx -> - KotlinAnalysis( + ProjectKotlinAnalysis( sourceSets = ctx.configuration.sourceSets, logger = ctx.logger ) @@ -281,6 +284,10 @@ class DokkaBase : DokkaPlugin() { externalClasslikesTranslator providing ::DefaultDescriptorToDocumentableTranslator } + internal val disposeKotlinAnalysisPostAction by extending { + CoreExtensions.postActions with PostAction { this@DokkaBase.querySingle { kotlinAnalysis }.close() } + } + private companion object { init { // Suppress messages emitted by the IntelliJ logger since diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index ed4c4792..e72700e0 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -4,11 +4,7 @@ import com.intellij.psi.PsiElement import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.analysis.AnalysisEnvironment -import org.jetbrains.dokka.analysis.DokkaMessageCollector -import org.jetbrains.dokka.analysis.DokkaResolutionFacade -import org.jetbrains.dokka.analysis.EnvironmentAndFacade +import org.jetbrains.dokka.analysis.* import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.links.DRI @@ -38,51 +34,36 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { * Currently, all `ThreadLocal`s are in a compiler/IDE codebase. */ runBlocking(Dispatchers.Default) { - val analysis = setUpAnalysis(context) - - input.transformContentPagesTree { page -> - val samples = (page as? WithDocumentables)?.documentables?.flatMap { - it.documentation.entries.flatMap { entry -> - entry.value.children.filterIsInstance<Sample>().map { entry.key to it } + val analysis = SamplesKotlinAnalysis( + sourceSets = context.configuration.sourceSets, + logger = context.logger, + projectKotlinAnalysis = context.plugin<DokkaBase>().querySingle { kotlinAnalysis } + ) + analysis.use { + input.transformContentPagesTree { page -> + val samples = (page as? WithDocumentables)?.documentables?.flatMap { + it.documentation.entries.flatMap { entry -> + entry.value.children.filterIsInstance<Sample>().map { entry.key to it } + } } - } - - samples?.fold(page as ContentPage) { acc, (sampleSourceSet, sample) -> - acc.modified( - content = acc.content.addSample(page, sampleSourceSet, sample.name, analysis), - embeddedResources = acc.embeddedResources + KOTLIN_PLAYGROUND_SCRIPT - ) - } ?: page - } - } - private fun setUpAnalysis(context: DokkaContext) = context.configuration.sourceSets.associateWith { sourceSet -> - if (sourceSet.samples.isEmpty()) context.plugin<DokkaBase>() - .querySingle { kotlinAnalysis }[sourceSet] // from sourceSet.sourceRoots - else AnalysisEnvironment(DokkaMessageCollector(context.logger), sourceSet.analysisPlatform).run { - if (analysisPlatform == Platform.jvm) { - configureJdkClasspathRoots() + samples?.fold(page as ContentPage) { acc, (sampleSourceSet, sample) -> + acc.modified( + content = acc.content.addSample(page, sampleSourceSet, sample.name, it), + embeddedResources = acc.embeddedResources + KOTLIN_PLAYGROUND_SCRIPT + ) + } ?: page + } } - sourceSet.classpath.forEach(::addClasspath) - - addSources(sourceSet.samples.toList()) - - loadLanguageVersionSettings(sourceSet.languageVersion, sourceSet.apiVersion) - - val environment = createCoreEnvironment() - val (facade, _) = createResolutionFacade(environment) - EnvironmentAndFacade(environment, facade) } - } private fun ContentNode.addSample( contentPage: ContentPage, sourceSet: DokkaSourceSet, fqName: String, - analysis: Map<DokkaSourceSet, EnvironmentAndFacade> + analysis: KotlinAnalysis ): ContentNode { - val facade = analysis[sourceSet]?.facade - ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${sourceSet.sourceSetID}") } + val facade = analysis[sourceSet].facade val psiElement = fqNameToPsiElement(facade, fqName) ?: return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") } val imports = |