aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-03-03 17:42:48 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-04 14:28:14 +0100
commit156396f7520b3ac45e37068d6b72087008322cbe (patch)
tree51253dde720aae57111760862038393e4cc06204 /plugins/base
parent973cc5238e2f7ede6d9cf54437785770a3e020c9 (diff)
downloaddokka-156396f7520b3ac45e37068d6b72087008322cbe.tar.gz
dokka-156396f7520b3ac45e37068d6b72087008322cbe.tar.bz2
dokka-156396f7520b3ac45e37068d6b72087008322cbe.zip
Replace inline signature generation with KotlinSignatureProvider
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt13
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt42
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt43
5 files changed, 49 insertions, 57 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index 78a51559..f2adcbc1 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -6,6 +6,7 @@ import org.jetbrains.dokka.base.renderers.OutputWriter
import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
import org.jetbrains.dokka.base.resolvers.DefaultLocationProviderFactory
import org.jetbrains.dokka.base.resolvers.LocationProviderFactory
+import org.jetbrains.dokka.base.signatures.KotlinSignatureProvider
import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentableMerger
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
@@ -38,9 +39,19 @@ class DokkaBase : DokkaPlugin() {
CoreExtensions.documentableMerger with DefaultDocumentableMerger
}
+ val kotlinSignatureProvider by extending(isFallback = true) {
+ signatureProvider providing { ctx ->
+ KotlinSignatureProvider(ctx.single(commentsToContentConverter), ctx.logger)
+ }
+ }
+
val documentableToPageTranslator by extending(isFallback = true) {
CoreExtensions.documentableToPageTranslator providing { ctx ->
- DefaultDocumentableToPageTranslator(ctx.single(commentsToContentConverter), ctx.logger)
+ DefaultDocumentableToPageTranslator(
+ ctx.single(commentsToContentConverter),
+ ctx.single(signatureProvider),
+ ctx.logger
+ )
}
}
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 6eddca0d..2d4694bd 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -13,7 +13,7 @@ import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.utilities.DokkaLogger
class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider {
- private val contentBuilder = PageContentBuilder(ctcc, logger)
+ private val contentBuilder = PageContentBuilder(ctcc, this, logger)
override fun signature(documentable: Documentable): List<ContentNode> = when (documentable) {
is Function -> signature(documentable)
@@ -59,7 +59,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
if (generics.isNotEmpty()) {
text("<")
generics.forEach {
- signature(it)
+ this@KotlinSignatureProvider.signature(it)
}
text(">")
}
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt
index 2d9bab90..16f9b9b3 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.translators.documentables
+import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.model.Module
import org.jetbrains.dokka.pages.ModulePageNode
@@ -8,8 +9,9 @@ import org.jetbrains.dokka.utilities.DokkaLogger
class DefaultDocumentableToPageTranslator(
private val commentsToContentConverter: CommentsToContentConverter,
+ private val signatureProvider: SignatureProvider,
private val logger: DokkaLogger
) : DocumentableToPageTranslator {
override fun invoke(module: Module): ModulePageNode =
- DefaultPageCreator(commentsToContentConverter, logger).pageForModule(module)
+ DefaultPageCreator(commentsToContentConverter, signatureProvider, logger).pageForModule(module)
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index f171e15f..5f3772ce 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.translators.documentables
+import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
@@ -12,9 +13,10 @@ import org.jetbrains.dokka.utilities.DokkaLogger
open class DefaultPageCreator(
commentsToContentConverter: CommentsToContentConverter,
+ signatureProvider: SignatureProvider,
val logger: DokkaLogger
) {
- protected open val contentBuilder = PageContentBuilder(commentsToContentConverter, logger)
+ protected open val contentBuilder = PageContentBuilder(commentsToContentConverter, signatureProvider, logger)
open fun pageForModule(m: Module) =
ModulePageNode(m.name.ifEmpty { "<root>" }, contentForModule(m), m, m.packages.map(::pageForPackage))
@@ -50,21 +52,22 @@ open class DefaultPageCreator(
protected open fun contentForPackage(p: Package) = contentBuilder.contentFor(p) {
header(1) { text("Package ${p.name}") }
- contentForScope(p, p.dri, p.platformData)
+ +contentForScope(p, p.dri, p.platformData)
}
- protected open fun PageContentBuilder.DocumentableContentBuilder.contentForScope(
+ protected open fun contentForScope(
s: WithScope,
dri: DRI,
platformData: List<PlatformData>
- ) {
+ ) = contentBuilder.contentFor(s as Documentable) {
block("Types", 2, ContentKind.Classlikes, s.classlikes, platformData.toSet()) {
link(it.name.orEmpty(), it.dri)
+ +signature(it)
text(it.briefDocTagString)
}
block("Functions", 2, ContentKind.Functions, s.functions, platformData.toSet()) {
link(it.name, it.dri)
- signature(it)
+ +signature(it)
text(it.briefDocTagString)
}
block("Properties", 2, ContentKind.Properties, s.properties, platformData.toSet()) {
@@ -74,19 +77,8 @@ open class DefaultPageCreator(
}
protected open fun contentForClasslike(c: Classlike) = contentBuilder.contentFor(c) {
- when (c) { // TODO this when will be removed when signature generation is moved to utils
- is Class, is Object, is Annotation, is Interface -> header(1) { text(c.name ?: "<>") }
- is Enum -> {
- header(1) { text("enum ${c.name}") }
- block("Entries", 2, ContentKind.Properties, c.entries, c.platformData.toSet()) { entry ->
- link(entry.name.orEmpty(), entry.dri)
- contentForComments(entry)
- }
- }
- else -> throw IllegalStateException("$c should not be present here")
- }
-
- contentForComments(c)
+ +signature(c)
+ +contentForComments(c)
if (c is WithConstructors) {
block("Constructors", 2, ContentKind.Constructors, c.constructors, c.platformData.toSet()) {
@@ -96,10 +88,10 @@ open class DefaultPageCreator(
}
}
- contentForScope(c, c.dri, c.platformData)
+ +contentForScope(c, c.dri, c.platformData)
}
- protected open fun PageContentBuilder.DocumentableContentBuilder.contentForComments(d: Documentable) =
+ protected open fun contentForComments(d: Documentable) = contentBuilder.contentFor(d) {
// TODO: this probably needs fixing
d.documentation.forEach { _, documentationNode ->
documentationNode.children.forEach {
@@ -111,12 +103,12 @@ open class DefaultPageCreator(
text("\n")
}
}
-
+ }.children
protected open fun contentForFunction(f: Function) = contentBuilder.contentFor(f) {
header(1) { text(f.name) }
- signature(f)
- contentForComments(f)
+ +signature(f)
+ +contentForComments(f)
block("Parameters", 2, ContentKind.Parameters, f.children, f.platformData.toSet()) {
text(it.name ?: "<receiver>")
it.documentation.forEach { it.value.children.forEach { comment(it.root) } }
@@ -124,8 +116,4 @@ open class DefaultPageCreator(
}
protected open fun TagWrapper.toHeaderString() = this.javaClass.toGenericString().split('.').last()
-}
-
-class A {
- companion object F {}
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 8d04e986..eb422920 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -1,9 +1,9 @@
package org.jetbrains.dokka.base.translators.documentables
+import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.model.TypeWrapper
import org.jetbrains.dokka.model.doc.DocTag
import org.jetbrains.dokka.pages.*
@@ -14,6 +14,7 @@ annotation class ContentBuilderMarker
open class PageContentBuilder(
val commentsConverter: CommentsToContentConverter,
+ val signatureProvider: SignatureProvider,
val logger: DokkaLogger
) {
fun contentFor(
@@ -61,6 +62,14 @@ open class PageContentBuilder(
extras
)
+ operator fun ContentNode.unaryPlus() {
+ contents += this
+ }
+
+ operator fun Collection<ContentNode>.unaryPlus() {
+ contents += this
+ }
+
fun header(
level: Int,
kind: Kind = ContentKind.Main,
@@ -84,31 +93,13 @@ open class PageContentBuilder(
contents += createText(text, kind, platformData, styles, extras)
}
- fun signature(f: Function, block: DocumentableContentBuilder.() -> Unit) {
- contents += buildGroup(f.dri, f.platformData.toSet(), ContentKind.Symbol, mainStyles, mainExtras, block)
- }
-
- fun signature(f: Function) = signature(f) {
- text("fun ")
- f.receiver?.also {
- // TODO signature should be rewritten
- type(it.type)
- text(".")
- }
- link(f.name, f.dri)
- text("(")
- list(f.parameters) {
- link(it.name!!, it.dri)
- text(": ")
- type(it.type)
- }
- text(")")
- val returnType = f.type
- if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) {
- text(": ")
- type(returnType)
- }
- }
+ fun signature(d: Documentable) = ContentGroup(
+ signatureProvider.signature(d),
+ DCI(setOf(d.dri), ContentKind.Symbol),
+ d.platformData.toSet(),
+ mainStyles,
+ mainExtras
+ )
fun linkTable(
elements: List<DRI>,