diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-06-25 19:27:09 +0200 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-06-25 20:46:45 +0200 |
commit | 6d533d281163b6020adddc41bbfd3fd08309eb2a (patch) | |
tree | 2eed9e8cce8df0fedd118767dd3ad1dff9d8153b /plugins/base/src/main/kotlin | |
parent | 19996f2e89baf7bdeb83ec709400980721d189ed (diff) | |
download | dokka-6d533d281163b6020adddc41bbfd3fd08309eb2a.tar.gz dokka-6d533d281163b6020adddc41bbfd3fd08309eb2a.tar.bz2 dokka-6d533d281163b6020adddc41bbfd3fd08309eb2a.zip |
Enforces directory for classlikes
Diffstat (limited to 'plugins/base/src/main/kotlin')
5 files changed, 16 insertions, 11 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 580b3f6b..0e535c86 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -129,7 +129,7 @@ class DokkaBase : DokkaPlugin() { } val sameMethodNameMerger by extending { - pageMergerStrategy with SameMethodNamePageMergerStrategy order { + pageMergerStrategy providing { ctx -> SameMethodNamePageMergerStrategy(ctx.logger) } order { before(fallbackMerger) } } diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index eada2e3b..4d44fdef 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -76,7 +76,11 @@ open class DefaultLocationProvider( .takeWhile { (a, b) -> a == b }.count() return (List(contextPath.size - commonPathElements) { ".." } + nodePath.drop(commonPathElements) + - if (node.children.isNotEmpty()) listOf(PAGE_WITH_CHILDREN_SUFFIX) else emptyList()).joinToString("/") + if (node is ClasslikePageNode || node.children.isNotEmpty()) + listOf(PAGE_WITH_CHILDREN_SUFFIX) + else + emptyList() + ).joinToString("/") } private fun PageNode.parent() = pageGraphRoot.parentMap[this] 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 93d42e7e..4faf3ad4 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/PageMerger.kt @@ -8,11 +8,11 @@ class PageMerger(private val strategies: Iterable<PageMergerStrategy>) : PageTra override fun invoke(input: RootPageNode): RootPageNode = input.modified(children = input.children.map { it.mergeChildren(emptyList()) }) - private fun PageNode.mergeChildren(path: List<String>): PageNode = children.groupBy { it.name } - .map { (n, v) -> mergePageNodes(v, path + n) } - .let { pages -> - modified(children = pages.map { it.assertSingle(path) }.map { it.mergeChildren(path + it.name) }) - } + private fun PageNode.mergeChildren(path: List<String>): PageNode = children.groupBy { it::class }.map { + it.value.groupBy { it.name }.map { (n, v) -> mergePageNodes(v, path + n) }.map { it.assertSingle(path) } + }.let { pages -> + modified(children = pages.flatten().map { it.mergeChildren(path + it.name) }) + } private fun mergePageNodes(pages: List<PageNode>, path: List<String>): List<PageNode> = strategies.fold(pages) { acc, strategy -> tryMerge(strategy, acc, path) } diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt index 77226310..4b469eb7 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt @@ -1,17 +1,19 @@ package org.jetbrains.dokka.base.transformers.pages.merger import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.utilities.DokkaLogger -object SameMethodNamePageMergerStrategy : PageMergerStrategy { +class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStrategy { override fun tryMerge(pages: List<PageNode>, path: List<String>): List<PageNode> { val members = pages.filterIsInstance<MemberPageNode>().takeIf { it.isNotEmpty() } ?: return pages val name = pages.first().name.also { if (pages.any { page -> page.name != it }) { // Is this even possible? - println("Page names for $it do not match!") // TODO pass logger here somehow + logger.error("Page names for $it do not match!") } } val dri = members.flatMap { it.dri }.toSet() + val merged = MemberPageNode( dri = dri, name = name, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 42db9a1d..a926857f 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -35,8 +35,7 @@ open class DefaultPageCreator( open fun pageForPackage(p: DPackage): PackagePageNode = PackagePageNode( p.name, contentForPackage(p), setOf(p.dri), p, p.classlikes.map(::pageForClasslike) + - p.functions.map(::pageForFunction) + - p.typealiases.map(::pageForTypeAlias) + p.functions.map(::pageForFunction) ) open fun pageForEnumEntry(e: DEnumEntry): ClasslikePageNode = |