diff options
Diffstat (limited to 'plugins/base/src')
11 files changed, 76 insertions, 67 deletions
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<DokkaBase>().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<DocumentationNode> } -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<DokkaBase>().querySingle { kotlinAnalysis } + private val documentationFragments: SourceSetDependent<List<ModuleAndPackageDocumentationFragment>> = 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<DModule>): List<DModule> { 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<PageMergerStrategy>) : PageTransformer { +class PageMerger(context: DokkaContext) : PageTransformer { + + private val strategies: Iterable<PageMergerStrategy> = context.plugin<DokkaBase>().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<DokkaBase>().querySingle { commentsToContentConverter }, + context.plugin<DokkaBase>().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<DokkaBase>().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<DokkaBase>().querySingle { commentsToContentConverter } + private val signatureProvider = context.plugin<DokkaBase>().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<DokkaBase>().querySingle { kotlinAnalysis } + override suspend fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule { return coroutineScope { fun isFileInSourceRoots(file: File): Boolean = diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 7e8bde49..11896101 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -1,15 +1,12 @@ package linkableContent import org.jetbrains.dokka.SourceLinkDefinitionImpl -import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.transformers.pages.samples.DefaultSamplesTransformer import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.WithGenerics import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -127,14 +124,7 @@ class LinkableContentTest : AbstractCoreTest() { testFromData(configuration) { renderingStage = { rootPageNode, dokkaContext -> - val newRoot = SourceLinksTransformer( - dokkaContext, - PageContentBuilder( - dokkaContext.single(dokkaContext.plugin<DokkaBase>().commentsToContentConverter), - dokkaContext.single(dokkaContext.plugin<DokkaBase>().signatureProvider), - dokkaContext.logger - ) - ).invoke(rootPageNode) + val newRoot = SourceLinksTransformer(dokkaContext).invoke(rootPageNode) val moduleChildren = newRoot.children Assertions.assertEquals(1, moduleChildren.size) val packageChildren = moduleChildren.first().children diff --git a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt index 2aba6d67..a3069107 100644 --- a/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt +++ b/plugins/base/src/test/kotlin/transformers/ContextModuleAndPackageDocumentationReaderTest1.kt @@ -10,9 +10,11 @@ import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows import testApi.testRunner.TestDokkaConfigurationBuilder import testApi.testRunner.dModule import testApi.testRunner.dPackage +import java.lang.IllegalStateException class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAndPackageDocumentationReaderTest() { @@ -110,13 +112,11 @@ class ContextModuleAndPackageDocumentationReaderTest1 : AbstractContextModuleAnd @Test fun `assert moduleA with unknown source set`() { - val documentation = reader[ - dModule("moduleA", sourceSets = setOf(configurationBuilder.unattachedSourceSet { name = "unknown" })) - ] - assertEquals( - emptyMap<DokkaSourceSet, DocumentationNode>(), documentation, + assertThrows<IllegalStateException>( "Expected no documentation received for module with unknown sourceSet" - ) + ) { reader[ + dModule("moduleA", sourceSets = setOf(configurationBuilder.unattachedSourceSet { name = "unknown" })) + ]} } @Test |