aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-06-17 14:38:02 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-06-18 09:29:02 +0200
commit295c8f1ad4d51e124efe4bbeb4351fa4db6b40d1 (patch)
tree0410dc70a7b3a04a73a933a91065145276a3ac98
parent4ac93c20f3936d5824b77a04806a2cdcfbb5e25f (diff)
downloaddokka-295c8f1ad4d51e124efe4bbeb4351fa4db6b40d1.tar.gz
dokka-295c8f1ad4d51e124efe4bbeb4351fa4db6b40d1.tar.bz2
dokka-295c8f1ad4d51e124efe4bbeb4351fa4db6b40d1.zip
KotlinSignatureProvider: Render 'fun interface' into signature
-rw-r--r--core/src/main/kotlin/model/extraModifiers.kt6
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt43
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt6
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt18
5 files changed, 46 insertions, 31 deletions
diff --git a/core/src/main/kotlin/model/extraModifiers.kt b/core/src/main/kotlin/model/extraModifiers.kt
index 093ce62a..efaa3d60 100644
--- a/core/src/main/kotlin/model/extraModifiers.kt
+++ b/core/src/main/kotlin/model/extraModifiers.kt
@@ -18,6 +18,7 @@ sealed class ExtraModifiers(val name: String) {
object Operator : KotlinOnlyModifiers("operator")
object TailRec : KotlinOnlyModifiers("tailrec")
object VarArg : KotlinOnlyModifiers("vararg")
+ object Fun : KotlinOnlyModifiers("fun")
}
sealed class JavaOnlyModifiers(name: String) : ExtraModifiers(name) {
@@ -29,9 +30,9 @@ sealed class ExtraModifiers(val name: String) {
object Volatile : JavaOnlyModifiers("volatile")
object Transitive : JavaOnlyModifiers("transitive")
}
-
+
companion object {
- fun valueOf(str: String) = when(str) {
+ fun valueOf(str: String) = when (str) {
"inline" -> KotlinOnlyModifiers.Inline
"infix" -> KotlinOnlyModifiers.Infix
"external" -> KotlinOnlyModifiers.External
@@ -54,6 +55,7 @@ sealed class ExtraModifiers(val name: String) {
"transient" -> JavaOnlyModifiers.Transient
"volatile" -> JavaOnlyModifiers.Volatile
"transitive" -> JavaOnlyModifiers.Transitive
+ "fun" -> KotlinOnlyModifiers.Fun
else -> throw IllegalArgumentException("There is no Extra Modifier for given name $str")
}
}
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 3b00320c..ab3056ec 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -33,12 +33,17 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun signature(e: DEnumEntry) =
- contentBuilder.contentFor(e, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = e.sourceSets.toSet()) {
- group(styles = setOf(TextStyle.Block)){
+ contentBuilder.contentFor(
+ e,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace),
+ sourceSets = e.sourceSets.toSet()
+ ) {
+ group(styles = setOf(TextStyle.Block)) {
annotationsBlock(e)
link(e.name, e.dri, styles = emptySet())
e.extra[ConstructorValues]?.let { constructorValues ->
- platformText(constructorValues.values, constructorValues.values.keys){
+ sourceSetDependentText(constructorValues.values, constructorValues.values.keys) {
it.joinToString(prefix = "(", postfix = ")")
}
}
@@ -55,6 +60,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
+ @Suppress("UNCHECKED_CAST")
private fun <T : DClasslike> classlikeSignature(c: T) =
(c as? WithExtraProperties<out DClasslike>)?.let {
c.extra[ActualTypealias]?.let {
@@ -68,12 +74,12 @@ 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) {
annotationsBlock(c)
- platformText(
+ sourceSetDependentText(
c.visibility,
sourceSets
) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
if (c is DClass) {
- platformText(c.modifier, sourceSets) {
+ sourceSetDependentText(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 + " " }
@@ -81,6 +87,14 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
""
}
}
+ if (c is DInterface) {
+ c.extra[AdditionalModifiers]?.content?.let { additionalModifiers ->
+ sourceSetDependentText(additionalModifiers, sourceSets) { extraModifiers ->
+ if (ExtraModifiers.KotlinOnlyModifiers.Fun in extraModifiers) "fun "
+ else ""
+ }
+ }
+ }
when (c) {
is DClass -> text("class ")
is DInterface -> text("interface ")
@@ -123,17 +137,16 @@ 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) {
annotationsBlock(p)
- platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- platformText(p.modifier) {
+ sourceSetDependentText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ sourceSetDependentText(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() }
+ sourceSetDependentText(p.modifiers()) { it.toSignatureString() }
p.setter?.let { text("var ") } ?: text("val ")
list(p.generics, prefix = "<", suffix = "> ") {
+buildSignature(it)
@@ -150,13 +163,13 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun functionSignature(f: DFunction, sourceSets: Set<SourceSetData> = f.sourceSets.toSet()) =
contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
annotationsBlock(f)
- platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- platformText(f.modifier) {
+ sourceSetDependentText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ sourceSetDependentText(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() }
+ sourceSetDependentText(f.modifiers()) { it.toSignatureString() }
text("fun ")
list(f.generics, prefix = "<", suffix = "> ") {
+buildSignature(it)
@@ -169,7 +182,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text("(")
list(f.parameters) {
annotationsInline(it)
- platformText(it.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(it.modifiers()) { it.toSignatureString() }
text(it.name!!)
text(": ")
signatureForProjection(it.type)
@@ -197,8 +210,8 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
setOf(TextStyle.Monospace),
sourceSets = platforms.toSet()
) {
- platformText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- platformText(t.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ sourceSetDependentText(t.modifiers()) { it.toSignatureString() }
text("typealias ")
signatureForProjection(t.type)
text(" = ")
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 90e37308..dfa7b480 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -131,7 +131,6 @@ private class DokkaDescriptorVisitor(
val isExpect = descriptor.isExpect
val info = descriptor.resolveClassDescriptionData()
-
return DInterface(
dri = driWithPlatform.dri,
name = descriptor.name.asString(),
@@ -635,7 +634,8 @@ private class DokkaDescriptorVisitor(
ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline },
ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal },
ExtraModifiers.KotlinOnlyModifiers.Inner.takeIf { isInner },
- ExtraModifiers.KotlinOnlyModifiers.Data.takeIf { isData }
+ ExtraModifiers.KotlinOnlyModifiers.Data.takeIf { isData },
+ ExtraModifiers.KotlinOnlyModifiers.Fun.takeIf { isFun }
).toSet()
private fun ValueParameterDescriptor.additionalExtras() = listOfNotNull(
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index c499be6f..cbae588f 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -353,11 +353,11 @@ open class PageContentBuilder(
) =
ContentText(text, DCI(mainDRI, kind), sourceSets, styles, extra)
- fun <T> platformText(
+ fun <T> sourceSetDependentText(
value: SourceSetDependent<T>,
- platforms: Set<SourceSetData> = value.keys,
+ sourceSets: Set<SourceSetData> = value.keys,
transform: (T) -> String
- ) = value.entries.filter { it.key in platforms }.mapNotNull { (p, v) ->
+ ) = value.entries.filter { it.key in sourceSets }.mapNotNull { (p, v) ->
transform(v).takeIf { it.isNotBlank() }?.let { it to p }
}.groupBy({ it.first }) { it.second }.forEach {
text(it.key, sourceSets = it.value.toSet())
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
index 0eb25504..94eda40f 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
@@ -37,11 +37,11 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
private fun signature(c: DClasslike) =
contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) {
- platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
+ sourceSetDependentText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
if (c is DClass) {
- platformText(c.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
- platformText(c.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(c.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
+ sourceSetDependentText(c.modifiers()) { it.toSignatureString() }
}
when (c) {
@@ -69,9 +69,9 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
private fun signature(p: DProperty) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace)) {
group(styles = setOf(TextStyle.Block)) {
annotationsBlock(p)
- platformText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
- platformText(p.modifier) { it.name + " " }
- platformText(p.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
+ sourceSetDependentText(p.modifier) { it.name + " " }
+ sourceSetDependentText(p.modifiers()) { it.toSignatureString() }
signatureForProjection(p.type)
text(nbsp.toString())
link(p.name, p.dri)
@@ -81,8 +81,8 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
private fun signature(f: DFunction) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) {
group(styles = setOf(TextStyle.Block)) {
annotationsBlock(f)
- platformText(f.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
- platformText(f.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(f.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
+ sourceSetDependentText(f.modifiers()) { it.toSignatureString() }
val returnType = f.type
signatureForProjection(returnType)
text(nbsp.toString())
@@ -92,7 +92,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
}
list(f.parameters, "(", ")") {
annotationsInline(it)
- platformText(it.modifiers()) { it.toSignatureString() }
+ sourceSetDependentText(it.modifiers()) { it.toSignatureString() }
signatureForProjection(it.type)
text(nbsp.toString())
link(it.name!!, it.dri)