diff options
5 files changed, 66 insertions, 23 deletions
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index ed429fe2..79585413 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka import org.jetbrains.dokka.Model.Module +import org.jetbrains.dokka.Model.transformers.ActualExpectedMerger import org.jetbrains.dokka.Utilities.pretty import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.MarkdownToContentConverter @@ -46,6 +47,7 @@ class DokkaGenerator( .map { DokkaDescriptorVisitor.visitPackageFragmentDescriptor(it, DRI.topLevel) } .toList() .let { Module(it) } + .let { ActualExpectedMerger(it) } .also { println("${pass.analysisPlatform}:\n${it.pretty()}\n\n") } DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(pass, module) diff --git a/core/src/main/kotlin/Model/ElementSignatureProvider.kt b/core/src/main/kotlin/Model/ElementSignatureProvider.kt deleted file mode 100644 index e8fdde6e..00000000 --- a/core/src/main/kotlin/Model/ElementSignatureProvider.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.jetbrains.dokka - -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor - -interface ElementSignatureProvider { - fun signature(forDesc: DeclarationDescriptor): String - fun signature(forPsi: PsiElement): String -}
\ No newline at end of file diff --git a/core/src/main/kotlin/Model/SourceLinks.kt b/core/src/main/kotlin/Model/SourceLinks.kt deleted file mode 100644 index 68cdab4a..00000000 --- a/core/src/main/kotlin/Model/SourceLinks.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.jetbrains.dokka - -import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiNameIdentifierOwner -import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition -import org.jetbrains.kotlin.psi.psiUtil.startOffset -import java.io.File - -fun PsiElement.lineNumber(): Int? { - val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile) - // IJ uses 0-based line-numbers; external source browsers use 1-based - return doc?.getLineNumber(textRange.startOffset)?.plus(1) -}
\ No newline at end of file diff --git a/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt b/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt new file mode 100644 index 00000000..171b41d0 --- /dev/null +++ b/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt @@ -0,0 +1,57 @@ +package org.jetbrains.dokka.Model.transformers + +import org.jetbrains.dokka.Model.* +import org.jetbrains.dokka.Model.Function + +internal object ActualExpectedMerger : DocumentationNodeTransformer { + override fun invoke(original: Module) = Module( + original.packages.map { mergePackageContent(it) } + ) +} + +private fun mergePackageContent(original: Package) = Package( + original.dri, + merge(original.functions, Function::mergeWith), + merge(original.properties, Property::mergeWith), + merge(original.classes, Class::mergeWith) +) + +private fun <T: DocumentationNode<*>> merge(elements: List<T>, reducer: (T, T) -> T): List<T> = + elements.groupingBy { it.dri } + .reduce { _, left, right -> reducer(left, right)} + .values.toList() + +fun Function.mergeWith(other: Function) = Function( + dri, + name, + if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, + merge(parameters + other.parameters, Parameter::mergeWith), + docTags + other.docTags, + descriptors + other.descriptors +) + +fun Property.mergeWith(other: Property) = Property( + dri, + name, + if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, + docTags + other.docTags, + descriptors + other.descriptors +) + +fun Class.mergeWith(other: Class) = Class( + dri, + name, + merge(constructors + other.constructors, Function::mergeWith), + merge(functions + other.functions, Function::mergeWith), + merge(properties + other.properties, Property::mergeWith), + merge(classes + other.classes, Class::mergeWith), + docTags + other.docTags, + descriptors + other.descriptors +) + +fun Parameter.mergeWith(other: Parameter) = Parameter( + dri, + name, + docTags + other.docTags, + descriptors + other.descriptors +) diff --git a/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt new file mode 100644 index 00000000..f94147fb --- /dev/null +++ b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt @@ -0,0 +1,7 @@ +package org.jetbrains.dokka.Model.transformers + +import org.jetbrains.dokka.Model.Module + +interface DocumentationNodeTransformer { + operator fun invoke(original: Module): Module +}
\ No newline at end of file |