aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/transformers
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-02-16 23:02:30 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-18 13:28:23 +0100
commit705c6d45f95408633c71bc0bcd6bc93c9d79a381 (patch)
tree981bb204b14b2b74656f9b5010359f7c24c09516 /core/src/main/kotlin/transformers
parente82beddda7b51f285f0422c6a7078a0a80d54d14 (diff)
downloaddokka-705c6d45f95408633c71bc0bcd6bc93c9d79a381.tar.gz
dokka-705c6d45f95408633c71bc0bcd6bc93c9d79a381.tar.bz2
dokka-705c6d45f95408633c71bc0bcd6bc93c9d79a381.zip
Renames DocumentationMerger and moves it to base plugin
Diffstat (limited to 'core/src/main/kotlin/transformers')
-rw-r--r--core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt114
-rw-r--r--core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt (renamed from core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt)2
2 files changed, 1 insertions, 115 deletions
diff --git a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt b/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt
deleted file mode 100644
index 0d7fa249..00000000
--- a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt
+++ /dev/null
@@ -1,114 +0,0 @@
-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
-
-internal object DefaultDocumentationNodeMerger : DocumentationNodeMerger {
- override fun invoke(modules: Collection<Module>, context: DokkaContext): Module {
- if (!modules.all { it.name == modules.first().name })
- context.logger.error("All module names need to be the same")
- return Module(
- modules.first().name,
- merge(
- modules.flatMap { it.packages },
- Package::mergeWith
- )
- )
- }
-}
-
-private fun <T : Documentable> merge(elements: List<T>, reducer: (T, T) -> T): List<T> =
- elements.groupingBy { it.dri }
- .reduce { _, left, right -> reducer(left, right) }
- .values.toList()
-
-fun PlatformInfo.mergeWith(other: PlatformInfo?) = BasePlatformInfo(
- documentationNode,
- (platformData + (other?.platformData ?: emptyList())).distinct()
-)
-
-fun ClassPlatformInfo.mergeWith(other: ClassPlatformInfo?) = ClassPlatformInfo(
- info.mergeWith(other?.info),
- (inherited + (other?.inherited ?: emptyList())).distinct()
-)
-
-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)
- }.values.toList()
-
-fun Function.mergeWith(other: Function): Function = Function(
- dri,
- name,
- returnType,
- isConstructor,
- if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null,
- merge(parameters + other.parameters, Parameter::mergeWith),
- expected?.mergeWith(other.expected),
- (actual + other.actual).merge(),
- visibility = (visibility + other.visibility)
-)
-
-fun Property.mergeWith(other: Property) = Property(
- dri,
- name,
- if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null,
- expected?.mergeWith(other.expected),
- (actual + other.actual).merge(),
- accessors = (this.accessors + other.accessors).distinct(),
- visibility = (visibility + other.visibility)
-)
-
-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 = 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(),
- visibility = (visibility + other.visibility)
-)
-
-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),
- visibility = visibility
-)
-
-fun Parameter.mergeWith(other: Parameter) = Parameter(
- dri,
- name,
- type,
- expected?.mergeWith(other.expected),
- (actual + other.actual).merge()
-)
-
-fun Package.mergeWith(other: Package): Package = Package(
- dri,
- merge(functions + other.functions, Function::mergeWith),
- merge(properties + other.properties, Property::mergeWith),
- merge(classlikes + other.classlikes, Classlike::mergeWith)
-) \ No newline at end of file
diff --git a/core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt
index 25be625e..5a17bc24 100644
--- a/core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt
+++ b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt
@@ -3,6 +3,6 @@ package org.jetbrains.dokka.transformers.documentation
import org.jetbrains.dokka.model.Module
import org.jetbrains.dokka.plugability.DokkaContext
-interface DocumentationNodeMerger {
+interface DocumentableMerger {
operator fun invoke(modules: Collection<Module>, context: DokkaContext): Module
} \ No newline at end of file