diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-05-20 11:58:39 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-05-26 11:33:18 +0200 |
commit | 2ef03aa5074e35bb831b5fcfd8a0e88dfe45cd7c (patch) | |
tree | 968791d5a20546bb1f039045758ea53d5abce19d /plugins/base/src/main/kotlin/transformers/documentables | |
parent | 22f0a5b4b3c566a17062ab5a921d11d221a6c78b (diff) | |
download | dokka-2ef03aa5074e35bb831b5fcfd8a0e88dfe45cd7c.tar.gz dokka-2ef03aa5074e35bb831b5fcfd8a0e88dfe45cd7c.tar.bz2 dokka-2ef03aa5074e35bb831b5fcfd8a0e88dfe45cd7c.zip |
Refactor type aliases
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/documentables')
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt index cab4a9d2..80d01780 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt @@ -4,21 +4,21 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer +import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer -class ActualTypealiasAdder(val context: DokkaContext) : PreMergeDocumentableTransformer { - override fun invoke(modules: List<DModule>) = modules.map { it.mergeTypealiases() } +class ActualTypealiasAdder : DocumentableTransformer { + + override fun invoke(modules: DModule, context: DokkaContext) = modules.generateTypealiasesMap().let { aliases -> + modules.copy(packages = modules.packages.map { it.copy(classlikes = addActualTypeAliasToClasslikes(it.classlikes, aliases)) }) + } + + private fun DModule.generateTypealiasesMap(): Map<DRI, DTypeAlias> = + packages.flatMap { pkg -> + pkg.typealiases.map { typeAlias -> + typeAlias.dri to typeAlias + } + }.toMap() - private fun DModule.mergeTypealiases(): DModule = copy(packages = packages.map { pkg -> - if (pkg.typealiases.isEmpty()) { - pkg - } else { - val typealiases = pkg.typealiases.map { it.dri to it }.toMap() - pkg.copy( - classlikes = addActualTypeAliasToClasslikes(pkg.classlikes, typealiases) - ) - } - }) private fun addActualTypeAliasToClasslikes( elements: Iterable<DClasslike>, @@ -56,7 +56,7 @@ class ActualTypealiasAdder(val context: DokkaContext) : PreMergeDocumentableTran typealiases ) else -> throw IllegalStateException("${it::class.qualifiedName} ${it.name} cannot have extra added") - } as List<DClasslike> + } } private fun <T> addActualTypeAlias( @@ -70,7 +70,16 @@ class ActualTypealiasAdder(val context: DokkaContext) : PreMergeDocumentableTran element.extra + ActualTypealias( mapOf(ta.sourceSets.single() to ta.underlyingType.values.single()) ) - ) + ).let { + when(it) { + is DClass -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) + is DEnum -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) + is DInterface -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) + is DObject -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) + is DAnnotation -> it.copy(sourceSets = element.sourceSets + ta.sourceSets) + else -> throw IllegalStateException("${it::class.qualifiedName} ${it.name} cannot have copy its sourceSets") + } + } as T } ?: element } else { element |