aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-05-05 17:45:12 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-14 13:30:33 +0200
commit3f2a790190da4f40ea6d8a976aa1929b2a1b002b (patch)
tree752ee84451954e9ea5e6d4133e18e41aaee2f7b1 /plugins/base/src/main/kotlin/transformers
parenta440f0cb8756019131a2c15389e747aea3c585e7 (diff)
downloaddokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.gz
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.bz2
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.zip
Changing approach from platform-driven to source-set-driven
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt8
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt233
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt55
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt23
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt42
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt3
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt33
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt2
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt25
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt23
10 files changed, 199 insertions, 248 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt
index 35f27a94..cab4a9d2 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt
@@ -6,8 +6,8 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-class ActualTypealiasAdder : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>, context: DokkaContext) = modules.map { it.mergeTypealiases() }
+class ActualTypealiasAdder(val context: DokkaContext) : PreMergeDocumentableTransformer {
+ override fun invoke(modules: List<DModule>) = modules.map { it.mergeTypealiases() }
private fun DModule.mergeTypealiases(): DModule = copy(packages = packages.map { pkg ->
if (pkg.typealiases.isEmpty()) {
@@ -64,11 +64,11 @@ class ActualTypealiasAdder : PreMergeDocumentableTransformer {
typealiases: Map<DRI, DTypeAlias>
): List<T> where T : DClasslike, T : WithExtraProperties<T>, T : WithExpectActual =
elements.map { element ->
- if (element.sources.expect != null) {
+ if (element.expectPresentInSet != null) {
typealiases[element.dri]?.let { ta ->
element.withNewExtras(
element.extra + ActualTypealias(
- PlatformDependent.from(ta.platformData.single(), ta.underlyingType.values.single())
+ mapOf(ta.sourceSets.single() to ta.underlyingType.values.single())
)
)
} ?: element
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
index f871cdec..862f9240 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt
@@ -2,7 +2,6 @@ package org.jetbrains.dokka.base.transformers.documentables
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.mergeExtras
-import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
@@ -24,8 +23,9 @@ internal object DefaultDocumentableMerger : DocumentableMerger {
list.flatMap { it.packages },
DPackage::mergeWith
),
- documentation = list.platformDependentFor { documentation },
- platformData = list.flatMap { it.platformData }.distinct()
+ documentation = list.map { it.documentation }.flatMap { it.entries }.associate { (k,v) -> k to v },
+ expectPresentInSet = list.firstNotNullResult { it.expectPresentInSet },
+ sourceSets = list.flatMap { it.sourceSets }
).mergeExtras(left, right)
}
}
@@ -36,115 +36,51 @@ private fun <T : Documentable> merge(elements: List<T>, reducer: (T, T) -> T): L
.reduce { _, left, right -> reducer(left, right) }
.values.toList()
-private fun <T : Any, D : Documentable> Iterable<D>.platformDependentFor(
- selector: D.() -> PlatformDependent<T>
-): PlatformDependent<T> {
- val actuals = map { it.selector().map }
- .flatMap { it.entries }
- .associate { (k, v) -> k to v }
-
- val expected = firstNotNullResult { it.selector().expect }
-
- return PlatformDependent(actuals, expected)
-}
-
-private fun <T : Any> PlatformDependent<T>.mergeWith(other: PlatformDependent<T>) = PlatformDependent(
- map = this + other,
- expect = expect ?: other.expect
-)
-
private fun <T> mergeExpectActual(
elements: List<T>,
- reducer: (T, T) -> T,
- platformSetter: T.(List<PlatformData>) -> T
+ reducer: (T, T) -> T
): List<T> where T : Documentable, T : WithExpectActual {
- fun findExpect(actual: T, expects: List<T>): Expect<T> =
- expects.find { it.platformData.flatMap { it.targets }.containsAll(actual.platformData.flatMap { it.targets }) }
- .let { Expect.from(it) }
-
- fun reduceExpectActual(entry: Map.Entry<Expect<T>, List<T>>): List<T> = when (val expect = entry.key) {
- Expect.NotFound -> entry.value
- is Expect.Found -> entry.value.plus(expect.expect).reduce(reducer).let(::listOf)
- }
-
- fun analyzeExpectActual(sameDriElements: List<T>): List<T> {
- val pathGrouped: Collection<T> = mutableMapOf<Set<String>, T>().apply {
- sameDriElements.forEach { documentable ->
- val paths = documentable.sources.allValues.map { it.path }.toSet()
- val key = keys.find { it.containsAll(paths) }
- if (key == null) {
- put(paths, documentable)
- } else {
- computeIfPresent(key) { _, old -> reducer(old, documentable) }
- }
- }
- }.values
- val (expect, actual) = pathGrouped.partition { it.sources.expect != null }
- val mergedExpect = expect.groupBy { it.sources.expect?.path }.values.map { e ->
- e.first().platformSetter(e.flatMap { it.platformData }.distinct())
- }
- val groupExpectActual = actual.groupBy { findExpect(it, mergedExpect) }
- val pathsToExpects: Set<String> =
- groupExpectActual.keys.filterIsInstance<Expect.Found<T>>()
- .mapNotNull { it.expect.sources.expect?.path }.toSet()
+ fun analyzeExpectActual(sameDriElements: List<T>) = sameDriElements.reduce(reducer)
- return groupExpectActual.flatMap { reduceExpectActual(it) } + expect.filterNot { it.sources.expect?.path in pathsToExpects }
- }
-
- return elements.groupBy { it.dri }.values.flatMap(::analyzeExpectActual)
-}
-
-private sealed class Expect<out T : Any> {
- object NotFound : Expect<Nothing>()
- data class Found<T : Any>(val expect: T) : Expect<T>()
-
- companion object {
- fun <T : Any> from(t: T?) = t?.let(::Found) ?: NotFound
- }
+ return elements.groupBy { it.dri }.values.map(::analyzeExpectActual)
}
fun DPackage.mergeWith(other: DPackage): DPackage = copy(
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
- documentation = documentation.mergeWith(other.documentation),
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
typealiases = merge(typealiases + other.typealiases, DTypeAlias::mergeWith),
- platformData = (platformData + other.platformData).distinct()
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DFunction.mergeWith(other: DFunction): DFunction = copy(
parameters = merge(this.parameters + other.parameters, DParameter::mergeWith),
receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver,
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- modifier = modifier.mergeWith(other.modifier),
- platformData = (platformData + other.platformData).distinct(),
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ modifier = modifier + other.modifier,
+ sourceSets = sourceSets + other.sourceSets,
generics = merge(generics + other.generics, DTypeParameter::mergeWith)
).mergeExtras(this, other)
fun DProperty.mergeWith(other: DProperty): DProperty = copy(
receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver,
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- modifier = modifier.mergeWith(other.modifier),
- platformData = (platformData + other.platformData).distinct(),
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ modifier = modifier + other.modifier,
+ sourceSets = sourceSets + other.sourceSets,
getter = getter?.let { g -> other.getter?.let { g.mergeWith(it) } ?: g } ?: other.getter,
setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter,
generics = merge(generics + other.generics, DTypeParameter::mergeWith)
).mergeExtras(this, other)
-fun DClasslike.setPlatformData(platformData: List<PlatformData>): DClasslike = when (this) {
- is DClass -> copy(platformData = platformData)
- is DEnum -> copy(platformData = platformData)
- is DInterface -> copy(platformData = platformData)
- is DObject -> copy(platformData = platformData)
- is DAnnotation -> copy(platformData = platformData)
- else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot have platform set")
-}
-
fun DClasslike.mergeWith(other: DClasslike): DClasslike = when {
this is DClass && other is DClass -> mergeWith(other)
this is DEnum && other is DEnum -> mergeWith(other)
@@ -158,18 +94,19 @@ fun DClass.mergeWith(other: DClass): DClass = copy(
constructors = mergeExpectActual(
constructors + other.constructors,
DFunction::mergeWith
- ) { copy(platformData = it) },
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
+ ),
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion,
generics = merge(generics + other.generics, DTypeParameter::mergeWith),
- modifier = modifier.mergeWith(other.modifier),
- supertypes = supertypes.mergeWith(other.supertypes),
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ modifier = modifier + other.modifier,
+ supertypes = supertypes + other.supertypes,
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DEnum.mergeWith(other: DEnum): DEnum = copy(
@@ -177,78 +114,86 @@ fun DEnum.mergeWith(other: DEnum): DEnum = copy(
constructors = mergeExpectActual(
constructors + other.constructors,
DFunction::mergeWith
- ) { copy(platformData = it) },
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
+ ),
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion,
- supertypes = supertypes.mergeWith(other.supertypes),
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ supertypes = supertypes + other.supertypes,
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DEnumEntry.mergeWith(other: DEnumEntry): DEnumEntry = copy(
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
- documentation = documentation.mergeWith(other.documentation),
- platformData = (platformData + other.platformData).distinct()
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DObject.mergeWith(other: DObject): DObject = copy(
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
- supertypes = supertypes.mergeWith(other.supertypes),
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
+ supertypes = supertypes + other.supertypes,
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DInterface.mergeWith(other: DInterface): DInterface = copy(
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion,
generics = merge(generics + other.generics, DTypeParameter::mergeWith),
- supertypes = supertypes.mergeWith(other.supertypes),
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ supertypes = supertypes + other.supertypes,
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy(
constructors = mergeExpectActual(
constructors + other.constructors,
DFunction::mergeWith
- ) { copy(platformData = it) },
- functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) },
- properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) },
- classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData),
+ ),
+ functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith),
+ properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith),
+ classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith),
companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion,
- documentation = documentation.mergeWith(other.documentation),
- sources = sources.mergeWith(other.sources),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sources = sources+ other.sources,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DParameter.mergeWith(other: DParameter): DParameter = copy(
- documentation = documentation.mergeWith(other.documentation),
- platformData = (platformData + other.platformData).distinct()
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DTypeParameter.mergeWith(other: DTypeParameter): DTypeParameter = copy(
- documentation = documentation.mergeWith(other.documentation),
- platformData = (platformData + other.platformData).distinct()
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)
fun DTypeAlias.mergeWith(other: DTypeAlias): DTypeAlias = copy(
- documentation = documentation.mergeWith(other.documentation),
- underlyingType = underlyingType.mergeWith(other.underlyingType),
- visibility = visibility.mergeWith(other.visibility),
- platformData = (platformData + other.platformData).distinct()
+ documentation = documentation + other.documentation,
+ expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
+ underlyingType = underlyingType + other.underlyingType,
+ visibility = visibility + other.visibility,
+ sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other) \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt
index c261d2dc..6fdce3a8 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt
@@ -5,15 +5,14 @@ import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.DAnnotation
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DFunction
-import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
+internal class DocumentableVisibilityFilter(val context: DokkaContext) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>, context: DokkaContext): List<DModule> = modules.map { original ->
+ override fun invoke(modules: List<DModule>): List<DModule> = modules.map { original ->
val packageOptions =
- context.configuration.passesConfigurations.first { original.platformData.contains(it.platformData) }
+ context.configuration.passesConfigurations.first { original.sourceSets.contains(context.sourceSet(it)) }
.perPackageOptions
DocumentableFilter(packageOptions).processModule(original)
@@ -36,7 +35,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
original.name,
packages = packages,
documentation = original.documentation,
- platformData = original.platformData,
+ sourceSets = original.sourceSets,
extra = original.extra
)
}
@@ -69,7 +68,8 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
classlikes,
it.typealiases,
it.documentation,
- it.platformData,
+ it.expectPresentInSet,
+ it.sourceSets,
it.extra
)
}
@@ -78,26 +78,25 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
return Pair(packagesListChanged, filteredPackages)
}
- private fun <T : WithVisibility> alwaysTrue(a: T, p: PlatformData) = true
- private fun <T : WithVisibility> alwaysFalse(a: T, p: PlatformData) = false
+ private fun <T : WithVisibility> alwaysTrue(a: T, p: SourceSetData) = true
+ private fun <T : WithVisibility> alwaysFalse(a: T, p: SourceSetData) = false
- private fun WithVisibility.visibilityForPlatform(data: PlatformData): Visibility? =
- visibility[data] ?: visibility.expect
+ private fun WithVisibility.visibilityForPlatform(data: SourceSetData): Visibility? = visibility[data]
private fun <T> T.filterPlatforms(
- additionalCondition: (T, PlatformData) -> Boolean = ::alwaysTrue,
- alternativeCondition: (T, PlatformData) -> Boolean = ::alwaysFalse
+ additionalCondition: (T, SourceSetData) -> Boolean = ::alwaysTrue,
+ alternativeCondition: (T, SourceSetData) -> Boolean = ::alwaysFalse
) where T : Documentable, T : WithVisibility =
- platformData.filter { d ->
+ sourceSets.filter { d ->
visibilityForPlatform(d)?.isAllowedInPackage(dri.packageName) == true &&
additionalCondition(this, d) ||
alternativeCondition(this, d)
}
private fun <T> List<T>.transform(
- additionalCondition: (T, PlatformData) -> Boolean = ::alwaysTrue,
- alternativeCondition: (T, PlatformData) -> Boolean = ::alwaysFalse,
- recreate: (T, List<PlatformData>) -> T
+ additionalCondition: (T, SourceSetData) -> Boolean = ::alwaysTrue,
+ alternativeCondition: (T, SourceSetData) -> Boolean = ::alwaysFalse,
+ recreate: (T, List<SourceSetData>) -> T
): Pair<Boolean, List<T>> where T : Documentable, T : WithVisibility {
var changed = false
val values = mapNotNull { t ->
@@ -119,7 +118,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
private fun filterFunctions(
functions: List<DFunction>,
- additionalCondition: (DFunction, PlatformData) -> Boolean = ::alwaysTrue
+ additionalCondition: (DFunction, SourceSetData) -> Boolean = ::alwaysTrue
) =
functions.transform(additionalCondition) { original, filteredPlatforms ->
with(original) {
@@ -129,6 +128,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
isConstructor,
parameters,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
visibility.filtered(filteredPlatforms),
type,
@@ -141,13 +141,13 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
}
}
- private fun hasVisibleAccessorsForPlatform(property: DProperty, data: PlatformData) =
+ private fun hasVisibleAccessorsForPlatform(property: DProperty, data: SourceSetData) =
property.getter?.visibilityForPlatform(data)?.isAllowedInPackage(property.dri.packageName) == true ||
property.setter?.visibilityForPlatform(data)?.isAllowedInPackage(property.dri.packageName) == true
private fun filterProperties(
properties: List<DProperty>,
- additionalCondition: (DProperty, PlatformData) -> Boolean = ::alwaysTrue
+ additionalCondition: (DProperty, SourceSetData) -> Boolean = ::alwaysTrue
): Pair<Boolean, List<DProperty>> =
properties.transform(additionalCondition, ::hasVisibleAccessorsForPlatform) { original, filteredPlatforms ->
with(original) {
@@ -155,6 +155,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
dri,
name,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
visibility.filtered(filteredPlatforms),
type,
@@ -169,16 +170,17 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
}
}
- private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: List<PlatformData>) =
+ private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: List<SourceSetData>) =
entries.mapNotNull { entry ->
- if (filteredPlatforms.containsAll(entry.platformData)) entry
+ if (filteredPlatforms.containsAll(entry.sourceSets)) entry
else {
- val intersection = filteredPlatforms.intersect(entry.platformData).toList()
+ val intersection = filteredPlatforms.intersect(entry.sourceSets).toList()
if (intersection.isEmpty()) null
else DEnumEntry(
entry.dri,
entry.name,
entry.documentation.filtered(intersection),
+ entry.expectPresentInSet.filtered(filteredPlatforms),
filterFunctions(entry.functions) { _, data -> data in intersection }.second,
filterProperties(entry.properties) { _, data -> data in intersection }.second,
filterClasslikes(entry.classlikes) { _, data -> data in intersection }.second,
@@ -190,7 +192,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
private fun filterClasslikes(
classlikeList: List<DClasslike>,
- additionalCondition: (DClasslike, PlatformData) -> Boolean = ::alwaysTrue
+ additionalCondition: (DClasslike, SourceSetData) -> Boolean = ::alwaysTrue
): Pair<Boolean, List<DClasslike>> {
var classlikesListChanged = false
val filteredClasslikes: List<DClasslike> = classlikeList.mapNotNull {
@@ -200,7 +202,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
classlikesListChanged = true
null
} else {
- var modified = platformData.size != filteredPlatforms.size
+ var modified = sourceSets.size != filteredPlatforms.size
val functions =
filterFunctions(functions) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
modified = modified || listModified
@@ -246,6 +248,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
generics,
supertypes.filtered(filteredPlatforms),
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
modifier,
filteredPlatforms,
extra
@@ -254,6 +257,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
name,
dri,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
functions,
properties,
@@ -269,6 +273,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
name,
enumEntries,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
functions,
properties,
@@ -284,6 +289,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
dri,
name,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
functions,
properties,
@@ -299,6 +305,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer {
name,
dri,
documentation.filtered(filteredPlatforms),
+ expectPresentInSet.filtered(filteredPlatforms),
sources.filtered(filteredPlatforms),
functions,
properties,
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
index 9cc09d89..15ffc08a 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
@@ -4,7 +4,6 @@ import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.ExtraProperty
import org.jetbrains.dokka.model.properties.MergeStrategy
-import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
@@ -12,8 +11,8 @@ class InheritorsExtractorTransformer : DocumentableTransformer {
override fun invoke(original: DModule, context: DokkaContext): DModule =
original.generateInheritanceMap().let { inheritanceMap -> original.appendInheritors(inheritanceMap) as DModule }
- private fun <T : Documentable> T.appendInheritors(inheritanceMap: Map<PlatformData, Map<DRI, List<DRI>>>): Documentable =
- InheritorsInfo(PlatformDependent(inheritanceMap.getForDRI(dri))).let { info ->
+ private fun <T : Documentable> T.appendInheritors(inheritanceMap: Map<SourceSetData, Map<DRI, List<DRI>>>): Documentable =
+ InheritorsInfo(inheritanceMap.getForDRI(dri)).let { info ->
when (this) {
is DModule -> copy(packages = packages.map { it.appendInheritors(inheritanceMap) as DPackage })
is DPackage -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
@@ -44,12 +43,12 @@ class InheritorsExtractorTransformer : DocumentableTransformer {
}
}
- private fun InheritorsInfo.isNotEmpty() = this.value.allValues.fold(0) { acc, list -> acc + list.size } > 0
+ private fun InheritorsInfo.isNotEmpty() = this.value.values.fold(0) { acc, list -> acc + list.size } > 0
- private fun Map<PlatformData, Map<DRI, List<DRI>>>.getForDRI(dri: DRI) =
- PlatformDependent(map { (v, k) ->
+ private fun Map<SourceSetData, Map<DRI, List<DRI>>>.getForDRI(dri: DRI) =
+ map { (v, k) ->
v to k[dri]
- }.map { (k, v) -> k to v.orEmpty() }.toMap())
+ }.map { (k, v) -> k to v.orEmpty() }.toMap()
private fun DModule.generateInheritanceMap() =
getInheritanceEntriesRec().filterNot { it.second.isEmpty() }.groupBy({ it.first }) { it.second }
@@ -58,26 +57,24 @@ class InheritorsExtractorTransformer : DocumentableTransformer {
.groupBy({ it.first }) { it.second }.map { (k2, v2) -> k2 to v2.flatten() }.toMap()
}.filter { it.second.values.isNotEmpty() }.toMap()
- private fun <T : Documentable> T.getInheritanceEntriesRec(): List<Pair<PlatformData, List<Pair<DRI, DRI>>>> =
+ private fun <T : Documentable> T.getInheritanceEntriesRec(): List<Pair<SourceSetData, List<Pair<DRI, DRI>>>> =
this.toInheritanceEntries() + children.flatMap { it.getInheritanceEntriesRec() }
private fun <T : Documentable> T.toInheritanceEntries() =
(this as? WithSupertypes)?.let {
- it.supertypes.map.map { (k, v) -> k to v.map { it to dri } }
+ it.supertypes.map { (k, v) -> k to v.map { it to dri } }
}.orEmpty()
}
-class InheritorsInfo(val value: PlatformDependent<List<DRI>>) : ExtraProperty<Documentable> {
+class InheritorsInfo(val value: SourceSetDependent<List<DRI>>) : ExtraProperty<Documentable> {
companion object : ExtraProperty.Key<Documentable, InheritorsInfo> {
override fun mergeStrategyFor(left: InheritorsInfo, right: InheritorsInfo): MergeStrategy<Documentable> =
MergeStrategy.Replace(
InheritorsInfo(
- PlatformDependent(
- (left.value.map.entries.toList() + right.value.map.entries.toList())
+ (left.value.entries.toList() + right.value.entries.toList())
.groupBy({ it.key }) { it.value }
.map { (k, v) -> k to v.flatten() }.toMap()
- )
)
)
}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
index b69c43d3..a886494e 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
@@ -1,9 +1,9 @@
package org.jetbrains.dokka.base.transformers.documentables
import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.model.PlatformDependent
+import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.DocumentationNode
-import org.jetbrains.dokka.pages.PlatformData
+import org.jetbrains.dokka.model.sourceSet
import org.jetbrains.dokka.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
@@ -12,14 +12,14 @@ import java.nio.file.Files
import java.nio.file.Paths
-internal object ModuleAndPackageDocumentationTransformer : PreMergeDocumentableTransformer {
+internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer {
- override fun invoke(original: List<DModule>, context: DokkaContext): List<DModule> {
+ override fun invoke(original: List<DModule>): List<DModule> {
val modulesAndPackagesDocumentation =
context.configuration.passesConfigurations
.map {
- Pair(it.moduleName, it.platformData) to
+ Pair(it.moduleName, context.sourceSet(it)) to
it.includes.map { Paths.get(it) }
.also {
it.forEach {
@@ -50,10 +50,10 @@ internal object ModuleAndPackageDocumentationTransformer : PreMergeDocumentableT
return original.map { module ->
val moduleDocumentation =
- module.platformData.mapNotNull { pd ->
+ module.sourceSets.mapNotNull { pd ->
val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)]
val facade = context.platforms[pd]?.facade
- ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.name}") }
+ ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetName}") }
try {
doc?.get("Module")?.get(module.name)?.run {
pd to MarkdownParser(
@@ -68,15 +68,15 @@ internal object ModuleAndPackageDocumentationTransformer : PreMergeDocumentableT
}
}.toMap()
- val packagesDocumentation = module.packages.map { dPackage ->
- dPackage.name to dPackage.platformData.mapNotNull { platformData ->
- val doc = modulesAndPackagesDocumentation[Pair(module.name, platformData)]
- val facade = context.platforms[platformData]?.facade
- ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${platformData.name}") }
- val descriptor = facade.resolveSession.getPackageFragment(FqName(dPackage.name))
- ?: return@mapNotNull null.also { context.logger.warn("Could not find descriptor for ${dPackage.name}") }
- doc?.get("Package")?.get(dPackage.name)?.run {
- platformData to MarkdownParser(
+ val packagesDocumentation = module.packages.map {
+ it.name to it.sourceSets.mapNotNull { pd ->
+ val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)]
+ val facade = context.platforms[pd]?.facade
+ ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetName}") }
+ val descriptor = facade.resolveSession.getPackageFragment(FqName(it.name))
+ ?: return@mapNotNull null.also { context.logger.warn("Could not find descriptor for $") }
+ doc?.get("Package")?.get(it.name)?.run {
+ pd to MarkdownParser(
facade,
descriptor,
context.logger
@@ -86,13 +86,11 @@ internal object ModuleAndPackageDocumentationTransformer : PreMergeDocumentableT
}.toMap()
module.copy(
- documentation = module.documentation.let { mergeDocumentation(it.map, moduleDocumentation) },
+ documentation = mergeDocumentation(module.documentation, moduleDocumentation),
packages = module.packages.map {
val packageDocumentation = packagesDocumentation[it.name]
if (packageDocumentation != null && packageDocumentation.isNotEmpty())
- it.copy(documentation = it.documentation.let { value ->
- mergeDocumentation(value.map, packageDocumentation)
- })
+ it.copy(documentation = mergeDocumentation(it.documentation, packageDocumentation))
else
it
}
@@ -100,10 +98,10 @@ internal object ModuleAndPackageDocumentationTransformer : PreMergeDocumentableT
}
}
- private fun mergeDocumentation(origin: Map<PlatformData, DocumentationNode>, new: Map<PlatformData, DocumentationNode>) = PlatformDependent(
+ private fun mergeDocumentation(origin: Map<SourceSetData, DocumentationNode>, new: Map<SourceSetData, DocumentationNode>) =
(origin.asSequence() + new.asSequence())
.distinct()
.groupBy({ it.key }, { it.value })
.mapValues { (_, values) -> DocumentationNode(values.flatMap { it.children }) }
- )
+
}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
index 778e0498..cb74441e 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.transformers.pages.comments
+import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.DocTag
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.*
@@ -8,7 +9,7 @@ interface CommentsToContentConverter {
fun buildContent(
docTag: DocTag,
dci: DCI,
- platforms: Set<PlatformData>,
+ platforms: Set<SourceSetData>,
styles: Set<Style> = emptySet(),
extras: PropertyContainer<ContentNode> = PropertyContainer.empty()
): List<ContentNode>
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
index 4e65bae9..85391549 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.transformers.pages.comments
+import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.*
@@ -8,19 +9,19 @@ object DocTagToContentConverter : CommentsToContentConverter {
override fun buildContent(
docTag: DocTag,
dci: DCI,
- platforms: Set<PlatformData>,
+ sourceSets: Set<SourceSetData>,
styles: Set<Style>,
extra: PropertyContainer<ContentNode>
): List<ContentNode> {
fun buildChildren(docTag: DocTag, newStyles: Set<Style> = emptySet(), newExtras: SimpleAttr? = null) =
docTag.children.flatMap {
- buildContent(it, dci, platforms, styles + newStyles, newExtras?.let { extra + it } ?: extra)
+ buildContent(it, dci, sourceSets, styles + newStyles, newExtras?.let { extra + it } ?: extra)
}
fun buildTableRows(rows: List<DocTag>, newStyle: Style): List<ContentGroup> =
rows.flatMap {
- buildContent(it, dci, platforms, styles + newStyle, extra) as List<ContentGroup>
+ buildContent(it, dci, sourceSets, styles + newStyle, extra) as List<ContentGroup>
}
fun buildHeader(level: Int) =
@@ -29,7 +30,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildChildren(docTag),
level,
dci,
- platforms,
+ sourceSets,
styles
)
)
@@ -40,7 +41,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildChildren(docTag),
ordered,
dci,
- platforms,
+ sourceSets,
styles,
((PropertyContainer.empty<ContentNode>()) + SimpleAttr("start", start.toString()))
)
@@ -48,7 +49,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
fun buildNewLine() = listOf(
ContentBreakLine(
- platforms
+ sourceSets
)
)
@@ -71,7 +72,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildChildren(docTag),
docTag.params.get("href")!!,
dci,
- platforms,
+ sourceSets,
styles
)
)
@@ -83,7 +84,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
setOf(docTag.dri),
ContentKind.Symbol
),
- platforms,
+ sourceSets,
styles
)
)
@@ -92,7 +93,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildChildren(docTag),
"",
dci,
- platforms,
+ sourceSets,
styles
)
)
@@ -101,7 +102,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildChildren(docTag),
"",
dci,
- platforms,
+ sourceSets,
styles
)
)
@@ -110,7 +111,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
address = docTag.params["href"]!!,
altText = docTag.params["alt"],
dci = dci,
- platforms = platforms,
+ sourceSets = sourceSets,
style = styles,
extra = extra
)
@@ -119,7 +120,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
ContentText(
"",
dci,
- platforms,
+ sourceSets,
setOf()
)
)
@@ -127,7 +128,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
ContentText(
docTag.body,
dci,
- platforms,
+ sourceSets,
styles
)
)
@@ -137,7 +138,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
buildTableRows(docTag.children.filterIsInstance<Th>(), CommentTable),
buildTableRows(docTag.children.filterIsInstance<Tr>(), CommentTable),
dci,
- platforms,
+ sourceSets,
styles + CommentTable
)
)
@@ -145,10 +146,10 @@ object DocTagToContentConverter : CommentsToContentConverter {
is Tr -> listOf(
ContentGroup(
docTag.children.map {
- ContentGroup(buildChildren(it), dci, platforms, styles, extra)
+ ContentGroup(buildChildren(it), dci, sourceSets, styles, extra)
},
dci,
- platforms,
+ sourceSets,
styles
)
)
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 fb904f47..31e79555 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
@@ -32,6 +32,6 @@ object SameMethodNamePageMergerStrategy : PageMergerStrategy {
}
fun asGroup(dci: DCI, nodes: List<ContentNode>): ContentGroup =
- nodes.first().let { ContentGroup(nodes, dci, it.platforms, it.style, it.extra) }
+ nodes.first().let { ContentGroup(nodes, dci, it.sourceSets, it.style, it.extra) }
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
index 78fc4d33..9b04af40 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
@@ -8,8 +8,10 @@ import org.jetbrains.dokka.analysis.AnalysisEnvironment
import org.jetbrains.dokka.analysis.DokkaResolutionFacade
import org.jetbrains.dokka.base.renderers.platforms
import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.Sample
import org.jetbrains.dokka.model.properties.PropertyContainer
+import org.jetbrains.dokka.model.sourceSet
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -31,16 +33,16 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
val analysis = setUpAnalysis(context)
return input.transformContentPagesTree { page ->
- page.documentable?.documentation?.allEntries?.fold(page) { acc, entry ->
- entry.second.children.filterIsInstance<Sample>().fold(acc) { acc, sample ->
- acc.modified(content = acc.content.addSample(page, entry.first, sample.name, analysis))
+ page.documentable?.documentation?.entries?.fold(page) { acc, entry ->
+ entry.value.children.filterIsInstance<Sample>().fold(acc) { acc, sample ->
+ acc.modified(content = acc.content.addSample(page, entry.key, sample.name, analysis))
}
} ?: page
}
}
private fun setUpAnalysis(context: DokkaContext) = context.configuration.passesConfigurations.map {
- it.platformData to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run {
+ context.sourceSet(it) to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre())
}
@@ -56,12 +58,9 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
}
}.toMap()
- private fun ContentNode.addSample(contentPage: ContentPage, platform: PlatformData?, fqName: String, analysis: Map<PlatformData, EnvironmentAndFacade>): ContentNode {
- val facade = if(platform == null) {
- analysis.entries.find { it.key.platformType.name == "common" }?.value
- } else {
- analysis[platform]
- }?.facade ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform?.name ?: "expect"}") }
+ private fun ContentNode.addSample(contentPage: ContentPage, platform: SourceSetData, fqName: String, analysis: Map<SourceSetData, EnvironmentAndFacade>): ContentNode {
+ val facade = analysis[platform]?.facade ?:
+ return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleName}")}
val psiElement = fqNameToPsiElement(facade, fqName) ?:
return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") }
val imports = processImports(psiElement) // TODO: Process somehow imports. Maybe just attach them at the top of each body
@@ -96,13 +95,13 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
return DescriptorToSourceUtils.descriptorToDeclaration(symbol)
}
- private fun contentCode(platforms: List<PlatformData>, dri: Set<DRI>, content: String, language: String) =
+ private fun contentCode(sourceSets: List<SourceSetData>, dri: Set<DRI>, content: String, language: String) =
ContentCode(
children = listOf(
ContentText(
text = content,
dci = DCI(dri, ContentKind.BriefComment),
- platforms = platforms.toSet(),
+ sourceSets = sourceSets.toSet(),
style = emptySet(),
extra = PropertyContainer.empty()
)
@@ -110,7 +109,7 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
language = language,
extra = PropertyContainer.empty(),
dci = DCI(dri, ContentKind.Source),
- platforms = platforms.toSet(),
+ sourceSets = sourceSets.toSet(),
style = emptySet()
)
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
index fa73e757..876326d1 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -5,9 +5,12 @@ import com.intellij.psi.PsiDocumentManager
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.model.DescriptorDocumentableSource
+import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.DocumentableSource
import org.jetbrains.dokka.model.PsiDocumentableSource
import org.jetbrains.dokka.model.WithExpectActual
+import org.jetbrains.dokka.model.properties.PropertyContainer
+import org.jetbrains.dokka.model.sourceSet
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -30,11 +33,11 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
}
private fun getSourceLinks() = context.configuration.passesConfigurations
- .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, it.platformData) } }
+ .flatMap { it.sourceLinks.map { sl -> SourceLink(sl, context.sourceSetCache.getSourceSet(it)) } }
private fun resolveSources(documentable: WithExpectActual) = documentable.sources
.mapNotNull { entry ->
- getSourceLinks().find { entry.value.path.contains(it.path) && it.platformData == entry.key }?.let {
+ getSourceLinks().find { entry.value.path.contains(it.path) && it.sourceSetData == entry.key }?.let {
Pair(
entry.key,
entry.value.toLink(it)
@@ -42,7 +45,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
}
}
- private fun ContentPage.addSourcesContent(sources: List<Pair<PlatformData, String>>) = builder
+ private fun ContentPage.addSourcesContent(sources: List<Pair<SourceSetData, String>>) = builder
.buildSourcesContent(this, sources)
.let {
this.modified(
@@ -52,10 +55,10 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
private fun PageContentBuilder.buildSourcesContent(
node: ContentPage,
- sources: List<Pair<PlatformData, String>>
+ sources: List<Pair<SourceSetData, String>>
) = contentFor(
node.dri.first(),
- node.documentable!!.platformData.toSet()
+ node.documentable!!.sourceSets.toSet()
) {
header(2) { text("Sources") }
+ContentTable(
@@ -66,7 +69,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
}
},
DCI(node.dri, ContentKind.Source),
- node.documentable!!.platformData.toSet(),
+ node.documentable!!.sourceSets.toSet(),
style = emptySet()
)
}
@@ -94,7 +97,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
else -> ContentGroup(
children = listOf(this, table),
extra = this.extra,
- platforms = this.platforms,
+ sourceSets = this.sourceSets,
dci = this.dci,
style = this.style
)
@@ -107,8 +110,8 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
}
}
-data class SourceLink(val path: String, val url: String, val lineSuffix: String?, val platformData: PlatformData) {
- constructor(sourceLinkDefinition: DokkaConfiguration.SourceLinkDefinition, platformData: PlatformData) : this(
- sourceLinkDefinition.path, sourceLinkDefinition.url, sourceLinkDefinition.lineSuffix, platformData
+data class SourceLink(val path: String, val url: String, val lineSuffix: String?, val sourceSetData: SourceSetData) {
+ constructor(sourceLinkDefinition: DokkaConfiguration.SourceLinkDefinition, sourceSetData: SourceSetData) : this(
+ sourceLinkDefinition.path, sourceLinkDefinition.url, sourceLinkDefinition.lineSuffix, sourceSetData
)
} \ No newline at end of file