From 705c6d45f95408633c71bc0bcd6bc93c9d79a381 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Sun, 16 Feb 2020 23:02:30 +0100 Subject: Renames DocumentationMerger and moves it to base plugin --- core/src/main/kotlin/CoreExtensions.kt | 4 +- core/src/main/kotlin/DokkaGenerator.kt | 2 +- .../main/kotlin/plugability/DefaultExtensions.kt | 2 - .../DefaultDocumentationNodeMerger.kt | 114 --------------------- .../documentation/DocumentableMerger.kt | 8 ++ .../documentation/DocumentationNodeMerger.kt | 8 -- core/src/main/kotlin/utilities/genericUtils.kt | 3 + 7 files changed, 14 insertions(+), 127 deletions(-) delete mode 100644 core/src/main/kotlin/transformers/documentation/DefaultDocumentationNodeMerger.kt create mode 100644 core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt delete mode 100644 core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt create mode 100644 core/src/main/kotlin/utilities/genericUtils.kt (limited to 'core/src') 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() val psiToDocumentationTranslator by coreExtension() - val documentationMerger by coreExtension() + val documentableMerger by coreExtension() val documentationTransformer by coreExtension() val commentsToContentConverter by coreExtension() val documentationToPageTranslator by coreExtension() 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, 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 > get(point: E, fullContext: DokkaContext): List = 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, 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 merge(elements: List, reducer: (T, T) -> T): List = - 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.mergeClassPlatformInfo(): List = - groupingBy { it.documentationNode.children + it.inherited }.reduce { _, left, right -> - left.mergeWith(right) - }.values.toList() - -fun List.merge(): List = - 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/DocumentableMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt new file mode 100644 index 00000000..5a17bc24 --- /dev/null +++ b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.transformers.documentation + +import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.plugability.DokkaContext + +interface DocumentableMerger { + operator fun invoke(modules: Collection, context: DokkaContext): Module +} \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt deleted file mode 100644 index 25be625e..00000000 --- a/core/src/main/kotlin/transformers/documentation/DocumentationNodeMerger.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.transformers.documentation - -import org.jetbrains.dokka.model.Module -import org.jetbrains.dokka.plugability.DokkaContext - -interface DocumentationNodeMerger { - operator fun invoke(modules: Collection, 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 Pair.pullOutNull(): Pair? = first?.let { f -> second?.let { s -> f to s } } \ No newline at end of file -- cgit