From be80016c77e9b98a75d8e832dd5723737f0e1d72 Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Sun, 18 Oct 2020 23:04:26 +0200 Subject: Cleaning querying from plugins where possible --- plugins/base/src/main/kotlin/DokkaBase.kt | 40 ++++------------------ .../kotlin/signatures/KotlinSignatureProvider.kt | 12 +++++-- .../ModuleAndPackageDocumentationReader.kt | 13 ++++--- .../ModuleAndPackageDocumentationTransformer.kt | 3 ++ .../kotlin/transformers/pages/merger/PageMerger.kt | 10 +++++- .../pages/sourcelinks/SourceLinksTransformer.kt | 11 +++++- .../DefaultDescriptorToDocumentableTranslator.kt | 8 ++++- .../DefaultDocumentableToPageTranslator.kt | 15 ++++---- .../psi/DefaultPsiToDocumentableTranslator.kt | 7 +++- 9 files changed, 69 insertions(+), 50 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index c7e05e8f..a5d45282 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -24,7 +24,6 @@ import org.jetbrains.dokka.base.transformers.pages.samples.DefaultSamplesTransfo import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer import org.jetbrains.dokka.base.translators.descriptors.DefaultDescriptorToDocumentableTranslator import org.jetbrains.dokka.base.translators.documentables.DefaultDocumentableToPageTranslator -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -42,15 +41,11 @@ class DokkaBase : DokkaPlugin() { val descriptorToDocumentableTranslator by extending { - CoreExtensions.sourceToDocumentableTranslator providing { ctx -> - DefaultDescriptorToDocumentableTranslator(ctx.single(kotlinAnalysis)) - } + CoreExtensions.sourceToDocumentableTranslator providing ::DefaultDescriptorToDocumentableTranslator } val psiToDocumentableTranslator by extending { - CoreExtensions.sourceToDocumentableTranslator providing { ctx -> - DefaultPsiToDocumentableTranslator(ctx.single(kotlinAnalysis)) - } + CoreExtensions.sourceToDocumentableTranslator providing ::DefaultPsiToDocumentableTranslator } val documentableMerger by extending { @@ -80,17 +75,11 @@ class DokkaBase : DokkaPlugin() { } val modulesAndPackagesDocumentation by extending { - CoreExtensions.preMergeDocumentableTransformer providing { ctx -> - ModuleAndPackageDocumentationTransformer( - ModuleAndPackageDocumentationReader(ctx, ctx.single(kotlinAnalysis)) - ) - } + CoreExtensions.preMergeDocumentableTransformer providing ::ModuleAndPackageDocumentationTransformer } val kotlinSignatureProvider by extending { - signatureProvider providing { ctx -> - KotlinSignatureProvider(ctx.single(commentsToContentConverter), ctx.logger) - } + signatureProvider providing ::KotlinSignatureProvider } val sinceKotlinTransformer by extending { @@ -111,13 +100,7 @@ class DokkaBase : DokkaPlugin() { } val documentableToPageTranslator by extending { - CoreExtensions.documentableToPageTranslator providing { ctx -> - DefaultDocumentableToPageTranslator( - ctx.single(commentsToContentConverter), - ctx.single(signatureProvider), - ctx.logger - ) - } + CoreExtensions.documentableToPageTranslator providing ::DefaultDocumentableToPageTranslator } val docTagToContentConverter by extending { @@ -125,7 +108,7 @@ class DokkaBase : DokkaPlugin() { } val pageMerger by extending { - CoreExtensions.pageTransformer providing { ctx -> PageMerger(ctx[pageMergerStrategy]) } + CoreExtensions.pageTransformer providing ::PageMerger } val sourceSetMerger by extending { @@ -182,16 +165,7 @@ class DokkaBase : DokkaPlugin() { } val sourceLinksTransformer by extending { - htmlPreprocessors providing { - SourceLinksTransformer( - it, - PageContentBuilder( - it.single(commentsToContentConverter), - it.single(signatureProvider), - it.logger - ) - ) - } order { after(rootCreator) } + htmlPreprocessors providing ::SourceLinksTransformer order { after(rootCreator) } } val navigationPageInstaller by extending { diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 6273e789..7f29e032 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.signatures import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.dri import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.driOrNull import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter @@ -14,11 +15,18 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.TextStyle +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.utilities.DokkaLogger import kotlin.text.Typography.nbsp -class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, - JvmSignatureUtils by KotlinSignatureUtils { +class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) + : SignatureProvider, JvmSignatureUtils by KotlinSignatureUtils { + constructor(context: DokkaContext) : this( + context.plugin().querySingle { commentsToContentConverter }, + context.logger + ) private val contentBuilder = PageContentBuilder(ctcc, this, logger) private val ignoredVisibilities = setOf(JavaVisibility.Public, KotlinVisibility.Public) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt index 6e26377e..b74242c3 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationReader.kt @@ -4,6 +4,7 @@ package org.jetbrains.dokka.base.transformers.documentables import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.analysis.KotlinAnalysis +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationFragment import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationParsingContext @@ -15,6 +16,8 @@ import org.jetbrains.dokka.model.SourceSetDependent import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.doc.Deprecated import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.utilities.associateWithNotNull internal interface ModuleAndPackageDocumentationReader { @@ -22,15 +25,15 @@ internal interface ModuleAndPackageDocumentationReader { operator fun get(pkg: DPackage): SourceSetDependent } -internal fun ModuleAndPackageDocumentationReader( - context: DokkaContext, kotlinAnalysis: KotlinAnalysis? = null -): ModuleAndPackageDocumentationReader = ContextModuleAndPackageDocumentationReader(context, kotlinAnalysis) +internal fun ModuleAndPackageDocumentationReader(context: DokkaContext): ModuleAndPackageDocumentationReader = + ContextModuleAndPackageDocumentationReader(context) private class ContextModuleAndPackageDocumentationReader( - private val context: DokkaContext, - private val kotlinAnalysis: KotlinAnalysis? + private val context: DokkaContext ) : ModuleAndPackageDocumentationReader { + private val kotlinAnalysis: KotlinAnalysis = context.plugin().querySingle { kotlinAnalysis } + private val documentationFragments: SourceSetDependent> = context.configuration.sourceSets.associateWith { sourceSet -> sourceSet.includes.flatMap { include -> parseModuleAndPackageDocumentationFragments(include) } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt index 2b2a3f03..99fba9f7 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt @@ -4,12 +4,15 @@ import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.model.SourceSetDependent import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer internal class ModuleAndPackageDocumentationTransformer( private val moduleAndPackageDocumentationReader: ModuleAndPackageDocumentationReader ) : PreMergeDocumentableTransformer { + constructor(context: DokkaContext) : this(ModuleAndPackageDocumentationReader(context)) + override fun invoke(modules: List): List { return modules.map { module -> module.copy( diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt index 4faf3ad4..c1f1a7f5 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt @@ -1,10 +1,18 @@ package org.jetbrains.dokka.base.transformers.pages.merger +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.pages.RootPageNode +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.query +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.pages.PageTransformer -class PageMerger(private val strategies: Iterable) : PageTransformer { +class PageMerger(context: DokkaContext) : PageTransformer { + + private val strategies: Iterable = context.plugin().query { pageMergerStrategy } + override fun invoke(input: RootPageNode): RootPageNode = input.modified(children = input.children.map { it.mergeChildren(emptyList()) }) diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt index 2c6d301c..4f2d23c7 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -8,18 +8,27 @@ import org.jetbrains.dokka.model.DocumentableSource import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.analysis.DescriptorDocumentableSource import org.jetbrains.dokka.analysis.PsiDocumentableSource +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.model.WithSources import org.jetbrains.dokka.model.toDisplaySourceSets import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.pages.PageTransformer import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.utils.addToStdlib.cast import java.io.File -class SourceLinksTransformer(val context: DokkaContext, val builder: PageContentBuilder) : PageTransformer { +class SourceLinksTransformer(val context: DokkaContext) : PageTransformer { + + private val builder : PageContentBuilder = PageContentBuilder( + context.plugin().querySingle { commentsToContentConverter }, + context.plugin().querySingle { signatureProvider }, + context.logger + ) override fun invoke(input: RootPageNode) = input.transformContentPagesTree { node -> diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 8db3aa43..f388ee44 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -7,6 +7,7 @@ import org.jetbrains.dokka.analysis.DescriptorDocumentableSource import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.analysis.KotlinAnalysis import org.jetbrains.dokka.analysis.from +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.parsers.MarkdownParser import org.jetbrains.dokka.base.translators.isDirectlyAnException import org.jetbrains.dokka.links.* @@ -17,6 +18,9 @@ import org.jetbrains.dokka.model.TypeConstructor import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.query +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor @@ -60,9 +64,11 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue as ConstantsEnumValue import org.jetbrains.kotlin.resolve.constants.KClassValue as ConstantsKtClassValue class DefaultDescriptorToDocumentableTranslator( - private val kotlinAnalysis: KotlinAnalysis + context: DokkaContext ) : SourceToDocumentableTranslator { + private val kotlinAnalysis: KotlinAnalysis = context.plugin().querySingle { kotlinAnalysis } + override suspend fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule { val (environment, facade) = kotlinAnalysis[sourceSet] val packageFragments = environment.getSourceFiles().asSequence() diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt index 04251947..2aa3e2dc 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt @@ -1,17 +1,20 @@ package org.jetbrains.dokka.base.translators.documentables -import org.jetbrains.dokka.base.signatures.SignatureProvider -import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.ModulePageNode +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator -import org.jetbrains.dokka.utilities.DokkaLogger class DefaultDocumentableToPageTranslator( - private val commentsToContentConverter: CommentsToContentConverter, - private val signatureProvider: SignatureProvider, - private val logger: DokkaLogger + context: DokkaContext ) : DocumentableToPageTranslator { + private val commentsToContentConverter = context.plugin().querySingle { commentsToContentConverter } + private val signatureProvider = context.plugin().querySingle { signatureProvider } + private val logger = context.logger + override fun invoke(module: DModule): ModulePageNode = DefaultPageCreator(commentsToContentConverter, signatureProvider, logger).pageForModule(module) } \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index f46f11c9..00fab531 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -13,6 +13,7 @@ import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.analysis.KotlinAnalysis import org.jetbrains.dokka.analysis.PsiDocumentableSource import org.jetbrains.dokka.analysis.from +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.translators.isDirectlyAnException import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.nextTarget @@ -22,6 +23,8 @@ import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.doc.Param import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.dokka.utilities.parallelForEach @@ -46,9 +49,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File class DefaultPsiToDocumentableTranslator( - private val kotlinAnalysis: KotlinAnalysis + context: DokkaContext ) : SourceToDocumentableTranslator { + private val kotlinAnalysis: KotlinAnalysis = context.plugin().querySingle { kotlinAnalysis } + override suspend fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule { return coroutineScope { fun isFileInSourceRoots(file: File): Boolean = -- cgit