diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-05-28 21:12:50 +0200 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-06-12 14:15:24 +0200 |
commit | dd44b839eac1b7b647e97f2cc73dd96bd054713b (patch) | |
tree | 6ab5a393c2a7d926519626f5f45f5c8b8cd60505 /plugins/base/src/main/kotlin/signatures | |
parent | d7be30c841cb925fd0d6322ccdd9877169730b92 (diff) | |
download | dokka-dd44b839eac1b7b647e97f2cc73dd96bd054713b.tar.gz dokka-dd44b839eac1b7b647e97f2cc73dd96bd054713b.tar.bz2 dokka-dd44b839eac1b7b647e97f2cc73dd96bd054713b.zip |
Refactor of Annotations and ExtraModifiers to be platform depedent
Diffstat (limited to 'plugins/base/src/main/kotlin/signatures')
3 files changed, 98 insertions, 95 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index 0cf085b8..7f0e985e 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.signatures import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties +import org.jetbrains.dokka.pages.* interface JvmSignatureUtils { @@ -10,7 +11,7 @@ interface JvmSignatureUtils { fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable) - fun <T : Documentable> WithExtraProperties<T>.modifiers(): Set<ExtraModifiers> + fun <T : Documentable> WithExtraProperties<T>.modifiers(): SourceSetDependent<Set<ExtraModifiers>> fun Set<ExtraModifiers>.toSignatureString(): String = joinToString("") { it.name.toLowerCase() + " " } @@ -40,9 +41,11 @@ interface JvmSignatureUtils { else -> null }?.let { it.entries.forEach { - group(sourceSets = setOf(it.key)) { - it.value.filter { it !in ignored }.forEach { - operation(it) + it.value.filter { it !in ignored }.takeIf { it.isNotEmpty() }?.let { annotations -> + group(sourceSets = setOf(it.key), styles = setOf(TextStyle.Block)) { + annotations.forEach { + operation(it) + } } } } @@ -62,14 +65,16 @@ interface JvmSignatureUtils { link(a.dri.classNames!!, a.dri) text("(") a.params.entries.forEachIndexed { i, it -> - text(it.key + " = ") - when (renderAtStrategy) { - is All -> All - is Never, is OnlyOnce -> Never - }.let { strategy -> - valueToSignature(it.value, strategy, listBrackets, classExtension) + group(styles = setOf(TextStyle.Span)) { + text(it.key + " = ") + when (renderAtStrategy) { + is All -> All + is Never, is OnlyOnce -> Never + }.let { strategy -> + valueToSignature(it.value, strategy, listBrackets, classExtension) + } + if (i != a.params.entries.size - 1) text(", ") } - if (i != a.params.entries.size - 1) text(", ") } text(")") } diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 5514f9e5..542f6a1a 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -67,34 +67,34 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun regularSignature(c: DClasslike, sourceSets: Set<SourceSetData> = c.sourceSets.toSet()) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(c) - platformText( - c.visibility, - sourceSets - ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - if (c is DClass) { - platformText(c.modifier, sourceSets) { - if (it !in ignoredModifiers) - if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" - else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } - else - "" - } - } - when (c) { - is DClass -> text("class ") - is DInterface -> text("interface ") - is DEnum -> text("enum ") - is DObject -> text("object ") - is DAnnotation -> text("annotation class ") + annotationsBlock(c) + platformText( + c.visibility, + sourceSets + ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + if (c is DClass) { + platformText(c.modifier, sourceSets) { + if (it !in ignoredModifiers) + if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" + else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } + else + "" } - link(c.name!!, c.dri) - if (c is WithGenerics) { - list(c.generics, prefix = "<", suffix = "> ") { - +buildSignature(it) - } + } + when (c) { + is DClass -> text("class ") + is DInterface -> text("interface ") + is DEnum -> text("enum ") + is DObject -> text("object ") + is DAnnotation -> text("annotation class ") + } + link(c.name!!, c.dri) + if (c is WithGenerics) { + list(c.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) } + } + if (c is DClass) { if (c is WithConstructors) { val pConstructor = c.constructors.singleOrNull { it.extra[PrimaryConstructorExtra] != null } if (pConstructor?.annotations()?.isNotEmpty() == true) { @@ -115,11 +115,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog signatureForProjection(it.type) } } - if (c is WithSupertypes) { - c.supertypes.filter { it.key in sourceSets }.map { (s, dris) -> - list(dris, prefix = " : ", sourceSets = setOf(s)) { - link(it.sureClassNames, it, sourceSets = setOf(s)) - } + } + if (c is WithSupertypes) { + c.supertypes.filter { it.key in sourceSets }.map { (s, dris) -> + list(dris, prefix = " : ", sourceSets = setOf(s)) { + link(it.sureClassNames, it, sourceSets = setOf(s)) } } } @@ -128,62 +128,58 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun propertySignature(p: DProperty, sourceSets: Set<SourceSetData> = p.sourceSets.toSet()) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(p) - platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - platformText(p.modifier) { - it.takeIf { it !in ignoredModifiers }?.let { - if (it is JavaModifier.Empty) KotlinModifier.Open else it - }?.name?.let { "$it " } ?: "" - } - text(p.modifiers().toSignatureString()) - p.setter?.let { text("var ") } ?: text("val ") - list(p.generics, prefix = "<", suffix = "> ") { - +buildSignature(it) - } - p.receiver?.also { - signatureForProjection(it.type) - text(".") - } - link(p.name, p.dri) - text(": ") - signatureForProjection(p.type) + annotationsBlock(p) + platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + platformText(p.modifier) { + it.takeIf { it !in ignoredModifiers }?.let { + if (it is JavaModifier.Empty) KotlinModifier.Open else it + }?.name?.let { "$it " } ?: "" + } + platformText(p.modifiers()) { it.toSignatureString() } + p.setter?.let { text("var ") } ?: text("val ") + list(p.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) + } + p.receiver?.also { + signatureForProjection(it.type) + text(".") } + link(p.name, p.dri) + text(": ") + signatureForProjection(p.type) } private fun functionSignature(f: DFunction, sourceSets: Set<SourceSetData> = f.sourceSets.toSet()) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(f) - platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - platformText(f.modifier) { - it.takeIf { it !in ignoredModifiers }?.let { - if (it is JavaModifier.Empty) KotlinModifier.Open else it - }?.name?.let { "$it " } ?: "" - } - text(f.modifiers().toSignatureString()) - text("fun ") - list(f.generics, prefix = "<", suffix = "> ") { - +buildSignature(it) - } - f.receiver?.also { - signatureForProjection(it.type) - text(".") - } - link(f.name, f.dri) - text("(") - list(f.parameters) { - annotationsInline(it) - text(it.modifiers().toSignatureString()) - text(it.name!!) - text(": ") - signatureForProjection(it.type) - } - text(")") - if (f.documentReturnType()) { - text(": ") - signatureForProjection(f.type) - } + annotationsBlock(f) + platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + platformText(f.modifier) { + it.takeIf { it !in ignoredModifiers }?.let { + if (it is JavaModifier.Empty) KotlinModifier.Open else it + }?.name?.let { "$it " } ?: "" + } + platformText(f.modifiers()) { it.toSignatureString() } + text("fun ") + list(f.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) + } + f.receiver?.also { + signatureForProjection(it.type) + text(".") + } + link(f.name, f.dri) + text("(") + list(f.parameters) { + annotationsInline(it) + platformText(it.modifiers()) { it.toSignatureString() } + text(it.name!!) + text(": ") + signatureForProjection(it.type) + } + text(")") + if (f.documentReturnType()) { + text(": ") + signatureForProjection(f.type) } } @@ -204,7 +200,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog sourceSets = platforms.toSet() ) { platformText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - text(t.modifiers().toSignatureString()) + platformText(t.modifiers()) { it.toSignatureString() } text("typealias ") signatureForProjection(t.type) text(" = ") diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 48cfe304..1f323473 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -19,5 +19,7 @@ object KotlinSignatureUtils : JvmSignatureUtils { annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) override fun <T : Documentable> WithExtraProperties<T>.modifiers() = - extra[AdditionalModifiers]?.content?.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>()?.toSet() ?: emptySet() + extra[AdditionalModifiers]?.content?.entries?.map { + it.key to it.value.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>().toSet() + }?.toMap() ?: emptyMap() }
\ No newline at end of file |