aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-08-20 19:00:57 +0200
committerAndrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com>2020-09-08 12:52:59 +0200
commit337c72c547505422c3b047869a65790a14b9a9ea (patch)
tree6abe2d03e266f33147698196f7f96bdbc2ec1a8d /plugins/base/src/main/kotlin
parenta1f8efc30b4421ce371b02b747bbeac24fafd7ba (diff)
downloaddokka-337c72c547505422c3b047869a65790a14b9a9ea.tar.gz
dokka-337c72c547505422c3b047869a65790a14b9a9ea.tar.bz2
dokka-337c72c547505422c3b047869a65790a14b9a9ea.zip
Merger changes
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt58
1 files changed, 34 insertions, 24 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
index d556c9cb..371ab12d 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
@@ -10,7 +10,7 @@ import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-internal class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerger {
+internal class DefaultDocumentableMerger(val context: DokkaContext) : DocumentableMerger {
private val dependencyInfo = context.getDependencyInfo()
@@ -79,33 +79,43 @@ internal class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMe
reducer: (T, T) -> T
): List<T> where T : Documentable, T : WithExpectActual {
- fun analyzeExpectActual(sameDriElements: List<T>) = sameDriElements
- .partition { it.expectPresentInSet != null }
- .let { (expects, actuals) ->
- expects.map { expect ->
- listOf(expect) + actuals.filter { actual ->
- dependencyInfo[actual.sourceSets.single()]
- ?.contains(expect.expectPresentInSet!!)
- ?: throw IllegalStateException("Cannot resolve expect/actual relation for ${actual.name}")
- }
- }.map { it.reduce(reducer) }
- }
-
fun T.isExpectActual(): Boolean =
this.safeAs<WithExtraProperties<T>>().let { it != null && it.extra[IsExpectActual] != null }
- fun mergeClashingElements(elements: List<T>) = if(elements.size <= 1) elements else elements.map {
- when(it) {
- is DClass -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DObject -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DAnnotation -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DInterface -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DEnum -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DFunction -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- is DProperty -> it.copy(name = "${it.name}(${it.sourceSets.single().analysisPlatform.key})")
- else -> elements
+ fun Set<DokkaConfiguration.DokkaSourceSet>.parentSourceSet(): String = singleOrNull {
+ it.dependentSourceSets.all { it !in this.map { it.sourceSetID } }
+ }?.displayName
+ ?: "unresolved".also { context.logger.error("Ill-defined dependency between sourceSets") }
+
+ fun mergeClashingElements(elements: List<T>): List<T> = elements.groupBy { it.name }.values.flatMap {
+ if(it.size > 1) it.map {
+ when(it) {
+ is DClass -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DObject -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DAnnotation -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DInterface -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DEnum -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DFunction -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ is DProperty -> it.copy(name = "${it.name}(${it.sourceSets.parentSourceSet()})")
+ else -> it
+ }
+ } as List<T> else it
+ }
+
+ fun analyzeExpectActual(sameDriElements: List<T>): List<T> {
+ val (expects, actuals) = sameDriElements.partition { it.expectPresentInSet != null }
+ val groupedByOwnExpect = expects.map { expect ->
+ listOf(expect) + actuals.filter { actual ->
+ dependencyInfo[actual.sourceSets.single()]
+ ?.contains(expect.expectPresentInSet!!)
+ ?: throw IllegalStateException("Cannot resolve expect/actual relation for ${actual.name}")
+ }
}
- } as List<T>
+ val reducedToOneDocumentable = groupedByOwnExpect.map { it.reduce(reducer) }
+ val uniqueNamedDocumentables = reducedToOneDocumentable.let(::mergeClashingElements)
+ return uniqueNamedDocumentables
+ }
+
return elements.partition {
it.isExpectActual()