aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/plugability/DefaultExtensions.kt3
-rw-r--r--core/src/main/kotlin/renderers/html/htmlPreprocessors.kt10
-rw-r--r--core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt31
-rw-r--r--core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt2
-rw-r--r--core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt4
-rw-r--r--core/src/main/kotlin/transformers/pages/PageNodeTransformer.kt4
-rw-r--r--core/src/main/kotlin/transformers/pages/SameNamePageMergerStrategy.kt30
-rw-r--r--core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt51
-rw-r--r--core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt128
-rw-r--r--plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt2
-rw-r--r--plugins/xml/src/main/kotlin/XmlPlugin.kt2
11 files changed, 178 insertions, 89 deletions
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt
index 3f630ee3..28753cc6 100644
--- a/core/src/main/kotlin/plugability/DefaultExtensions.kt
+++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt
@@ -10,6 +10,7 @@ import org.jetbrains.dokka.transformers.descriptors.DefaultDescriptorToDocumenta
import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationNodeMerger
import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator
import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy
+import org.jetbrains.dokka.transformers.pages.SameNamePageMergerStrategy
import org.jetbrains.dokka.transformers.psi.DefaultPsiToDocumentationTranslator
import org.jetbrains.dokka.transformers.pages.DefaultPageNodeMerger
@@ -37,7 +38,7 @@ internal object DefaultExtensions {
CoreExtensions.renderer -> renderer.get(fullContext)
CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext)
CoreExtensions.outputWriter -> outputWriter.get(fullContext)
- CoreExtensions.pageMergerStrategy -> DefaultPageMergerStrategy
+ 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/renderers/html/htmlPreprocessors.kt b/core/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index 7ce6d298..4ee67448 100644
--- a/core/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/core/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -8,12 +8,12 @@ import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.renderers.platforms
import org.jetbrains.dokka.transformers.pages.PageNodeTransformer
-object RootCreator : PageNodeTransformer() {
+object RootCreator : PageNodeTransformer {
override fun invoke(input: RootPageNode) =
RendererSpecificRootPage("", listOf(input), RenderingStrategy.DoNothing)
}
-object SearchPageInstaller : PageNodeTransformer() {
+object SearchPageInstaller : PageNodeTransformer {
override fun invoke(input: RootPageNode) = input.modified(children = input.children + searchPage)
private val searchPage = RendererSpecificResourcePage(
@@ -34,7 +34,7 @@ object SearchPageInstaller : PageNodeTransformer() {
})
}
-object NavigationPageInstaller : PageNodeTransformer() {
+object NavigationPageInstaller : PageNodeTransformer {
override fun invoke(input: RootPageNode) = input.modified(
children = input.children + NavigationPage(
input.children.filterIsInstance<ContentPage>().single().let(::visit)
@@ -48,7 +48,7 @@ object NavigationPageInstaller : PageNodeTransformer() {
page.children.filterIsInstance<ContentPage>().map { visit(it) })
}
-object ResourceInstaller : PageNodeTransformer() {
+object ResourceInstaller : PageNodeTransformer {
override fun invoke(input: RootPageNode) = input.modified(children = input.children + resourcePages)
private val resourcePages = listOf("styles", "scripts", "images").map {
@@ -56,7 +56,7 @@ object ResourceInstaller : PageNodeTransformer() {
}
}
-object StyleAndScriptsAppender : PageNodeTransformer() {
+object StyleAndScriptsAppender : PageNodeTransformer {
override fun invoke(input: RootPageNode) = input.transformContentPagesTree {
it.modified(
embeddedResources = it.embeddedResources + listOf(
diff --git a/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt
index 81da71ce..66562d8b 100644
--- a/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt
+++ b/core/src/main/kotlin/transformers/pages/DefaultPageMergerStrategy.kt
@@ -1,30 +1,11 @@
package org.jetbrains.dokka.transformers.pages
-import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.utilities.DokkaLogger
-object DefaultPageMergerStrategy : PageMergerStrategy() {
- override fun tryMerge(pages: List<PageNode>): List<PageNode> = listOf(pages.mergePageNodes())
-
- private fun List<PageNode>.mergePageNodes(): ContentPage {
- val name = first().name
- val resChildren = this.flatMap { it.children }.distinct()
- val contentChildren = this.filterIsInstance<ContentPage>()
- val dri = contentChildren.flatMap { it.dri }.toSet()
- val dci = DCI(
- dri = dri,
- kind = contentChildren.first().content.dci.kind
- )
- return contentChildren.first()
- .modified(
- dri = dri,
- name = name,
- children = resChildren,
- content = asGroup(dci, contentChildren.map { it.content })
- )
- }
-
- fun asGroup(dci: DCI, nodes: List<ContentNode>): ContentGroup {
- val n = nodes.first()
- return ContentGroup(nodes, dci, n.platforms, n.style, n.extras)
+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
index 72e491cf..bdfe393e 100644
--- a/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt
+++ b/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt
@@ -5,7 +5,7 @@ import org.jetbrains.dokka.pages.PageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
-class DefaultPageNodeMerger(val context: DokkaContext) : PageNodeTransformer(context) {
+class DefaultPageNodeMerger(val context: DokkaContext) : PageNodeTransformer {
override fun invoke(input: RootPageNode): RootPageNode =
input.modified(children = input.children.map { it.mergeChildren() })
diff --git a/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt
index 37dc5a6a..8eb526b3 100644
--- a/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt
+++ b/core/src/main/kotlin/transformers/pages/PageMergerStrategy.kt
@@ -2,8 +2,8 @@ package org.jetbrains.dokka.transformers.pages
import org.jetbrains.dokka.pages.PageNode
-abstract class PageMergerStrategy {
+interface PageMergerStrategy {
- abstract fun tryMerge(pages: List<PageNode>): List<PageNode>
+ fun tryMerge(pages: List<PageNode>): List<PageNode>
} \ No newline at end of file
diff --git a/core/src/main/kotlin/transformers/pages/PageNodeTransformer.kt b/core/src/main/kotlin/transformers/pages/PageNodeTransformer.kt
index ebf53d30..45357060 100644
--- a/core/src/main/kotlin/transformers/pages/PageNodeTransformer.kt
+++ b/core/src/main/kotlin/transformers/pages/PageNodeTransformer.kt
@@ -4,6 +4,6 @@ import org.jetbrains.dokka.pages.ModulePageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
-abstract class PageNodeTransformer(context: DokkaContext? = null) {
- abstract operator fun invoke(input: RootPageNode): RootPageNode
+interface PageNodeTransformer {
+ operator fun invoke(input: RootPageNode): RootPageNode
} \ No newline at end of file
diff --git a/core/src/main/kotlin/transformers/pages/SameNamePageMergerStrategy.kt b/core/src/main/kotlin/transformers/pages/SameNamePageMergerStrategy.kt
new file mode 100644
index 00000000..5b0e8794
--- /dev/null
+++ b/core/src/main/kotlin/transformers/pages/SameNamePageMergerStrategy.kt
@@ -0,0 +1,30 @@
+package org.jetbrains.dokka.transformers.pages
+
+import org.jetbrains.dokka.pages.*
+
+object SameNamePageMergerStrategy : PageMergerStrategy {
+ override fun tryMerge(pages: List<PageNode>): List<PageNode> = listOf(pages.mergePageNodes())
+
+ private fun List<PageNode>.mergePageNodes(): ContentPage {
+ val name = first().name
+ val resChildren = this.flatMap { it.children }.distinct()
+ val contentChildren = this.filterIsInstance<ContentPage>()
+ val dri = contentChildren.flatMap { it.dri }.toSet()
+ val dci = DCI(
+ dri = dri,
+ kind = contentChildren.first().content.dci.kind
+ )
+ return contentChildren.first()
+ .modified(
+ dri = dri,
+ name = name,
+ children = resChildren,
+ content = asGroup(dci, contentChildren.map { it.content })
+ )
+ }
+
+ 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
diff --git a/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt b/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt
deleted file mode 100644
index 432820af..00000000
--- a/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-package pageMerger
-
-import org.jetbrains.dokka.pages.ContentPage
-import org.jetbrains.dokka.pages.PageNode
-import org.junit.Test
-import testApi.testRunner.AbstractCoreTest
-
-class DefaultPageNodeMergerTest : AbstractCoreTest() {
-
- @Test
- fun test1() {
- val configuration = dokkaConfiguration {
- passes {
- pass {
- sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
- }
- }
- }
-
- testInline(
- """
- |/src/main/kotlin/pageMerger/Test.kt
- |package pageMerger
- |
- |fun testT(): Int = 1
- |fun testT(i: Int): Int = i
- |
- |object Test {
- | fun test(): String = ""
- | fun test(str: String): String = str
- |}
- """.trimMargin(),
- configuration
- ) {
- pagesTransformationStage = {
- val allChildren = it.childrenRec().filterIsInstance<ContentPage>()
- val testT = allChildren.filter { it.name == "testT" }
- val test = allChildren.filter { it.name == "test" }
-
- assert(testT.size == 1) { "There can be only one testT page" }
- assert(testT.first().dri.size == 2) { "testT page should have 2 DRI" }
-
- assert(test.size == 1) { "There can be only one test page" }
- assert(test.first().dri.size == 2) { "test page should have 2 DRI" }
- }
- }
- }
-
- fun PageNode.childrenRec(): List<PageNode> = listOf(this) + children.flatMap { it.childrenRec() }
-
-} \ No newline at end of file
diff --git a/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
new file mode 100644
index 00000000..e43e2348
--- /dev/null
+++ b/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
@@ -0,0 +1,128 @@
+package pageMerger
+
+import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.pages.ContentPage
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.plugability.DokkaPlugin
+import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy
+import org.jetbrains.dokka.transformers.pages.PageMergerStrategy
+import org.jetbrains.dokka.transformers.pages.SameNamePageMergerStrategy
+import org.jetbrains.dokka.utilities.DokkaLogger
+import org.junit.Test
+import testApi.testRunner.AbstractCoreTest
+
+class PageNodeMergerTest : AbstractCoreTest() {
+
+ object SameNameStrategy : DokkaPlugin() {
+ val strategy by extending { CoreExtensions.pageMergerStrategy with SameNamePageMergerStrategy }
+ }
+
+ class DefaultStrategy(val strList: MutableList<String> = mutableListOf()) : DokkaPlugin(), DokkaLogger {
+ val strategy by extending { CoreExtensions.pageMergerStrategy with DefaultPageMergerStrategy(this@DefaultStrategy) }
+
+ override var warningsCount: Int = 0
+ override var errorsCount: Int = 0
+
+ override fun debug(message: String) = TODO()
+
+ override fun info(message: String) = TODO()
+
+ override fun progress(message: String) = TODO()
+
+ override fun warn(message: String) {
+ strList += message
+ }
+
+ override fun error(message: String) = TODO()
+
+ override fun report() = TODO()
+ }
+
+ @Test
+ fun sameNameStrategyTest() {
+
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |fun testT(): Int = 1
+ |fun testT(i: Int): Int = i
+ |
+ |object Test {
+ | fun test(): String = ""
+ | fun test(str: String): String = str
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(SameNameStrategy)
+ ) {
+ pagesTransformationStage = {
+ val allChildren = it.childrenRec().filterIsInstance<ContentPage>()
+ val testT = allChildren.filter { it.name == "testT" }
+ val test = allChildren.filter { it.name == "test" }
+
+ assert(testT.size == 1) { "There can be only one testT page" }
+ assert(testT.first().dri.size == 2) { "testT page should have 2 DRI, but has ${testT.first().dri.size}" }
+
+ assert(test.size == 1) { "There can be only one test page" }
+ assert(test.first().dri.size == 2) { "test page should have 2 DRI, but has ${test.first().dri.size}" }
+ }
+ }
+ }
+
+ @Test
+ fun defaultStrategyTest() {
+ val strList: MutableList<String> = mutableListOf()
+
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |fun testT(): Int = 1
+ |fun testT(i: Int): Int = i
+ |
+ |object Test {
+ | fun test(): String = ""
+ | fun test(str: String): String = str
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(DefaultStrategy(strList))
+ ) {
+ pagesTransformationStage = { root ->
+ val allChildren = root.childrenRec().filterIsInstance<ContentPage>()
+ val testT = allChildren.filter { it.name == "testT" }
+ val test = allChildren.filter { it.name == "test" }
+
+ assert(testT.size == 1) { "There can be only one testT page" }
+ assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" }
+
+ assert(test.size == 1) { "There can be only one test page" }
+ assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" }
+
+ assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" }
+ }
+ }
+ }
+
+ fun PageNode.childrenRec(): List<PageNode> = listOf(this) + children.flatMap { it.childrenRec() }
+
+} \ No newline at end of file
diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
index 0f66c77c..52723157 100644
--- a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
+++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
@@ -18,7 +18,7 @@ class MathjaxPlugin : DokkaPlugin() {
private const val ANNOTATION = "usesMathJax"
private const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest"
-object MathjaxTransformer : PageNodeTransformer() {
+object MathjaxTransformer : PageNodeTransformer {
override fun invoke(input: RootPageNode) = input.transformContentPagesTree {
it.modified(
embeddedResources = it.embeddedResources + if (it.isNeedingMathjax) listOf(LIB_PATH) else emptyList()
diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt
index e2ac261a..e19b76b3 100644
--- a/plugins/xml/src/main/kotlin/XmlPlugin.kt
+++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt
@@ -16,7 +16,7 @@ class XmlPlugin : DokkaPlugin() {
}
}
-class XmlTransformer(private val dokkaContext: DokkaContext) : PageNodeTransformer(dokkaContext) {
+class XmlTransformer(private val dokkaContext: DokkaContext) : PageNodeTransformer {
private val commentsToContentConverter by lazy { dokkaContext.single(CoreExtensions.commentsToContentConverter) }
enum class XMLKind : Kind {