aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-07-28 18:23:50 +0200
committerGitHub <noreply@github.com>2021-07-28 18:23:50 +0200
commitb2b542988d1523749ab3a881e3cd4cf502ccdd6d (patch)
tree5a68f6ada1df4c31ffad0597bb6b952f4791a407 /plugins/base/src/main/kotlin
parentf03083d7534209ad94dc3c4d7afd17f58e58127d (diff)
downloaddokka-b2b542988d1523749ab3a881e3cd4cf502ccdd6d.tar.gz
dokka-b2b542988d1523749ab3a881e3cd4cf502ccdd6d.tar.bz2
dokka-b2b542988d1523749ab3a881e3cd4cf502ccdd6d.zip
Fix broken link in kotlinx.serialization (#2038)
* Fix broken link in kotlinx.serialization * Rename DRIWithSourceSet to DRIWithSourceSets
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt37
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt7
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt8
3 files changed, 36 insertions, 16 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
index 5488f754..2575c204 100644
--- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
+++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt
@@ -5,6 +5,7 @@ import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.PointingToDeclaration
import org.jetbrains.dokka.model.DisplaySourceSet
+import org.jetbrains.dokka.model.sourceSetIDs
import org.jetbrains.dokka.model.toDisplaySourceSet
import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.*
@@ -34,11 +35,19 @@ open class DokkaLocationProvider(
pageGraphRoot.children.forEach { registerPath(it, emptyList()) }
}
- protected val pagesIndex: Map<DRIWithSourceSet, ContentPage> =
+ protected val pagesIndex: Map<DRIWithSourceSets, ContentPage> =
pageGraphRoot.withDescendants().filterIsInstance<ContentPage>()
.flatMap { page ->
page.dri.flatMap { dri ->
- page.sourceSets().ifEmpty { setOf(null) }.map { sourceSet -> DRIWithSourceSet(dri,sourceSet) to page }
+ page.sourceSets().ifEmpty { setOf(null) }
+ .map { sourceSet -> DRIWithSourceSets(dri, setOfNotNull(sourceSet)) to page }
+ .let {
+ if (it.size > 1) {
+ it + (DRIWithSourceSets(dri, page.sourceSets()) to page)
+ } else {
+ it
+ }
+ }
}
}
.groupingBy { it.first }
@@ -46,7 +55,7 @@ open class DokkaLocationProvider(
if (first) page else throw AssertionError("Multiple pages associated with key: ${key.dri}/${key.sourceSet}")
}
- protected val anchorsIndex: Map<DRIWithSourceSet, PageWithKind> =
+ protected val anchorsIndex: Map<DRIWithSourceSets, PageWithKind> =
pageGraphRoot.withDescendants().filterIsInstance<ContentPage>()
.flatMap { page ->
page.content.withDescendants()
@@ -60,7 +69,7 @@ open class DokkaLocationProvider(
.flatMap { (pair, kind) ->
val (dri, sourceSets) = pair
sourceSets.ifEmpty { setOf(null) }.map { sourceSet ->
- DRIWithSourceSet(dri, sourceSet) to PageWithKind(page, kind)
+ DRIWithSourceSets(dri, setOfNotNull(sourceSet)) to PageWithKind(page, kind)
}
}
}.toMap()
@@ -70,18 +79,18 @@ open class DokkaLocationProvider(
override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?): String? =
sourceSets.ifEmpty { setOf(null) }.mapNotNull { sourceSet ->
- val driWithSourceSet = DRIWithSourceSet(dri, sourceSet)
- getLocalLocation(driWithSourceSet, context)
- ?: getLocalLocation(driWithSourceSet.copy(dri = dri.copy(target = PointingToDeclaration)), context)
+ val driWithSourceSets = DRIWithSourceSets(dri, setOfNotNull(sourceSet))
+ getLocalLocation(driWithSourceSets, context)
+ ?: getLocalLocation(driWithSourceSets.copy(dri = dri.copy(target = PointingToDeclaration)), context)
// Not found in PageGraph, that means it's an external link
?: getExternalLocation(dri, sourceSets)
?: getExternalLocation(dri.copy(target = PointingToDeclaration), sourceSets)
}.distinct().singleOrNull()
- private fun getLocalLocation(driWithSourceSet: DRIWithSourceSet, context: PageNode?): String? {
- val (dri, originalSourceSet) = driWithSourceSet
+ private fun getLocalLocation(driWithSourceSets: DRIWithSourceSets, context: PageNode?): String? {
+ val (dri, originalSourceSet) = driWithSourceSets
val allSourceSets =
- listOf(originalSourceSet) + originalSourceSet?.let { oss ->
+ listOf(originalSourceSet) + originalSourceSet.let { oss ->
dokkaContext.configuration.sourceSets.filter { it.sourceSetID in oss.sourceSetIDs }
.flatMap { it.dependentSourceSets }
.mapNotNull { ssid ->
@@ -90,10 +99,10 @@ open class DokkaLocationProvider(
}.orEmpty()
return allSourceSets.asSequence().mapNotNull { displaySourceSet ->
- pagesIndex[DRIWithSourceSet(dri, displaySourceSet)]?.let { page -> resolve(page, context) }
- ?: anchorsIndex[driWithSourceSet]?.let { (page, kind) ->
+ pagesIndex[DRIWithSourceSets(dri, displaySourceSet)]?.let { page -> resolve(page, context) }
+ ?: anchorsIndex[driWithSourceSets]?.let { (page, kind) ->
val dci = DCI(setOf(dri), kind)
- resolve(page, context) + "#" + anchorForDCI(dci, setOfNotNull(displaySourceSet))
+ resolve(page, context) + "#" + anchorForDCI(dci, displaySourceSet)
}
}.firstOrNull()
}
@@ -130,7 +139,7 @@ open class DokkaLocationProvider(
private val PageNode.pathName: String
get() = if (this is PackagePageNode) name else identifierToFilename(name)
- protected data class DRIWithSourceSet(val dri: DRI, val sourceSet: DisplaySourceSet?)
+ protected data class DRIWithSourceSets(val dri: DRI, val sourceSet: Set<DisplaySourceSet>)
protected data class PageWithKind(val page: ContentPage, val kind: Kind)
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 4eacf359..2fb70fc8 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
@@ -1,5 +1,7 @@
package org.jetbrains.dokka.base.transformers.pages.merger
+import org.jetbrains.dokka.base.renderers.sourceSets
+import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.utilities.DokkaLogger
@@ -19,7 +21,7 @@ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStra
dri = dri,
name = name,
children = members.flatMap { it.children }.distinct(),
- content = squashDivergentInstances(members),
+ content = squashDivergentInstances(members).withSourceSets(members.allSourceSets()),
embeddedResources = members.flatMap { it.embeddedResources }.distinct(),
documentable = null
)
@@ -27,6 +29,9 @@ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStra
return (pages - members) + listOf(merged)
}
+ private fun List<MemberPageNode>.allSourceSets(): Set<DisplaySourceSet> =
+ fold(emptySet()) { acc, e -> acc + e.sourceSets() }
+
private fun squashDivergentInstances(nodes: List<MemberPageNode>): ContentNode =
nodes.map { it.content }
.reduce { acc, node ->
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index eaa4b6cd..081608d6 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -607,7 +607,13 @@ open class DefaultPageCreator(
styles = emptySet(),
extra = elementName?.let { name -> extra + SymbolAnchorHint(name, kind) } ?: extra
) {
- link(elementName.orEmpty(), elements.first().dri, kind = kind, styles = setOf(ContentStyle.RowTitle))
+ link(
+ text = elementName.orEmpty(),
+ address = elements.first().dri,
+ kind = kind,
+ styles = setOf(ContentStyle.RowTitle),
+ sourceSets = elements.sourceSets.toSet(),
+ )
divergentGroup(
ContentDivergentGroup.GroupID(name),
elements.map { it.dri }.toSet(),