aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt165
1 files changed, 101 insertions, 64 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index bd967518..8db37012 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -15,6 +15,7 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.ContentKind
import org.jetbrains.dokka.pages.ContentNode
import org.jetbrains.dokka.pages.TextStyle
+import org.jetbrains.dokka.pages.TokenStyle
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
@@ -60,7 +61,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
it !in ignoredExtraModifiers || entry.key.analysisPlatform in (platformSpecificModifiers[it]
?: emptySet())
}
- }
+ }, styles = mainStyles + TokenStyle.Keyword
) {
it.toSignatureString()
}
@@ -78,8 +79,15 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
annotationsBlock(e)
link(e.name, e.dri, styles = emptySet())
e.extra[ConstructorValues]?.let { constructorValues ->
- constructorValues.values[it]
- text(constructorValues.values[it]?.joinToString(prefix = "(", postfix = ")") ?: "")
+ constructorValues.values[it]?.let { values ->
+ punctuation("(")
+ list(
+ elements = values,
+ separator = ", ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ ) { highlightValue(it) }
+ punctuation(")")
+ }
}
}
}
@@ -93,9 +101,9 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
?: emptySet()),
sourceSets = setOf(sourceSet)
) {
- text("typealias ")
+ keyword("typealias ")
link(c.name.orEmpty(), c.dri)
- text(" = ")
+ operator(" = ")
signatureForProjection(aliasedType)
}
@@ -118,10 +126,9 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
sourceSets = setOf(sourceSet)
) {
annotationsBlock(c)
- text(c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
+ c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
if (c is DClass) {
- text(
- if (c.modifier[sourceSet] !in ignoredModifiers)
+ val modifier = if (c.modifier[sourceSet] !in ignoredModifiers)
when {
c.extra[AdditionalModifiers]?.content?.get(sourceSet)?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true -> ""
c.modifier[sourceSet] is JavaModifier.Empty -> "${KotlinModifier.Open.name} "
@@ -129,33 +136,35 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
else
""
- )
+ modifier.takeIf { it.isNotEmpty() }?.let { keyword(it) }
}
when (c) {
is DClass -> {
processExtraModifiers(c)
- text("class ")
+ keyword("class ")
}
is DInterface -> {
processExtraModifiers(c)
- text("interface ")
+ keyword("interface ")
}
is DEnum -> {
processExtraModifiers(c)
- text("enum ")
+ keyword("enum ")
}
is DObject -> {
processExtraModifiers(c)
- text("object ")
+ keyword("object ")
}
is DAnnotation -> {
processExtraModifiers(c)
- text("annotation class ")
+ keyword("annotation class ")
}
}
link(c.name!!, c.dri)
if (c is WithGenerics) {
- list(c.generics, prefix = "<", suffix = ">") {
+ list(c.generics, prefix = "<", suffix = ">",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
annotationsInline(it)
+buildSignature(it)
}
@@ -166,18 +175,20 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
if (pConstructor.annotations().values.any { it.isNotEmpty() }) {
text(nbsp.toString())
annotationsInline(pConstructor)
- text("constructor")
+ keyword("constructor")
}
list(
- pConstructor.parameters,
- "(",
- ")",
- ", ",
- pConstructor.sourceSets.toSet()
+ elements = pConstructor.parameters,
+ prefix = "(",
+ suffix = ")",
+ separator = ", ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Punctuation,
+ sourceSets = pConstructor.sourceSets.toSet()
) {
annotationsInline(it)
text(it.name.orEmpty())
- text(": ")
+ operator(": ")
signatureForProjection(it.type)
}
}
@@ -186,7 +197,9 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
c.supertypes.filter { it.key == sourceSet }.map { (s, typeConstructors) ->
list(typeConstructors, prefix = " : ", sourceSets = setOf(s)) {
link(it.typeConstructor.dri.sureClassNames, it.typeConstructor.dri, sourceSets = setOf(s))
- list(it.typeConstructor.projections, prefix = "<", suffix = "> ") {
+ list(it.typeConstructor.projections, prefix = "<", suffix = "> ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
signatureForProjection(it)
}
}
@@ -203,31 +216,42 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
sourceSets = setOf(it)
) {
annotationsBlock(p)
- text(p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
- text(
- p.modifier[it].takeIf { it !in ignoredModifiers }?.let {
+ p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ p.modifier[it].takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- )
- text(p.modifiers()[it]?.toSignatureString() ?: "")
- p.setter?.let { text("var ") } ?: text("val ")
- list(p.generics, prefix = "<", suffix = "> ") {
+ }?.name?.let { keyword("$it ") }
+ p.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
+ p.setter?.let { keyword("var ") } ?: keyword("val ")
+ list(p.generics, prefix = "<", suffix = "> ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
annotationsInline(it)
+buildSignature(it)
}
p.receiver?.also {
signatureForProjection(it.type)
- text(".")
+ punctuation(".")
}
link(p.name, p.dri)
- text(": ")
+ operator(": ")
signatureForProjection(p.type)
p.extra[DefaultValue]?.run {
- text(" = $value")
+ operator(" = ")
+ highlightValue(value)
}
}
}
+ private fun PageContentBuilder.DocumentableContentBuilder.highlightValue(expr: Expression) = when (expr) {
+ is IntegerConstant -> constant(expr.value.toString())
+ is FloatConstant -> constant(expr.value.toString() + "f")
+ is DoubleConstant -> constant(expr.value.toString())
+ is BooleanConstant -> booleanLiteral(expr.value)
+ is StringConstant -> stringLiteral("\"${expr.value}\"")
+ is ComplexExpression -> text(expr.value)
+ else -> Unit
+ }
+
private fun functionSignature(f: DFunction) =
f.sourceSets.map {
contentBuilder.contentFor(
@@ -237,37 +261,40 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
sourceSets = setOf(it)
) {
annotationsBlock(f)
- text(f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
- text(f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let {
+ f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- )
- text(f.modifiers()[it]?.toSignatureString() ?: "")
- text("fun ")
+ }?.name?.let { keyword("$it ") }
+ f.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
+ keyword("fun ")
val usedGenerics = if (f.isConstructor) f.generics.filter { f uses it } else f.generics
- list(usedGenerics, prefix = "<", suffix = "> ") {
+ list(usedGenerics, prefix = "<", suffix = "> ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
annotationsInline(it)
+buildSignature(it)
}
f.receiver?.also {
signatureForProjection(it.type)
- text(".")
+ punctuation(".")
}
- link(f.name, f.dri)
- text("(")
- list(f.parameters) {
+ link(f.name, f.dri, styles = mainStyles + TokenStyle.Function)
+ punctuation("(")
+ list(f.parameters,
+ separatorStyles = mainStyles + TokenStyle.Punctuation) {
annotationsInline(it)
processExtraModifiers(it)
text(it.name!!)
- text(": ")
+ operator(": ")
signatureForProjection(it.type)
it.extra[DefaultValue]?.run {
- text(" = $value")
+ operator(" = ")
+ highlightValue(value)
}
}
- text(")")
+ punctuation(")")
if (f.documentReturnType()) {
- text(": ")
+ operator(": ")
signatureForProjection(f.type)
}
}
@@ -291,11 +318,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
sourceSets = platforms.toSet()
) {
annotationsBlock(t)
- text(t.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
+ t.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
processExtraModifiers(t)
- text("typealias ")
+ keyword("typealias ")
signatureForProjection(t.type)
- text(" = ")
+ operator(" = ")
signatureForTypealiasTarget(t, type)
}
}
@@ -306,7 +333,8 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
t.sourceSets.map {
contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) {
signatureForProjection(t.variantTypeParameter.withDri(t.dri.withTargetToDeclaration()))
- list(t.nontrivialBounds, prefix = " : ") { bound ->
+ list(t.nontrivialBounds, prefix = " : ",
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) { bound ->
signatureForProjection(bound)
}
}
@@ -338,24 +366,29 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
val linkText = if (showFullyQualifiedName && p.dri.packageName != null) {
"${p.dri.packageName}.${p.dri.classNames.orEmpty()}"
} else p.dri.classNames.orEmpty()
- if (p.presentableName != null) text(p.presentableName + ": ")
+ if (p.presentableName != null) {
+ text(p.presentableName!!)
+ operator(": ")
+ }
annotationsInline(p)
link(linkText, p.dri)
- list(p.projections, prefix = "<", suffix = ">") {
+ list(p.projections, prefix = "<", suffix = ">",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
signatureForProjection(it, showFullyQualifiedName)
}
}
is Variance<*> -> group(styles = emptySet()) {
- text("$p ".takeIf { it.isNotBlank() } ?: "")
+ keyword("$p ".takeIf { it.isNotBlank() } ?: "")
signatureForProjection(p.inner, showFullyQualifiedName)
}
- is Star -> text("*")
+ is Star -> operator("*")
is Nullable -> group(styles = emptySet()) {
signatureForProjection(p.inner, showFullyQualifiedName)
- text("?")
+ operator("?")
}
is TypeAliased -> signatureForProjection(p.typeAlias)
@@ -373,12 +406,15 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun funType(dri: DRI, sourceSets: Set<DokkaSourceSet>, type: FunctionalTypeConstructor) =
contentBuilder.contentFor(dri, sourceSets, ContentKind.Main) {
- if (type.presentableName != null) text(type.presentableName + ": ")
- if (type.isSuspendable) text("suspend ")
+ if (type.presentableName != null) {
+ text(type.presentableName!!)
+ operator(": ")
+ }
+ if (type.isSuspendable) keyword("suspend ")
if (type.isExtensionFunction) {
signatureForProjection(type.projections.first())
- text(".")
+ punctuation(".")
}
val args = if (type.isExtensionFunction)
@@ -386,12 +422,13 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
else
type.projections
- text("(")
+ punctuation("(")
args.subList(0, args.size - 1).forEachIndexed { i, arg ->
signatureForProjection(arg)
- if (i < args.size - 2) text(", ")
+ if (i < args.size - 2) punctuation(", ")
}
- text(") -> ")
+ punctuation(")")
+ operator(" -> ")
signatureForProjection(args.last())
}
}