aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-01-23 11:10:37 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-10 12:16:32 +0100
commit612e8c2f6f1b52f19c6ae51aa3d5655dfb43ba0c (patch)
treeb801dba1dd61c17d0d67b91c5f093151955d0e2b /core/src
parentf7c67c2ade8b56c6556ec59d9c0adf8643a8e566 (diff)
downloaddokka-612e8c2f6f1b52f19c6ae51aa3d5655dfb43ba0c.tar.gz
dokka-612e8c2f6f1b52f19c6ae51aa3d5655dfb43ba0c.tar.bz2
dokka-612e8c2f6f1b52f19c6ae51aa3d5655dfb43ba0c.zip
formatting
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/model/Documentable.kt120
-rw-r--r--core/src/main/kotlin/pages/PageBuilder.kt64
-rw-r--r--core/src/main/kotlin/pages/PageContentBuilder.kt17
-rw-r--r--core/src/main/kotlin/pages/PageNodes.kt10
-rw-r--r--core/src/main/kotlin/renderers/html/HtmlRenderer.kt4
-rw-r--r--core/src/main/kotlin/transformers/descriptors/DefaultDescriptorToDocumentationTranslator.kt61
-rw-r--r--core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt59
7 files changed, 257 insertions, 78 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 7add2c3f..86ba24b7 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -1,9 +1,10 @@
package org.jetbrains.dokka.model
-import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.dokka.transformers.descriptors.KotlinTypeWrapper
import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.pages.PlatformData
+import org.jetbrains.dokka.transformers.descriptors.KotlinClassKindTypes
+import org.jetbrains.dokka.transformers.descriptors.KotlinTypeWrapper
class Module(override val name: String, val packages: List<Package>) : Documentable() {
override val dri: DRI = DRI.topLevel
@@ -15,7 +16,7 @@ class Package(
override val dri: DRI,
override val functions: List<Function>,
override val properties: List<Property>,
- override val classes: List<Class>,
+ override val classlikes: List<Classlike>,
override val extra: MutableSet<Extra> = mutableSetOf()
) : ScopeNode() {
override val name = dri.packageName.orEmpty()
@@ -24,16 +25,79 @@ class Package(
class Class(
override val dri: DRI,
override val name: String,
- val kind: ClassKind,
+ override val kind: ClassKind,
val constructors: List<Function>,
override val functions: List<Function>,
override val properties: List<Property>,
- override val classes: List<Class>,
+ override val classlikes: List<Classlike>,
override val expected: ClassPlatformInfo?,
override val actual: List<ClassPlatformInfo>,
override val extra: MutableSet<Extra> = mutableSetOf()
-) : ScopeNode() {
- val inherited by lazy { platformInfo.mapNotNull { (it as? ClassPlatformInfo)?.inherited }.flatten() }
+) : Classlike(
+ name = name,
+ dri = dri,
+ kind = kind,
+ functions = functions,
+ properties = properties,
+ classlikes = classlikes,
+ expected = expected,
+ actual = actual,
+ extra = extra
+)
+
+class Enum(
+ override val dri: DRI,
+ override val name: String,
+ val entries: List<EnumEntry>,
+ val constructors: List<Function>,
+ override val functions: List<Function> = emptyList(),
+ override val properties: List<Property> = emptyList(),
+ override val classlikes: List<Classlike> = emptyList(),
+ override val expected: ClassPlatformInfo? = null,
+ override val actual: List<ClassPlatformInfo>,
+ override val extra: MutableSet<Extra> = mutableSetOf()
+) : Classlike(dri = dri, name = name, kind = KotlinClassKindTypes.ENUM_CLASS, actual = actual) {
+ constructor(c: Classlike, entries: List<EnumEntry>, ctors: List<Function>) : this(
+ dri = c.dri,
+ name = c.name,
+ entries = entries,
+ constructors = ctors,
+ functions = c.functions,
+ properties = c.properties,
+ classlikes = c.classlikes,
+ expected = c.expected,
+ actual = c.actual,
+ extra = c.extra
+ )
+
+ override val children: List<Documentable>
+ get() = entries
+}
+
+class EnumEntry(
+ override val dri: DRI,
+ override val name: String,
+ override val expected: ClassPlatformInfo? = null,
+ override val actual: List<ClassPlatformInfo>,
+ override val extra: MutableSet<Extra> = mutableSetOf()
+) : Classlike(
+ dri = dri,
+ name = name,
+ actual = actual,
+ expected = expected,
+ extra = extra,
+ kind = KotlinClassKindTypes.ENUM_ENTRY
+) {
+ constructor(c: Classlike) : this(
+ dri = c.dri,
+ name = c.name,
+ actual = c.actual,
+ expected = c.expected,
+ extra = c.extra
+ )
+
+ override val children: List<Parameter>
+ get() = emptyList()
}
class Function(
@@ -83,7 +147,8 @@ interface PlatformInfo {
class BasePlatformInfo(
override val documentationNode: DocumentationNode,
- override val platformData: List<PlatformData>) : PlatformInfo {
+ override val platformData: List<PlatformData>
+) : PlatformInfo {
override fun equals(other: Any?): Boolean =
other is PlatformInfo && documentationNode == other.documentationNode
@@ -94,7 +159,8 @@ class BasePlatformInfo(
class ClassPlatformInfo(
val info: PlatformInfo,
- val inherited: List<DRI>) : PlatformInfo by info
+ val inherited: List<DRI>
+) : PlatformInfo by info
abstract class Documentable {
open val expected: PlatformInfo? = null
@@ -114,27 +180,45 @@ abstract class Documentable {
override fun hashCode() = dri.hashCode()
+
+ val commentsData: List<DocumentationNode>
+ get() = platformInfo.map { it.documentationNode }
+
val briefDocTagString: String
get() =
platformInfo
- .firstOrNull()
- ?.documentationNode
- ?.children
- ?.firstOrNull()
- ?.root
- ?.docTagSummary()
- ?.shorten(40) ?: ""
+ .firstOrNull()
+ ?.documentationNode
+ ?.children
+ ?.firstOrNull()
+ ?.root
+ ?.docTagSummary()
+ ?.shorten(40) ?: ""
open val extra: MutableSet<Extra> = mutableSetOf()
}
+abstract class Classlike(
+ override val dri: DRI,
+ override val name: String,
+ open val kind: ClassKind,
+ override val functions: List<Function> = emptyList(),
+ override val properties: List<Property> = emptyList(),
+ override val classlikes: List<Classlike> = emptyList(),
+ override val expected: ClassPlatformInfo? = null,
+ override val actual: List<ClassPlatformInfo>,
+ override val extra: MutableSet<Extra> = mutableSetOf()
+) : ScopeNode() {
+ val inherited by lazy { platformInfo.mapNotNull { (it as? ClassPlatformInfo)?.inherited }.flatten() }
+}
+
abstract class ScopeNode : Documentable() {
abstract val functions: List<Function>
abstract val properties: List<Property>
- abstract val classes: List<Class>
+ abstract val classlikes: List<Classlike>
override val children: List<Documentable>
- get() = functions + properties + classes
+ get() = functions + properties + classlikes
}
abstract class CallableNode : Documentable() {
diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt
index e8930fae..003cc815 100644
--- a/core/src/main/kotlin/pages/PageBuilder.kt
+++ b/core/src/main/kotlin/pages/PageBuilder.kt
@@ -1,8 +1,9 @@
package org.jetbrains.dokka.pages
-import org.jetbrains.dokka.model.doc.TagWrapper
import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.Enum
import org.jetbrains.dokka.model.Function
+import org.jetbrains.dokka.model.doc.TagWrapper
class DefaultPageBuilder(
override val rootContentGroup: RootContentBuilder
@@ -13,14 +14,21 @@ class DefaultPageBuilder(
override fun pageForPackage(p: Package) =
PackagePageNode(p.name, contentForPackage(p), setOf(p.dri), p,
- p.classes.map { pageForClass(it) } +
+ p.classlikes.map { pageForClasslike(it) } +
p.functions.map { pageForMember(it) })
- override fun pageForClass(c: Class): ClassPageNode =
- ClassPageNode(c.name, contentForClass(c), setOf(c.dri), c,
- c.constructors.map { pageForMember(it) } +
- c.classes.map { pageForClass(it) } +
+ override fun pageForClasslike(c: Classlike): ClasslikePageNode {
+ val constructors = when (c) {
+ is Class -> c.constructors
+ is Enum -> c.constructors
+ else -> emptyList()
+ }
+
+ return ClasslikePageNode(c.name, contentForClasslike(c), setOf(c.dri), c,
+ constructors.map { pageForMember(it) } +
+ c.classlikes.map { pageForClasslike(it) } +
c.functions.map { pageForMember(it) })
+ }
override fun pageForMember(m: CallableNode): MemberPageNode =
when (m) {
@@ -43,7 +51,7 @@ class DefaultPageBuilder(
private fun contentForPackage(p: Package) = group(p) {
header(1) { text("Package ${p.name}") }
- block("Types", 2, ContentKind.Properties, p.classes, p.platformData) {
+ block("Types", 2, ContentKind.Properties, p.classlikes, p.platformData) {
link(it.name, it.dri)
text(it.briefDocTagString)
}
@@ -54,6 +62,12 @@ class DefaultPageBuilder(
}
}
+ private fun contentForClasslike(c: Classlike): ContentGroup = when (c) {
+ is Class -> contentForClass(c)
+ is Enum -> contentForEnum(c)
+ else -> throw IllegalStateException("$c should not be present here")
+ }
+
private fun contentForClass(c: Class) = group(c) {
header(1) { text(c.name) }
c.inherited.takeIf { it.isNotEmpty() }?.let {
@@ -69,7 +83,32 @@ class DefaultPageBuilder(
comment(it.root)
text("\n")
}
+
+ block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) {
+ link(it.name, it.dri)
+ signature(it)
+ text(it.briefDocTagString)
+ }
+ block("Properties", 2, ContentKind.Properties, c.properties, c.platformData) {
+ link(it.name, it.dri)
+ text(it.briefDocTagString)
+ }
+ }
+ }
+
+ fun contentForEnum(c: Enum): ContentGroup = group(c) {
+ header(1) { text("enum ${c.name}") }
+
+ block("Entries", 2, ContentKind.Properties, c.entries, c.platformData) { entry ->
+ link(entry.name, entry.dri)
+ contentForComments(entry)
+ }
+
+ c.inherited.takeIf { it.isNotEmpty() }?.let {
+ header(2) { text("SuperInterfaces") }
+ linkTable(it)
}
+ contentForComments(c)
block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) {
link(it.name, it.dri)
signature(it)
@@ -86,6 +125,15 @@ class DefaultPageBuilder(
}
}
+ private fun PageContentBuilder.contentForComments(d: Documentable) =
+ d.commentsData.forEach {
+ it.children.forEach {
+ header(3) { text(it.toHeaderString()) }
+ comment(it.root)
+ text("\n")
+ }
+ }
+
private fun contentForFunction(f: Function) = group(f) {
header(1) { text(f.name) }
signature(f)
@@ -115,5 +163,5 @@ interface PageBuilder {
fun pageForModule(m: Module): ModulePageNode
fun pageForPackage(p: Package): PackagePageNode
fun pageForMember(m: CallableNode): MemberPageNode
- fun pageForClass(c: Class): ClassPageNode
+ fun pageForClasslike(c: Classlike): ClasslikePageNode
} \ No newline at end of file
diff --git a/core/src/main/kotlin/pages/PageContentBuilder.kt b/core/src/main/kotlin/pages/PageContentBuilder.kt
index efe23b5a..d5ffe27a 100644
--- a/core/src/main/kotlin/pages/PageContentBuilder.kt
+++ b/core/src/main/kotlin/pages/PageContentBuilder.kt
@@ -1,12 +1,12 @@
package org.jetbrains.dokka.pages
-import org.jetbrains.dokka.model.doc.DocTag
-import org.jetbrains.dokka.utilities.DokkaLogger
+import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.model.Parameter
import org.jetbrains.dokka.model.TypeWrapper
-import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.doc.DocTag
+import org.jetbrains.dokka.utilities.DokkaLogger
class DefaultPageContentBuilder(
private val dri: Set<DRI>,
@@ -169,10 +169,9 @@ private fun PageContentBuilder.type(t: TypeWrapper) {
else if (t.constructorNamePathSegments.isNotEmpty() && t.dri == null)
text(t.toString())
else (this as? DefaultPageContentBuilder)?.let {
- logger.error("type $t cannot be resolved")
- text("???")
- }
-
+ logger.error("type $t cannot be resolved")
+ text("???")
+ }
list(t.arguments, prefix = "<", suffix = ">") {
type(it)
}
@@ -199,8 +198,8 @@ interface PageContentBuilder {
fun header(level: Int, block: PageContentBuilderFunction)
fun <T> list(
elements: List<T>,
- prefix: String = "",
- suffix: String = "",
+ prefix: String = "",
+ suffix: String = "",
separator: String = ",",
operation: PageContentBuilder.(T) -> Unit
)
diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt
index 73d63cd7..6b67a734 100644
--- a/core/src/main/kotlin/pages/PageNodes.kt
+++ b/core/src/main/kotlin/pages/PageNodes.kt
@@ -47,7 +47,7 @@ abstract class RootPageNode: PageNode {
fun transformContentPagesTree(operation: (ContentPage) -> ContentPage) = transformPageNodeTree {
if (it is ContentPage) operation(it) else it
- } as RootPageNode
+ }
private fun PageNode.transformNode(operation: (PageNode) -> PageNode): PageNode =
operation(this).let { newNode ->
@@ -105,7 +105,7 @@ class PackagePageNode(
else PackagePageNode(name, content, dri, documentable, children, embeddedResources)
}
-class ClassPageNode(
+class ClasslikePageNode(
override val name: String,
override val content: ContentNode,
override val dri: Set<DRI>,
@@ -113,7 +113,7 @@ class ClassPageNode(
override val children: List<PageNode>,
override val embeddedResources: List<String> = listOf()
) : ContentPage {
- override fun modified(name: String, children: List<PageNode>): ClassPageNode =
+ override fun modified(name: String, children: List<PageNode>): ClasslikePageNode =
modified(name = name, content = this.content, children = children)
override fun modified(
@@ -121,9 +121,9 @@ class ClassPageNode(
content: ContentNode,
embeddedResources: List<String>,
children: List<PageNode>
- ): ClassPageNode =
+ ): ClasslikePageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
- else ClassPageNode(name, content, dri, documentable, children, embeddedResources)
+ else ClasslikePageNode(name, content, dri, documentable, children, embeddedResources)
}
class MemberPageNode(
diff --git a/core/src/main/kotlin/renderers/html/HtmlRenderer.kt b/core/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 27197ce6..47f5d066 100644
--- a/core/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/core/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -145,7 +145,7 @@ open class HtmlRenderer(
super.renderPage(page)
if (page is ContentPage) {
pageList.add(
- """{ "name": "${page.name}", ${if (page is ClassPageNode) "\"class\": \"${page.name}\"," else ""} "location": "${locationProvider.resolve(
+ """{ "name": "${page.name}", ${if (page is ClasslikePageNode) "\"class\": \"${page.name}\"," else ""} "location": "${locationProvider.resolve(
page
)}" }"""
)
@@ -205,7 +205,7 @@ fun List<HTMLMetadata>.joinAttr() = joinToString(" ") { it.key + "=" + it.value
private fun PageNode.pageKind() = when (this) {
is PackagePageNode -> "package"
- is ClassPageNode -> "class"
+ is ClasslikePageNode -> "class"
is MemberPageNode -> when (this.documentable) {
is Function -> "function"
else -> "other"
diff --git a/core/src/main/kotlin/transformers/descriptors/DefaultDescriptorToDocumentationTranslator.kt b/core/src/main/kotlin/transformers/descriptors/DefaultDescriptorToDocumentationTranslator.kt
index 54762303..651bd223 100644
--- a/core/src/main/kotlin/transformers/descriptors/DefaultDescriptorToDocumentationTranslator.kt
+++ b/core/src/main/kotlin/transformers/descriptors/DefaultDescriptorToDocumentationTranslator.kt
@@ -1,15 +1,17 @@
package org.jetbrains.dokka.transformers.descriptors
import org.jetbrains.dokka.analysis.DokkaResolutionFacade
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.ClassKind
-import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.withClass
+import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.Enum
+import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.model.Property
+import org.jetbrains.dokka.model.ClassKind
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.pages.PlatformData
+import org.jetbrains.dokka.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
@@ -20,10 +22,9 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
-import org.jetbrains.dokka.parsers.MarkdownParser
import kotlin.reflect.KClass
-object DefaultDescriptorToDocumentationTranslator: DescriptorToDocumentationTranslator {
+object DefaultDescriptorToDocumentationTranslator : DescriptorToDocumentationTranslator {
override fun invoke(
moduleName: String,
packageFragments: Iterable<PackageFragmentDescriptor>,
@@ -42,6 +43,8 @@ internal data class DRIWithPlatformInfo(
val actual: List<PlatformInfo>
)
+private fun DRI.withEmptyInfo() = DRIWithPlatformInfo(this, null, emptyList())
+
internal class DokkaDescriptorVisitor(
private val platformData: PlatformData,
private val resolutionFacade: DokkaResolutionFacade
@@ -54,18 +57,42 @@ internal class DokkaDescriptorVisitor(
descriptor: PackageFragmentDescriptor,
parent: DRIWithPlatformInfo
): Package {
- val driWithPlatform = DRIWithPlatformInfo(DRI(packageName = descriptor.fqName.asString()), null, emptyList())
+ val driWithPlatform = DRI(packageName = descriptor.fqName.asString()).withEmptyInfo()
val scope = descriptor.getMemberScope()
return Package(
dri = driWithPlatform.dri,
functions = scope.functions(driWithPlatform),
properties = scope.properties(driWithPlatform),
- classes = scope.classes(driWithPlatform)
+ classlikes = scope.classlikes(driWithPlatform)
+ )
+ }
+
+ override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Classlike = when (descriptor.kind) {
+ org.jetbrains.kotlin.descriptors.ClassKind.ENUM_CLASS -> enumDescriptor(descriptor, parent)
+ else -> classDescriptor(descriptor, parent)
+ }
+
+ fun enumDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Enum {
+ val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo()
+ val scope = descriptor.getMemberScope(emptyList())
+ val descriptorData = descriptor.takeUnless { it.isExpect }?.resolveClassDescriptionData()
+
+ return Enum(
+ dri = driWithPlatform.dri,
+ name = descriptor.name.asString(),
+ entries = scope.classlikes(driWithPlatform).filter { it.kind == KotlinClassKindTypes.ENUM_ENTRY }.map { EnumEntry(it) },
+ constructors = descriptor.constructors.map { visitConstructorDescriptor(it, driWithPlatform) },
+ functions = scope.functions(driWithPlatform),
+ properties = scope.properties(driWithPlatform),
+ classlikes = scope.classlikes(driWithPlatform),
+ expected = descriptor.takeIf { it.isExpect }?.resolveClassDescriptionData(),
+ actual = listOfNotNull(descriptorData),
+ extra = mutableSetOf() // TODO Implement following method to return proper results getXMLDRIs(descriptor, descriptorData).toMutableSet()
)
}
- override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Class {
- val driWithPlatform = DRIWithPlatformInfo(parent.dri.withClass(descriptor.name.asString()), null, emptyList())
+ fun classDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Class {
+ val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo()
val scope = descriptor.getMemberScope(emptyList())
val descriptorData = descriptor.takeUnless { it.isExpect }?.resolveClassDescriptionData()
val expected = descriptor.takeIf { it.isExpect }?.resolveClassDescriptionData()
@@ -87,7 +114,7 @@ internal class DokkaDescriptorVisitor(
) },
functions = scope.functions(driWithPlatform),
properties = scope.properties(driWithPlatform),
- classes = scope.classes(driWithPlatform),
+ classlikes = scope.classlikes(driWithPlatform),
expected = expected,
actual = actual,
extra = mutableSetOf() // TODO Implement following method to return proper results getXMLDRIs(descriptor, descriptorData).toMutableSet()
@@ -193,7 +220,7 @@ internal class DokkaDescriptorVisitor(
.filterIsInstance<PropertyDescriptor>()
.map { visitPropertyDescriptor(it, parent) }
- private fun MemberScope.classes(parent: DRIWithPlatformInfo): List<Class> =
+ private fun MemberScope.classlikes(parent: DRIWithPlatformInfo): List<Classlike> =
getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true }
.filterIsInstance<ClassDescriptor>()
.map { visitClassDescriptor(it, parent) }
@@ -242,10 +269,12 @@ class KotlinTypeWrapper(private val kotlinType: KotlinType) : TypeWrapper {
override val constructorFqName = fqNameSafe?.asString()
override val constructorNamePathSegments: List<String> =
fqNameSafe?.pathSegments()?.map { it.asString() } ?: emptyList()
- override val arguments: List<KotlinTypeWrapper> by lazy { kotlinType.arguments.map {
- KotlinTypeWrapper(
- it.type
- )
- } }
+ override val arguments: List<KotlinTypeWrapper> by lazy {
+ kotlinType.arguments.map {
+ KotlinTypeWrapper(
+ it.type
+ )
+ }
+ }
override val dri: DRI? by lazy { declarationDescriptor?.let { DRI.from(it) } }
} \ No newline at end of file
diff --git a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt b/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt
index 86348206..ec67ea88 100644
--- a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt
+++ b/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.transformers.documentation
import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.Enum
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.plugability.DokkaContext
@@ -18,9 +19,9 @@ internal object DefaultDocumentationNodeMerger : DocumentationNodeMerger {
}
}
-private fun <T: Documentable> merge(elements: List<T>, reducer: (T, T) -> T): List<T> =
+private fun <T : Documentable> merge(elements: List<T>, reducer: (T, T) -> T): List<T> =
elements.groupingBy { it.dri }
- .reduce { _, left, right -> reducer(left, right)}
+ .reduce { _, left, right -> reducer(left, right) }
.values.toList()
fun PlatformInfo.mergeWith(other: PlatformInfo?) = BasePlatformInfo(
@@ -33,17 +34,17 @@ fun ClassPlatformInfo.mergeWith(other: ClassPlatformInfo?) = ClassPlatformInfo(
(inherited + (other?.inherited ?: emptyList())).distinct()
)
-fun List<ClassPlatformInfo>.mergeClassPlatformInfo() : List<ClassPlatformInfo> =
- groupingBy { it.documentationNode.children + it.inherited}.reduce {
- _, left, right -> left.mergeWith(right)
+fun List<ClassPlatformInfo>.mergeClassPlatformInfo(): List<ClassPlatformInfo> =
+ groupingBy { it.documentationNode.children + it.inherited }.reduce { _, left, right ->
+ left.mergeWith(right)
}.values.toList()
-fun List<PlatformInfo>.merge() : List<PlatformInfo> =
- groupingBy { it.documentationNode }.reduce {
- _, left, right -> left.mergeWith(right)
+fun List<PlatformInfo>.merge(): List<PlatformInfo> =
+ groupingBy { it.documentationNode }.reduce { _, left, right ->
+ left.mergeWith(right)
}.values.toList()
-fun Function.mergeWith(other: Function) = Function(
+fun Function.mergeWith(other: Function): Function = Function(
dri,
name,
returnType,
@@ -62,16 +63,34 @@ fun Property.mergeWith(other: Property) = Property(
(actual + other.actual).merge()
)
+fun Classlike.mergeWith(other: Classlike): Classlike = when {
+ this is Class && other is Class -> mergeWith(other)
+ this is Enum && other is Enum -> mergeWith(other)
+ else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot be merged with ${other::class.qualifiedName} ${other.name}")
+}
+
fun Class.mergeWith(other: Class) = Class(
- dri,
- name,
- kind,
- merge(constructors + other.constructors, Function::mergeWith),
- merge(functions + other.functions, Function::mergeWith),
- merge(properties + other.properties, Property::mergeWith),
- merge(classes + other.classes, Class::mergeWith),
- expected?.mergeWith(other.expected),
- (actual + other.actual).mergeClassPlatformInfo()
+ dri = dri,
+ name = name,
+ kind = kind,
+ constructors = merge(constructors + other.constructors, Function::mergeWith),
+ functions = merge(functions + other.functions, Function::mergeWith),
+ properties = merge(properties + other.properties, Property::mergeWith),
+ classlikes = merge(classlikes + other.classlikes, Classlike::mergeWith),
+ expected = expected?.mergeWith(other.expected),
+ actual = (actual + other.actual).mergeClassPlatformInfo()
+)
+
+fun Enum.mergeWith(other: Enum) = Enum(
+ dri = dri,
+ name = name,
+ functions = merge(functions + other.functions, Function::mergeWith),
+ properties = merge(properties + other.properties, Property::mergeWith),
+ classlikes = merge(classlikes + other.classlikes, Classlike::mergeWith),
+ expected = expected?.mergeWith(other.expected),
+ actual = (actual + other.actual).mergeClassPlatformInfo(),
+ entries = (this.entries + other.entries.distinctBy { it.dri }.toList()),
+ constructors = merge(constructors + other.constructors, Function::mergeWith)
)
fun Parameter.mergeWith(other: Parameter) = Parameter(
@@ -82,9 +101,9 @@ fun Parameter.mergeWith(other: Parameter) = Parameter(
(actual + other.actual).merge()
)
-fun Package.mergeWith(other: Package) = Package(
+fun Package.mergeWith(other: Package): Package = Package(
dri,
merge(functions + other.functions, Function::mergeWith),
merge(properties + other.properties, Property::mergeWith),
- merge(classes + other.classes, Class::mergeWith)
+ merge(classlikes + other.classlikes, Classlike::mergeWith)
) \ No newline at end of file