aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt34
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt44
2 files changed, 48 insertions, 30 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
index 8c014a29..9cc09d89 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
@@ -17,21 +17,35 @@ class InheritorsExtractorTransformer : DocumentableTransformer {
when (this) {
is DModule -> copy(packages = packages.map { it.appendInheritors(inheritanceMap) as DPackage })
is DPackage -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- is DClass -> copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- is DEnum -> copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- is DInterface -> copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ is DClass -> if (info.isNotEmpty()) {
+ copy(
+ extra = extra + info,
+ classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ } else {
+ copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ }
+ is DEnum -> if (info.isNotEmpty()) {
+ copy(
+ extra = extra + info,
+ classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ } else {
+ copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ }
+ is DInterface -> if (info.isNotEmpty()) {
+ copy(
+ extra = extra + info,
+ classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ } else {
+ copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
+ }
is DObject -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
is DAnnotation -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
else -> this
}
}
+ private fun InheritorsInfo.isNotEmpty() = this.value.allValues.fold(0) { acc, list -> acc + list.size } > 0
+
private fun Map<PlatformData, Map<DRI, List<DRI>>>.getForDRI(dri: DRI) =
PlatformDependent(map { (v, k) ->
v to k[dri]
@@ -42,7 +56,7 @@ class InheritorsExtractorTransformer : DocumentableTransformer {
.map { (k, v) ->
k to v.flatMap { p -> p.groupBy({ it.first }) { it.second }.toList() }
.groupBy({ it.first }) { it.second }.map { (k2, v2) -> k2 to v2.flatten() }.toMap()
- }.filter{ it.second.values.isEmpty() }.toMap()
+ }.filter { it.second.values.isNotEmpty() }.toMap()
private fun <T : Documentable> T.getInheritanceEntriesRec(): List<Pair<PlatformData, List<Pair<DRI, DRI>>>> =
this.toInheritanceEntries() + children.flatMap { it.getInheritanceEntriesRec() }
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index e1bce565..a70f22d8 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -1,13 +1,16 @@
package org.jetbrains.dokka.base.translators.documentables
import org.jetbrains.dokka.base.signatures.SignatureProvider
+import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder.DocumentableContentBuilder
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.*
+import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.utilities.DokkaLogger
+import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
@@ -129,26 +132,27 @@ open class DefaultPageCreator(
}
}
}
- // TODO: Fix this after fixing InheritorsExtractorTransformer
-// (s as? WithExtraProperties<Documentable>)?.let { it.extra[InheritorsInfo] }?.let { inheritors ->
-// val map = inheritors.value.map
-// if (map.values.any()) {
-// header(2) { text("Subtypes") }
-// +ContentTable(
-// emptyList(),
-// map.entries.groupBy({ it.value }, { it.key }).map { (types, platforms) ->
-// buildGroup(dri, platforms.toSet(), ContentKind.Subtypes) {
-// types.map {
-// link(it.toString(), it)
-// }
-// }
-// },
-// DCI(setOf(dri), ContentKind.Subtypes),
-// platformData.toSet(),
-// style = emptySet()
-// )
-// }
-// }
+ s.safeAs<WithExtraProperties<Documentable>>()?.let { it.extra[InheritorsInfo] }?.let { inheritors ->
+ val map = inheritors.value.map.filter { it.value.isNotEmpty() }
+ if (map.values.any()) {
+ header(2) { text("Inheritors") }
+ +ContentTable(
+ emptyList(),
+ map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } }
+ .groupBy({ it.second }, { it.first }).map { (classlike, platforms) ->
+ buildGroup(dri, platforms.toSet(), ContentKind.Inheritors) {
+ link(
+ classlike.classNames?.substringBeforeLast(".") ?: classlike.toString()
+ .also { logger.warn("No class name found for DRI $classlike") }, classlike
+ )
+ }
+ },
+ DCI(setOf(dri), ContentKind.Inheritors),
+ platformData.toSet(),
+ style = emptySet()
+ )
+ }
+ }
}
protected open fun contentForEnumEntry(e: DEnumEntry) = contentBuilder.contentFor(e) {