From 940cf84196f0cd0dbeafae2f0ec5f73a49b68285 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Tue, 5 Nov 2019 17:20:21 +0100 Subject: Signateures wrapped in symbols --- core/src/main/kotlin/renderers/DefaultRenderer.kt | 2 +- .../transformers/DefaultDocumentationToPageTransformer.kt | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/renderers/DefaultRenderer.kt b/core/src/main/kotlin/renderers/DefaultRenderer.kt index a2ca4131..e3b3fbeb 100644 --- a/core/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/core/src/main/kotlin/renderers/DefaultRenderer.kt @@ -14,7 +14,7 @@ abstract class DefaultRenderer(val fileWriter: FileWriter, val locationProvider: protected open fun buildHeader(level: Int, content: List, pageContext: PageNode): String = buildHeader(level, content.joinToString { it.build(pageContext) }) protected open fun buildGroup(children: List, pageContext: PageNode): String = children.joinToString { it.build(pageContext) } protected open fun buildComment(parts: List, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) } - protected open fun buildSymbol(parts: List, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) } + protected open fun buildSymbol(parts: List, pageContext: PageNode): String = parts.joinToString(separator = "") { it.build(pageContext) } protected open fun buildBlock(name: String, content: List, pageContext: PageNode) = buildHeader(3, name) + content.joinToString("\n") { it.build(pageContext) } protected open fun ContentNode.build(pageContext: PageNode): String = buildContentNode(this, pageContext) diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt index 0427b9b6..a3966d62 100644 --- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt @@ -111,6 +111,10 @@ class DefaultDocumentationToPageTransformer( contents += ContentText(text, platformData) } + inline fun symbol(block: ContentBuilder.() -> Unit) { + contents += ContentSymbol(content(block), platformData) + } + inline fun block(name: String, elements: Iterable, block: ContentBuilder.(T) -> Unit) { contents += ContentBlock(name, content { elements.forEach { block(it) } }, platformData) } @@ -152,10 +156,10 @@ class DefaultDocumentationToPageTransformer( ContentBuilder(platformData).apply(block).build() // When builder is made public it will be moved as extension method to someplace near Function model - private fun ContentBuilder.signature(f: Function) { + private fun ContentBuilder.signature(f: Function) = symbol { text("fun ") if (f.receiver is Parameter) { - type(f.receiver.descriptor.type) + type(f.receiver.descriptor.type) text(".") } link(f.name, f.dri) @@ -166,6 +170,12 @@ class DefaultDocumentationToPageTransformer( type(it.descriptor.type) } text(")") + val returnType = f.descriptor.returnType + if (returnType != null && + returnType.constructor.declarationDescriptor?.fqNameSafe?.asString() != Unit::class.qualifiedName) { + text(": ") + type(returnType) + } } private fun ContentBuilder.type(t: KotlinType) { -- cgit