aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/signatures
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-03-04 00:29:36 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:28:14 +0100
commit89c33f431a43caa07365ec69b2b57f3b4e9a01c6 (patch)
treea48238a60970e7ac75efbc4e3ca5f182f6430b8d /plugins/base/src/main/kotlin/signatures
parentd08591dea709917553c0d6de024820bb29b328fb (diff)
downloaddokka-89c33f431a43caa07365ec69b2b57f3b4e9a01c6.tar.gz
dokka-89c33f431a43caa07365ec69b2b57f3b4e9a01c6.tar.bz2
dokka-89c33f431a43caa07365ec69b2b57f3b4e9a01c6.zip
Big refactor of signature provider
Diffstat (limited to 'plugins/base/src/main/kotlin/signatures')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt91
-rw-r--r--plugins/base/src/main/kotlin/signatures/SignatureProvider.kt2
2 files changed, 46 insertions, 47 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 2d4694bd..0706d387 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -2,9 +2,9 @@ package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
-import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.sureClassNames
import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.Annotation
import org.jetbrains.dokka.model.Enum
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.pages.ContentKind
@@ -15,56 +15,51 @@ import org.jetbrains.dokka.utilities.DokkaLogger
class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider {
private val contentBuilder = PageContentBuilder(ctcc, this, logger)
- override fun signature(documentable: Documentable): List<ContentNode> = when (documentable) {
+ override fun signature(documentable: Documentable): ContentNode = when (documentable) {
is Function -> signature(documentable)
is Classlike -> signature(documentable)
+ is TypeParameter -> signature(documentable)
else -> throw NotImplementedError(
"Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}"
)
}
- private fun signature(f: Function) = f.platformData.map { signature(f, it) }.distinct()
-
- private fun signature(c: Classlike) = c.platformData.map { signature(c, it) }.distinct()
-
- private fun signature(c: Classlike, platform: PlatformData) = contentBuilder.contentFor(c, ContentKind.Symbol) {
- text(c.visibility[platform]?.externalDisplayName ?: "")
+ private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) {
+ platformText(c.visibility) { it.externalDisplayName + " " }
if (c is Class) {
- text(c.modifier.toString())
+ text(c.modifier.toString() + " ")
}
when (c) {
- is Class -> text(" class ")
- is Interface -> text(" interface ")
- is Enum -> text(" enum ")
- is Object -> text(" object ")
+ is Class -> text("class ")
+ is Interface -> text("interface ")
+ is Enum -> text("enum ")
+ is Object -> text("object ")
+ is Annotation -> text("annotation class ")
}
text(c.name!!)
if (c is WithSupertypes) {
- list(c.supertypes.getValue(platform), prefix = " : ") {
- link(it.sureClassNames, it)
+ c.supertypes.map { (p, dris) ->
+ list(dris, prefix = " : ", platformData = setOf(p)) {
+ link(it.sureClassNames, it, platformData = setOf(p))
+ }
}
}
}
- private fun signature(f: Function, platform: PlatformData) = contentBuilder.contentFor(f, ContentKind.Symbol) {
- text(f.visibility[platform]?.externalDisplayName ?: "")
- text(f.modifier.toString())
- text(" fun ")
+ private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) {
+ platformText(f.visibility) { it.externalDisplayName + " " }
+ text(f.modifier.toString() + " ")
+ text("fun ")
f.receiver?.also {
type(it.type)
text(".")
}
link(f.name, f.dri)
- val generics = f.generics.filterOnPlatform(platform)
- if (generics.isNotEmpty()) {
- text("<")
- generics.forEach {
- this@KotlinSignatureProvider.signature(it)
- }
- text(">")
+ list(f.generics, prefix = "<", suffix = ">") {
+ +buildSignature(it)
}
text("(")
- list(f.parameters.filterOnPlatform(platform)) {
+ list(f.parameters) {
link(it.name!!, it.dri)
text(": ")
type(it.type)
@@ -73,41 +68,45 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
val returnType = f.type
if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) {
text(": ")
-
type(returnType)
}
}
private fun signature(t: TypeParameter) = contentBuilder.contentFor(t, ContentKind.Symbol) {
link(t.name, t.dri)
- if (t.bounds.isNotEmpty()) {
- text("<")
- t.bounds.forEach {
- signature(it, t.dri, t.platformData)
- }
- text(">")
+ list(t.bounds, prefix = " : ") {
+ signatureForProjection(it)
}
}
- private fun signature(p: Projection, dri: DRI, platforms: List<PlatformData>): List<ContentNode> = when (p) {
- is OtherParameter -> contentBuilder.contentFor(dri, platforms.toSet()) { text(p.name) }.children
+ private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) {
+ is OtherParameter -> text(p.name)
- is TypeConstructor -> contentBuilder.contentFor(dri, platforms.toSet()) {
+ is TypeConstructor -> group {
link(p.dri.classNames.orEmpty(), p.dri)
- }.children + p.projections.flatMap { signature(it, dri, platforms) }
+ list(p.projections, prefix = "<", suffix = ">") {
+ signatureForProjection(it)
+ }
+ }
- is Variance -> contentBuilder.contentFor(dri, platforms.toSet()) {
+ is Variance -> group {
text(p.kind.toString() + " ")
- }.children + signature(p.inner, dri, platforms)
+ signatureForProjection(p.inner)
+ }
- is Star -> contentBuilder.contentFor(dri, platforms.toSet()) { text("*") }.children
+ is Star -> text("*")
- is Nullable -> signature(p.inner, dri, platforms) + contentBuilder.contentFor(
- dri,
- platforms.toSet()
- ) { text("?") }.children
+ is Nullable -> group {
+ signatureForProjection(p.inner)
+ text("?")
+ }
}
private fun <T : Documentable> Collection<T>.filterOnPlatform(platformData: PlatformData) =
this.filter { it.platformData.contains(platformData) }
-} \ No newline at end of file
+}
+
+private fun <T> PageContentBuilder.DocumentableContentBuilder.platformText(
+ value: PlatformDependent<T>,
+ transform: (T) -> String
+) = value.entries.forEach { (p, v) -> text(transform(v), platformData = setOf(p)) } \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
index 738f405a..041015fc 100644
--- a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt
@@ -4,5 +4,5 @@ import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.pages.ContentNode
interface SignatureProvider {
- fun signature(documentable: Documentable): List<ContentNode>
+ fun signature(documentable: Documentable): ContentNode
} \ No newline at end of file