From 29cc17ba80018e3e45a5fabcf2e370c735fd5674 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 25 Aug 2020 14:28:44 +0200 Subject: Implement ModuleAndPackageDocumentationReader --- .../ModuleAndPackageDocumentationParsingContext.kt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt (limited to 'plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt') diff --git a/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt new file mode 100644 index 00000000..f11a5d13 --- /dev/null +++ b/plugins/base/src/main/kotlin/parsers/moduleAndPackage/ModuleAndPackageDocumentationParsingContext.kt @@ -0,0 +1,36 @@ +@file:Suppress("FunctionName") + +package org.jetbrains.dokka.base.parsers.moduleAndPackage + +import org.jetbrains.dokka.analysis.DokkaResolutionFacade +import org.jetbrains.dokka.base.parsers.MarkdownParser +import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.* +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.utilities.DokkaLogger +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +internal fun interface ModuleAndPackageDocumentationParsingContext { + fun markdownParserFor(fragment: ModuleAndPackageDocumentationFragment): MarkdownParser +} + +internal fun ModuleAndPackageDocumentationParsingContext.parse( + fragment: ModuleAndPackageDocumentationFragment +): DocumentationNode { + return markdownParserFor(fragment).parse(fragment.documentation) +} + +internal fun ModuleAndPackageDocumentationParsingContext( + logger: DokkaLogger, + facade: DokkaResolutionFacade? = null, +) = ModuleAndPackageDocumentationParsingContext { fragment -> + val descriptor = when (fragment.classifier) { + Module -> facade?.moduleDescriptor?.getPackage(FqName.topLevel(Name.identifier(""))) + Package -> facade?.moduleDescriptor?.getPackage(FqName(fragment.name)) + } + MarkdownParser( + resolutionFacade = facade, + declarationDescriptor = descriptor, + logger = logger + ) +} -- cgit