aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-02-17 10:55:44 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-18 13:28:23 +0100
commit2bfb7733dfef8da0271a01a7275ea42ecb69d93a (patch)
treec3e6369da1a795d1b2dcf8342629742ca0dfbde3 /core/src/main
parentf625cef495d625d81ee22e950083f57cc4fab875 (diff)
downloaddokka-2bfb7733dfef8da0271a01a7275ea42ecb69d93a.tar.gz
dokka-2bfb7733dfef8da0271a01a7275ea42ecb69d93a.tar.bz2
dokka-2bfb7733dfef8da0271a01a7275ea42ecb69d93a.zip
Cleans up page mergers and moves them to base plugin
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/CoreExtensions.kt2
-rw-r--r--core/src/main/kotlin/plugability/DefaultExtensions.kt4
-rw-r--r--core/src/main/kotlin/plugability/DokkaContext.kt3
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt6
-rw-r--r--core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt11
-rw-r--r--core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt23
-rw-r--r--core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt9
-rw-r--r--core/src/main/kotlin/transformers/pages/SameMethodNamePageMergerStrategy.kt33
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