diff options
4 files changed, 56 insertions, 46 deletions
diff --git a/core/src/main/kotlin/DokkaDescriptorVisitor.kt b/core/src/main/kotlin/DokkaDescriptorVisitor.kt index b6d622e5..0a026157 100644 --- a/core/src/main/kotlin/DokkaDescriptorVisitor.kt +++ b/core/src/main/kotlin/DokkaDescriptorVisitor.kt @@ -40,8 +40,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document scope.functions(dri), scope.properties(dri), scope.classes(dri), - descriptor.findKDoc(), - descriptor + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) ) } @@ -51,8 +51,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document dri, descriptor.name.asString(), descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor(it, dri) }, - descriptor.findKDoc(), - descriptor + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) ) } @@ -63,8 +63,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document descriptor.name.asString(), descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor(it, dri) }, descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, dri) }, - descriptor.findKDoc(), - descriptor + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) ) } @@ -75,18 +75,28 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document "<init>", null, descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, dri) }, - descriptor.findKDoc(), - descriptor + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) ) } override fun visitReceiverParameterDescriptor( descriptor: ReceiverParameterDescriptor, parent: DRI - ) = Parameter(parent.copy(target = 0), null, descriptor.findKDoc(), descriptor) + ) = Parameter( + parent.copy(target = 0), + null, + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) + ) private fun parameter(index: Int, descriptor: ValueParameterDescriptor, parent: DRI) = - Parameter(parent.copy(target = index + 1), descriptor.name.asString(), descriptor.findKDoc(), descriptor) + Parameter( + parent.copy(target = index + 1), + descriptor.name.asString(), + listOfNotNull(descriptor.findKDoc()), + listOf(descriptor) + ) private fun MemberScope.functions(parent: DRI): List<Function> = getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) { true } diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index a82c86d1..99764fac 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag class Module(val packages: List<Package>) : DocumentationNode<Nothing>() { - override val docTag: KDocTag? = null + override val docTags: List<KDocTag> = emptyList() override val dri: DRI = DRI.topLevel @@ -20,7 +20,7 @@ class Package( ) : ScopeNode<Nothing>() { val name = dri.packageName.orEmpty() - override val docTag: KDocTag? = null + override val docTags: List<KDocTag> = emptyList() } class Class( @@ -30,8 +30,8 @@ class Class( override val functions: List<Function>, override val properties: List<Property>, override val classes: List<Class>, - override val docTag: KDocTag?, - override val descriptor: ClassDescriptor + override val docTags: List<KDocTag>, + override val descriptors: List<ClassDescriptor> ) : ScopeNode<ClassDescriptor>() class Function( @@ -39,8 +39,8 @@ class Function( val name: String, override val receiver: Parameter?, val parameters: List<Parameter>, - override val docTag: KDocTag?, - override val descriptor: FunctionDescriptor + override val docTags: List<KDocTag>, + override val descriptors: List<FunctionDescriptor> ) : CallableNode<FunctionDescriptor>() { override val children: List<Parameter> get() = listOfNotNull(receiver) + parameters @@ -50,8 +50,8 @@ class Property( override val dri: DRI, val name: String, override val receiver: Parameter?, - override val docTag: KDocTag?, - override val descriptor: PropertyDescriptor + override val docTags: List<KDocTag>, + override val descriptors: List<PropertyDescriptor> ) : CallableNode<PropertyDescriptor>() { override val children: List<Parameter> get() = listOfNotNull(receiver) @@ -61,17 +61,17 @@ class Property( class Parameter( override val dri: DRI, val name: String?, - override val docTag: KDocTag?, - override val descriptor: ParameterDescriptor + override val docTags: List<KDocTag>, + override val descriptors: List<ParameterDescriptor> ) : DocumentationNode<ParameterDescriptor>() { override val children: List<DocumentationNode<*>> get() = emptyList() } abstract class DocumentationNode<out T : DeclarationDescriptor> { - open val descriptor: T? = null + open val descriptors: List<T> = emptyList() - abstract val docTag: KDocTag? // TODO: replace in the future with more robust doc-comment model + abstract val docTags: List<KDocTag> // TODO: replace in the future with more robust doc-comment model abstract val dri: DRI @@ -85,11 +85,11 @@ abstract class DocumentationNode<out T : DeclarationDescriptor> { override fun hashCode() = dri.hashCode() - val rawDocstring: String - get() = docTag?.getContent().orEmpty() + val rawDocstrings: List<String> + get() = docTags.map(KDocTag::getContent) val briefDocstring: String - get() = rawDocstring.shorten(40) + get() = rawDocstrings.firstOrNull().orEmpty().shorten(40) } abstract class ScopeNode<out T : ClassOrPackageFragmentDescriptor> : DocumentationNode<T>() { diff --git a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt index 14b56226..9b249878 100644 --- a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt +++ b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt @@ -7,7 +7,6 @@ import org.jetbrains.dokka.DokkaResolutionFacade import org.jetbrains.dokka.MarkdownNode import org.jetbrains.dokka.Model.DocumentationNode import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.visit import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink class MarkdownToContentConverter( @@ -90,20 +89,21 @@ class MarkdownToContentConverter( } MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK -> { - val descriptor = documentationNode.descriptor - if (descriptor != null) { + if (documentationNode.descriptors.isNotEmpty()) { val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text - ?:destinationNode.text - - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - descriptor, - null, - destination.split('.') - ) + ?: destinationNode.text + + documentationNode.descriptors.flatMap { + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + it, + null, + destination.split('.') + ) + } .firstOrNull() ?.let { ContentLink(destination, DRI.from(it), platforms) } .let(::listOfNotNull) diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt index 273b47d0..2fc926ef 100644 --- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt @@ -72,7 +72,7 @@ class DefaultDocumentationToPageTransformer( private fun contentForClass(c: Class) = content(platformData) { header(1) { text(c.name) } - markdown(c.rawDocstring, c) + c.rawDocstrings.forEach { markdown(it, c) } block("Constructors", c.constructors) { signature(it) text(it.briefDocstring) @@ -87,11 +87,11 @@ class DefaultDocumentationToPageTransformer( private fun contentForFunction(f: Function) = content(platformData) { header(1) { text(f.name) } signature(f) - markdown(f.rawDocstring, f) - block("Parameters", f.children) { + f.rawDocstrings.forEach { markdown(it, f) } + block("Parameters", f.children) { param -> group { - text(it.name ?: "<receiver>") - markdown(it.rawDocstring, it) + text(param.name ?: "<receiver>") + param.rawDocstrings.forEach { markdown(it, param) } } } } @@ -159,7 +159,7 @@ class DefaultDocumentationToPageTransformer( private fun ContentBuilder.signature(f: Function) = symbol { text("fun ") if (f.receiver is Parameter) { - type(f.receiver.descriptor.type) + type(f.receiver.descriptors.first().type) text(".") } link(f.name, f.dri) @@ -167,11 +167,11 @@ class DefaultDocumentationToPageTransformer( list(f.parameters) { link(it.name!!, it.dri) text(": ") - type(it.descriptor.type) + type(it.descriptors.first().type) } text(")") - val returnType = f.descriptor.returnType - if (f.descriptor !is ConstructorDescriptor && returnType != null && + val returnType = f.descriptors.first().returnType + if (f.descriptors.first() !is ConstructorDescriptor && returnType != null && returnType.constructor.declarationDescriptor?.fqNameSafe?.asString() != Unit::class.qualifiedName) { text(": ") type(returnType) |