aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
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
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')
-rw-r--r--core/src/main/kotlin/CoreExtensions.kt4
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt2
-rw-r--r--core/src/main/kotlin/plugability/DefaultExtensions.kt2
-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
-rw-r--r--core/src/main/kotlin/utilities/genericUtils.kt3
6 files changed, 7 insertions, 120 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt
index 1364f1c1..47f2e4c1 100644
--- a/core/src/main/kotlin/CoreExtensions.kt
+++ b/core/src/main/kotlin/CoreExtensions.kt
@@ -6,7 +6,7 @@ import org.jetbrains.dokka.renderers.Renderer
import org.jetbrains.dokka.renderers.OutputWriter
import org.jetbrains.dokka.resolvers.LocationProviderFactory
import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentationTranslator
-import org.jetbrains.dokka.transformers.documentation.DocumentationNodeMerger
+import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.dokka.transformers.documentation.DocumentationNodeTransformer
import org.jetbrains.dokka.transformers.documentation.DocumentationToPageTranslator
import org.jetbrains.dokka.transformers.pages.PageMergerStrategy
@@ -22,7 +22,7 @@ import kotlin.reflect.KProperty
object CoreExtensions {
val descriptorToDocumentationTranslator by coreExtension<DescriptorToDocumentationTranslator>()
val psiToDocumentationTranslator by coreExtension<PsiToDocumentationTranslator>()
- val documentationMerger by coreExtension<DocumentationNodeMerger>()
+ val documentableMerger by coreExtension<DocumentableMerger>()
val documentationTransformer by coreExtension<DocumentationNodeTransformer>()
val commentsToContentConverter by coreExtension<CommentsToContentConverter>()
val documentationToPageTranslator by coreExtension<DocumentationToPageTranslator>()
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index 573ba13e..1829c9e4 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -78,7 +78,7 @@ class DokkaGenerator(
fun mergeDocumentationModels(
modulesFromPlatforms: List<Module>,
context: DokkaContext
- ) = context.single(CoreExtensions.documentationMerger).invoke(modulesFromPlatforms, context)
+ ) = context.single(CoreExtensions.documentableMerger).invoke(modulesFromPlatforms, context)
fun transformDocumentationModel(
documentationModel: Module,
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt
index 70a7e4db..c1a72c74 100644
--- a/core/src/main/kotlin/plugability/DefaultExtensions.kt
+++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt
@@ -6,7 +6,6 @@ import org.jetbrains.dokka.renderers.FileWriter
import org.jetbrains.dokka.renderers.OutputWriter
import org.jetbrains.dokka.renderers.html.HtmlRenderer
import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory
-import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationNodeMerger
import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator
import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy
import org.jetbrains.dokka.transformers.psi.DefaultPsiToDocumentationTranslator
@@ -28,7 +27,6 @@ internal object DefaultExtensions {
internal fun <T : Any, E : ExtensionPoint<T>> get(point: E, fullContext: DokkaContext): List<T> =
when (point) {
CoreExtensions.psiToDocumentationTranslator -> DefaultPsiToDocumentationTranslator
- CoreExtensions.documentationMerger -> DefaultDocumentationNodeMerger
CoreExtensions.commentsToContentConverter -> converter.get(fullContext)
CoreExtensions.documentationToPageTranslator -> DefaultDocumentationToPageTranslator
CoreExtensions.pageTransformer -> DefaultPageNodeMerger(fullContext)
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
diff --git a/core/src/main/kotlin/utilities/genericUtils.kt b/core/src/main/kotlin/utilities/genericUtils.kt
new file mode 100644
index 00000000..e94e4e8f
--- /dev/null
+++ b/core/src/main/kotlin/utilities/genericUtils.kt
@@ -0,0 +1,3 @@
+package org.jetbrains.dokka.utilities
+
+fun <T : Any, S : Any> Pair<T?, S?>.pullOutNull(): Pair<T, S>? = first?.let { f -> second?.let { s -> f to s } } \ No newline at end of file