From 9110dbc70e42d10c56d1e080fdaeecd1ea13d84f Mon Sep 17 00:00:00 2001 From: Filip ZybaƂa Date: Fri, 13 Mar 2020 14:56:38 +0100 Subject: Fixed data class rendering. Added information about primary constructor and changed its rendering. --- core/src/main/kotlin/model/aditionalExtras.kt | 6 ++++++ .../main/kotlin/signatures/KotlinSignatureProvider.kt | 17 ++++++++++++++++- .../DefaultDescriptorToDocumentableTranslator.kt | 5 +++++ .../translators/documentables/DefaultPageCreator.kt | 8 +++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index f7d37111..75f5f69a 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -35,4 +35,10 @@ class Annotations(val content: List) : ExtraProperty { override fun hashCode(): Int = dri.hashCode() } +} + +object PrimaryConstructorExtra: ExtraProperty { + object PrimaryConstructorExtraKey: ExtraProperty.Key + + override val key: ExtraProperty.Key = PrimaryConstructorExtraKey } \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 6eeedb88..31cd0eca 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -33,7 +33,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(c: DClasslike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } if (c is DClass) { - text(c.modifier.name + " ") + if (c.extra[AdditionalModifiers.AdditionalKey]?.content?.contains(ExtraModifiers.DATA) == true) { + text("data ") + } else { + text(c.modifier.name + " ") + } } when (c) { is DClass -> text("class ") @@ -43,6 +47,17 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog is DAnnotation -> text("annotation class ") } link(c.name!!, c.dri) + if(c is Class){ + val pConstructor = c.constructors.singleOrNull() { it.extra[PrimaryConstructorExtra.PrimaryConstructorExtraKey] != null } + if(pConstructor != null) { + list(pConstructor.parameters, "(", ")", ",", pConstructor.platformData.toSet()){ + breakLine() + text(it.name ?: "", styles = mainStyles.plus(TextStyle.Bold)) + text(": ") + signatureForProjection(it.type) + } + } + } if (c is WithSupertypes) { c.supertypes.map { (p, dris) -> list(dris, prefix = " : ", platformData = setOf(p)) { diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index ae623ff2..bd21f9df 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -488,6 +488,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) } ).toProperty() + inline fun ConstructorDescriptor.additionalExtras(): PropertyContainer = + if(this.isPrimary) + (this as FunctionDescriptor).additionalExtras() + PrimaryConstructorExtra + else (this as FunctionDescriptor).additionalExtras() + fun ClassDescriptor.additionalExtras() = listOfNotNull( ExtraModifiers.DYNAMIC.takeIf { isDynamic() }, ExtraModifiers.INLINE.takeIf { isInline }, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index eba56625..464c7bf4 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -105,7 +105,13 @@ open class DefaultPageCreator( +contentForComments(c) { it !is Property } if (c is WithConstructors) { - block("Constructors", 2, ContentKind.Constructors, c.constructors, c.platformData.toSet()) { + block( + "Constructors", + 2, + ContentKind.Constructors, + c.constructors.filter { it.extra[PrimaryConstructorExtra.PrimaryConstructorExtraKey] == null }, + c.platformData.toSet() + ) { link(it.name, it.dri) group { +buildSignature(it) -- cgit