diff options
Diffstat (limited to 'core/src/main/kotlin')
8 files changed, 8 insertions, 83 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt index 2d705c1b..0f88b492 100644 --- a/core/src/main/kotlin/CoreExtensions.kt +++ b/core/src/main/kotlin/CoreExtensions.kt @@ -9,7 +9,6 @@ import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentationTra import org.jetbrains.dokka.transformers.documentation.DocumentableMerger import org.jetbrains.dokka.transformers.documentation.DocumentationNodeTransformer import org.jetbrains.dokka.transformers.documentation.DocumentablesToPageTranslator -import org.jetbrains.dokka.transformers.pages.PageMergerStrategy import org.jetbrains.dokka.transformers.pages.PageNodeTransformer import org.jetbrains.dokka.transformers.psi.PsiToDocumentationTranslator import kotlin.reflect.KProperty @@ -31,7 +30,6 @@ object CoreExtensions { val commentsToContentConverter by coreExtension<CommentsToContentConverter>() val locationProviderFactory by coreExtension<LocationProviderFactory>() val outputWriter by coreExtension<OutputWriter>() - val pageMergerStrategy by coreExtension<PageMergerStrategy>() private fun <T: Any> coreExtension() = object { operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy<ExtensionPoint<T>> = diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt index 828d1bf1..1a367d30 100644 --- a/core/src/main/kotlin/plugability/DefaultExtensions.kt +++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt @@ -5,8 +5,6 @@ import org.jetbrains.dokka.pages.DocTagToContentConverter import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.OutputWriter import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory -import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy -import org.jetbrains.dokka.transformers.pages.DefaultPageNodeMerger internal object DefaultExtensions { @@ -18,10 +16,8 @@ internal object DefaultExtensions { internal fun <T : Any, E : ExtensionPoint<T>> get(point: E, fullContext: DokkaContext): List<T> = when (point) { CoreExtensions.commentsToContentConverter -> converter.get(fullContext) - CoreExtensions.pageTransformer -> DefaultPageNodeMerger(fullContext) CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext) CoreExtensions.outputWriter -> outputWriter.get(fullContext) - CoreExtensions.pageMergerStrategy -> DefaultPageMergerStrategy(fullContext.logger) else -> null }.let { listOfNotNull( it ) as List<T> } }
\ No newline at end of file diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index b4be5862..bcf6e1e0 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -43,6 +43,9 @@ interface DokkaContext { } } +inline fun <reified T: DokkaPlugin> DokkaContext.plugin(): T = plugin(T::class) + ?: throw java.lang.IllegalStateException("Plugin ${T::class.qualifiedName} is not present in context.") + interface DokkaContextConfiguration { fun addExtensionDependencies(extension: Extension<*>) } diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index cdc92ca5..c00b0af3 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -48,4 +48,8 @@ abstract class DokkaPlugin { .map { it.get(this) } .forEach { if (it.condition.invoke(configuration)) ctx.addExtensionDependencies(it) } } -}
\ No newline at end of file +} + +inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> = + context?.let { it[extension()] } + ?: throw IllegalStateException("Querying about plugins is only possible with dokka context initialised")
\ No newline at end of file diff --git a/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt deleted file mode 100644 index 66562d8b..00000000 --- a/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.jetbrains.dokka.transformers.pages - -import org.jetbrains.dokka.pages.PageNode -import org.jetbrains.dokka.utilities.DokkaLogger - -class DefaultPageMergerStrategy(val logger: DokkaLogger) : PageMergerStrategy { - override fun tryMerge(pages: List<PageNode>): List<PageNode> { - if (pages.size != 1) logger.warn("Expected 1 page, but got ${pages.size}") - return listOf(pages.first()) - } -}
\ No newline at end of file diff --git a/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt b/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt deleted file mode 100644 index bdfe393e..00000000 --- a/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.jetbrains.dokka.transformers.pages - -import org.jetbrains.dokka.CoreExtensions -import org.jetbrains.dokka.pages.PageNode -import org.jetbrains.dokka.pages.RootPageNode -import org.jetbrains.dokka.plugability.DokkaContext - -class DefaultPageNodeMerger(val context: DokkaContext) : PageNodeTransformer { - override fun invoke(input: RootPageNode): RootPageNode = - input.modified(children = input.children.map { it.mergeChildren() }) - - fun PageNode.mergeChildren(): PageNode = children.groupBy { it.name } - .map { (_, v) -> v.mergePageNodes() } - .let { pages -> modified(children = pages.map { it.first().mergeChildren() }) } - - private fun List<PageNode>.mergePageNodes(): List<PageNode> = - context[CoreExtensions.pageMergerStrategy].fold(this) { pages, strategy -> tryMerge(strategy, pages) } - - private fun tryMerge(strategy: PageMergerStrategy, pages: List<PageNode>) = if (pages.size > 1) - strategy.tryMerge(pages) - else - pages -}
\ No newline at end of file diff --git a/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt deleted file mode 100644 index 8eb526b3..00000000 --- a/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.jetbrains.dokka.transformers.pages - -import org.jetbrains.dokka.pages.PageNode - -interface PageMergerStrategy { - - fun tryMerge(pages: List<PageNode>): List<PageNode> - -}
\ No newline at end of file diff --git a/core/src/main/kotlin/transformers/pages/SameMethodNamePageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/SameMethodNamePageMergerStrategy.kt deleted file mode 100644 index 3835506b..00000000 --- a/core/src/main/kotlin/transformers/pages/SameMethodNamePageMergerStrategy.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.jetbrains.dokka.transformers.pages - -import org.jetbrains.dokka.pages.* - -object SameMethodNamePageMergerStrategy : PageMergerStrategy { - override fun tryMerge(pages: List<PageNode>): List<PageNode> { - val name = pages.first().name - val members = pages.filterIsInstance<MemberPageNode>() - val others = pages.filterNot { it is MemberPageNode } - - val resChildren = members.flatMap { it.children }.distinct() - val dri = members.flatMap { it.dri }.toSet() - val dci = DCI( - dri = dri, - kind = members.first().content.dci.kind - ) - - val merged = MemberPageNode( - dri = dri, - name = name, - children = resChildren, - content = asGroup(dci, members.map { it.content }), - documentable = null - ) - - return others + listOf(merged) - } - - fun asGroup(dci: DCI, nodes: List<ContentNode>): ContentGroup { - val n = nodes.first() - return ContentGroup(nodes, dci, n.platforms, n.style, n.extras) - } -}
\ No newline at end of file |