aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/CoreExtensions.kt4
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt2
-rw-r--r--core/src/main/kotlin/pages/PageBuilder.kt158
-rw-r--r--core/src/main/kotlin/pages/PageContentBuilder.kt215
-rw-r--r--core/src/main/kotlin/plugability/DefaultExtensions.kt2
-rw-r--r--core/src/main/kotlin/transformers/documentation/DefaultDocumentationToPageTranslator.kt23
-rw-r--r--core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt (renamed from core/src/main/kotlin/transformers/documentation/DocumentationToPageTranslator.kt)2
7 files changed, 4 insertions, 402 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt
index 47f2e4c1..8ae333ee 100644
--- a/core/src/main/kotlin/CoreExtensions.kt
+++ b/core/src/main/kotlin/CoreExtensions.kt
@@ -8,7 +8,7 @@ import org.jetbrains.dokka.resolvers.LocationProviderFactory
import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentationTranslator
import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.dokka.transformers.documentation.DocumentationNodeTransformer
-import org.jetbrains.dokka.transformers.documentation.DocumentationToPageTranslator
+import org.jetbrains.dokka.transformers.documentation.DocumentablesToPageTranslator
import org.jetbrains.dokka.transformers.pages.PageMergerStrategy
import org.jetbrains.dokka.transformers.pages.PageNodeTransformer
import org.jetbrains.dokka.transformers.psi.PsiToDocumentationTranslator
@@ -25,7 +25,7 @@ object CoreExtensions {
val documentableMerger by coreExtension<DocumentableMerger>()
val documentationTransformer by coreExtension<DocumentationNodeTransformer>()
val commentsToContentConverter by coreExtension<CommentsToContentConverter>()
- val documentationToPageTranslator by coreExtension<DocumentationToPageTranslator>()
+ val documentablesToPageTranslator by coreExtension<DocumentablesToPageTranslator>()
val pageTransformer by coreExtension<PageNodeTransformer>()
val locationProviderFactory by coreExtension<LocationProviderFactory>()
val outputWriter by coreExtension<OutputWriter>()
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index 1829c9e4..1ad93f4f 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -88,7 +88,7 @@ class DokkaGenerator(
fun createPages(
transformedDocumentation: Module,
context: DokkaContext
- ) = context.single(CoreExtensions.documentationToPageTranslator).invoke(transformedDocumentation, context)
+ ) = context.single(CoreExtensions.documentablesToPageTranslator).invoke(transformedDocumentation, context)
fun transformPages(
pages: RootPageNode,
diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt
deleted file mode 100644
index eb6f5e21..00000000
--- a/core/src/main/kotlin/pages/PageBuilder.kt
+++ /dev/null
@@ -1,158 +0,0 @@
-package org.jetbrains.dokka.pages
-
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.Enum
-import org.jetbrains.dokka.model.Function
-import org.jetbrains.dokka.model.doc.TagWrapper
-
-open class DefaultPageBuilder(
- override val rootContentGroup: RootContentBuilder
-) : PageBuilder {
-
- override fun pageForModule(m: Module): ModulePageNode =
- ModulePageNode(m.name.ifEmpty { "root" }, contentForModule(m), m, m.packages.map { pageForPackage(it) })
-
- override fun pageForPackage(p: Package) =
- PackagePageNode(p.name, contentForPackage(p), setOf(p.dri), p,
- p.classlikes.map { pageForClasslike(it) } +
- p.functions.map { pageForMember(it) })
-
- override fun pageForClasslike(c: Classlike): ClasslikePageNode {
- val constructors = when (c) {
- is Class -> c.constructors
- is Enum -> c.constructors
- else -> emptyList()
- }
-
- return ClasslikePageNode(c.name, contentForClasslike(c), setOf(c.dri), c,
- constructors.map { pageForMember(it) } +
- c.classlikes.map { pageForClasslike(it) } +
- c.functions.map { pageForMember(it) })
- }
-
- override fun pageForMember(m: CallableNode): MemberPageNode =
- when (m) {
- is Function ->
- MemberPageNode(m.name, contentForFunction(m), setOf(m.dri), m)
- else -> throw IllegalStateException("$m should not be present here")
- }
-
- protected open fun group(node: Documentable, content: PageContentBuilderFunction) =
- rootContentGroup(node, ContentKind.Main, content)
-
- protected open fun contentForModule(m: Module) = group(m) {
- header(1) { text("root") }
- block("Packages", 2, ContentKind.Packages, m.packages, m.platformData) {
- link(it.name, it.dri)
- }
- text("Index\n")
- text("Link to allpage here")
- }
-
- protected open fun contentForPackage(p: Package) = group(p) {
- header(1) { text("Package ${p.name}") }
- block("Types", 2, ContentKind.Properties, p.classlikes, p.platformData) {
- link(it.name, it.dri)
- text(it.briefDocTagString)
- }
- block("Functions", 2, ContentKind.Functions, p.functions, p.platformData) {
- link(it.name, it.dri)
- signature(it)
- text(it.briefDocTagString)
- }
- }
-
- open fun contentForClasslike(c: Classlike): ContentGroup = when (c) {
- is Class -> contentForClass(c)
- is Enum -> contentForEnum(c)
- else -> throw IllegalStateException("$c should not be present here")
- }
-
- protected fun contentForClass(c: Class) = group(c) {
- header(1) { text(c.name) }
-
- c.inherited.takeIf { it.isNotEmpty() }?.let {
- header(2) { text("SuperInterfaces") }
- linkTable(it)
- }
- contentForComments(c)
- block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) {
- link(it.name, it.dri)
- signature(it)
- text(it.briefDocTagString)
- }
- block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) {
- link(it.name, it.dri)
- signature(it)
- text(it.briefDocTagString)
- }
- block("Properties", 2, ContentKind.Properties, c.properties, c.platformData) {
- link(it.name, it.dri)
- text(it.briefDocTagString)
-
- }
- }
-
- fun contentForEnum(c: Enum): ContentGroup = group(c) {
- header(1) { text("enum ${c.name}") }
-
- block("Entries", 2, ContentKind.Properties, c.entries, c.platformData) { entry ->
- link(entry.name, entry.dri)
- contentForComments(entry)
- }
-
- c.inherited.takeIf { it.isNotEmpty() }?.let {
- header(2) { text("SuperInterfaces") }
- linkTable(it)
- }
- contentForComments(c)
- block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) {
- link(it.name, it.dri)
- signature(it)
- text(it.briefDocTagString)
- }
- block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) {
- link(it.name, it.dri)
- signature(it)
- text(it.briefDocTagString)
- }
- block("Properties", 2, ContentKind.Properties, c.properties, c.platformData) {
- link(it.name, it.dri)
- text(it.briefDocTagString)
- }
- }
-
- private fun PageContentBuilder.contentForComments(d: Documentable) =
- d.platformInfo.forEach { platformInfo ->
- platformInfo.documentationNode.children.forEach {
- header(3) {
- text(it.toHeaderString())
- text(" [${platformInfo.platformData.joinToString(", ") { it.platformType.name }}]")
- }
- comment(it.root)
- text("\n")
- }
- }
-
- private fun contentForFunction(f: Function) = group(f) {
- header(1) { text(f.name) }
- signature(f)
- contentForComments(f)
- block("Parameters", 2, ContentKind.Parameters, f.children, f.platformData) {
- text(it.name ?: "<receiver>")
- it.platformInfo.forEach { it.documentationNode.children.forEach { comment(it.root) } }
- }
- }
-
- private fun TagWrapper.toHeaderString() = this.javaClass.toGenericString().split('.').last()
-}
-
-typealias RootContentBuilder = (Documentable, Kind, PageContentBuilderFunction) -> ContentGroup
-
-interface PageBuilder {
- val rootContentGroup: RootContentBuilder
- fun pageForModule(m: Module): ModulePageNode
- fun pageForPackage(p: Package): PackagePageNode
- fun pageForMember(m: CallableNode): MemberPageNode
- fun pageForClasslike(c: Classlike): ClasslikePageNode
-} \ No newline at end of file
diff --git a/core/src/main/kotlin/pages/PageContentBuilder.kt b/core/src/main/kotlin/pages/PageContentBuilder.kt
deleted file mode 100644
index ed0a0fea..00000000
--- a/core/src/main/kotlin/pages/PageContentBuilder.kt
+++ /dev/null
@@ -1,215 +0,0 @@
-package org.jetbrains.dokka.pages
-
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.Function
-import org.jetbrains.dokka.model.Parameter
-import org.jetbrains.dokka.model.TypeWrapper
-import org.jetbrains.dokka.model.doc.DocTag
-import org.jetbrains.dokka.utilities.DokkaLogger
-
-open class DefaultPageContentBuilder(
- private val dri: Set<DRI>,
- private val platformData: Set<PlatformData>,
- private val kind: Kind,
- private val commentsConverter: CommentsToContentConverter,
- open val logger: DokkaLogger,
- private val styles: Set<Style> = emptySet(),
- private val extras: Set<Extra> = emptySet()
-) : PageContentBuilder {
- protected val contents = mutableListOf<ContentNode>()
-
- protected fun createText(text: String, kind: Kind = ContentKind.Symbol) =
- ContentText(text, DCI(dri, kind), platformData, styles, extras)
-
- protected fun build() = ContentGroup(
- contents.toList(),
- DCI(dri, kind),
- platformData,
- styles,
- extras
- )
-
- override fun header(level: Int, block: PageContentBuilderFunction) {
- contents += ContentHeader(level, group(ContentKind.Symbol, block))
- }
-
- override fun text(text: String, kind: Kind) {
- contents += createText(text, kind)
- }
-
- protected fun signature(f: Function, block: PageContentBuilderFunction) {
- contents += group(setOf(f.dri), f.platformData, ContentKind.Symbol, block)
- }
-
- override fun signature(f: Function) = signature(f) {
- text("fun ")
- if (f.receiver is Parameter) {
- type(f.receiver.type)
- text(".")
- }
- link(f.name, f.dri)
- text("(")
- list(f.parameters) {
- link(it.name!!, it.dri)
- text(": ")
- type(it.type)
- }
- text(")")
- val returnType = f.returnType
- if (!f.isConstructor && returnType != null &&
- returnType.constructorFqName != Unit::class.qualifiedName) {
- text(": ")
- type(returnType)
- }
- }
-
- override fun linkTable(elements: List<DRI>) {
- contents += ContentTable(
- emptyList(),
- elements.map { group(dri, platformData, ContentKind.Classes) { link(it.classNames ?: "", it) } },
- DCI(dri, kind),
- platformData, styles, extras
- )
- }
-
- override fun <T : Documentable> block(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- platformData: Set<PlatformData>,
- operation: PageContentBuilder.(T) -> Unit
- ) {
- header(level) { text(name) }
-
- contents += ContentTable(
- emptyList(),
- elements.map { group(setOf(it.dri), it.platformData, kind) { operation(it) } },
- DCI(dri, kind),
- platformData, styles, extras
- )
- }
-
- override fun <T> list(
- elements: List<T>,
- prefix: String,
- suffix: String,
- separator: String,
- operation: PageContentBuilder.(T) -> Unit
- ) {
- if (elements.isNotEmpty()) {
- if (prefix.isNotEmpty()) text(prefix)
- elements.dropLast(1).forEach {
- operation(it)
- text(separator)
- }
- operation(elements.last())
- if (suffix.isNotEmpty()) text(suffix)
- }
- }
-
- override fun link(text: String, address: DRI, kind: Kind) {
- contents += ContentDRILink(
- listOf(createText(text)),
- address,
- DCI(dri, kind),
- platformData
- )
- }
-
- override fun link(address: DRI, kind: Kind, block: PageContentBuilderFunction) {
- contents += ContentDRILink(
- group(ContentKind.Main, block).children,
- address,
- DCI(dri, kind),
- platformData
- )
- }
-
- override fun comment(docTag: DocTag) {
- contents += group(ContentKind.Comment) {
- with(this as DefaultPageContentBuilder) {
- contents += commentsConverter.buildContent(
- docTag,
- DCI(dri, ContentKind.Comment),
- platformData
- )
- }
- }
- }
-
- fun group(kind: Kind, block: PageContentBuilderFunction): ContentGroup =
- group(dri, platformData, kind, block)
-
- override fun group(
- dri: Set<DRI>,
- platformData: Set<PlatformData>,
- kind: Kind,
- block: PageContentBuilderFunction
- ): ContentGroup = group(dri, platformData, kind, commentsConverter, logger, block)
-
- companion object {
- fun group(
- dri: Set<DRI>,
- platformData: Set<PlatformData>,
- kind: Kind,
- commentsConverter: CommentsToContentConverter,
- logger: DokkaLogger,
- block: PageContentBuilderFunction
- ): ContentGroup =
- DefaultPageContentBuilder(dri, platformData, kind, commentsConverter, logger).apply(block).build()
- }
-}
-
-
-fun PageContentBuilder.type(t: TypeWrapper) {
- if (t.constructorNamePathSegments.isNotEmpty() && t.dri != null)
- link(t.constructorNamePathSegments.last(), t.dri!!)
- else if (t.constructorNamePathSegments.isNotEmpty() && t.dri == null)
- text(t.toString())
- else (this as? DefaultPageContentBuilder)?.let {
- logger.error("type $t cannot be resolved")
- text("???")
- }
- list(t.arguments, prefix = "<", suffix = ">") {
- type(it)
- }
-}
-
-typealias PageContentBuilderFunction = PageContentBuilder.() -> Unit
-
-@DslMarker
-annotation class ContentMarker
-
-@ContentMarker
-interface PageContentBuilder {
- fun group(
- dri: Set<DRI>,
- platformData: Set<PlatformData>,
- kind: Kind, block: PageContentBuilderFunction
- ): ContentGroup
- fun text(text: String, kind: Kind = ContentKind.Symbol)
- fun signature(f: Function)
- fun link(text: String, address: DRI, kind: Kind = ContentKind.Symbol)
- fun link(address: DRI, kind: Kind = ContentKind.Symbol, block: PageContentBuilderFunction)
- fun linkTable(elements: List<DRI>)
- fun comment(docTag: DocTag)
- fun header(level: Int, block: PageContentBuilderFunction)
- fun <T> list(
- elements: List<T>,
- prefix: String = "",
- suffix: String = "",
- separator: String = ",",
- operation: PageContentBuilder.(T) -> Unit
- )
-
- fun <T : Documentable> block(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- platformData: Set<PlatformData>,
- operation: PageContentBuilder.(T) -> Unit
- )
-} \ No newline at end of file
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt
index c1a72c74..7c76afe7 100644
--- a/core/src/main/kotlin/plugability/DefaultExtensions.kt
+++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt
@@ -6,7 +6,6 @@ import org.jetbrains.dokka.renderers.FileWriter
import org.jetbrains.dokka.renderers.OutputWriter
import org.jetbrains.dokka.renderers.html.HtmlRenderer
import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory
-import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator
import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy
import org.jetbrains.dokka.transformers.psi.DefaultPsiToDocumentationTranslator
import org.jetbrains.dokka.transformers.pages.DefaultPageNodeMerger
@@ -28,7 +27,6 @@ internal object DefaultExtensions {
when (point) {
CoreExtensions.psiToDocumentationTranslator -> DefaultPsiToDocumentationTranslator
CoreExtensions.commentsToContentConverter -> converter.get(fullContext)
- CoreExtensions.documentationToPageTranslator -> DefaultDocumentationToPageTranslator
CoreExtensions.pageTransformer -> DefaultPageNodeMerger(fullContext)
CoreExtensions.renderer -> renderer.get(fullContext)
CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext)
diff --git a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DefaultDocumentationToPageTranslator.kt
deleted file mode 100644
index c2a21150..00000000
--- a/core/src/main/kotlin/transformers/documentation/DefaultDocumentationToPageTranslator.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.jetbrains.dokka.transformers.documentation
-
-import org.jetbrains.dokka.CoreExtensions
-import org.jetbrains.dokka.model.Module
-import org.jetbrains.dokka.pages.DefaultPageBuilder
-import org.jetbrains.dokka.pages.DefaultPageContentBuilder
-import org.jetbrains.dokka.pages.ModulePageNode
-import org.jetbrains.dokka.plugability.DokkaContext
-
-
-object DefaultDocumentationToPageTranslator : DocumentationToPageTranslator {
- override fun invoke(module: Module, context: DokkaContext): ModulePageNode =
- DefaultPageBuilder { node, kind, operation ->
- DefaultPageContentBuilder.group(
- setOf(node.dri),
- node.platformData,
- kind,
- context.single(CoreExtensions.commentsToContentConverter),
- context.logger,
- operation
- )
- }.pageForModule(module)
-} \ No newline at end of file
diff --git a/core/src/main/kotlin/transformers/documentation/DocumentationToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt
index 08c26b19..fa74d216 100644
--- a/core/src/main/kotlin/transformers/documentation/DocumentationToPageTranslator.kt
+++ b/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt
@@ -4,6 +4,6 @@ import org.jetbrains.dokka.model.Module
import org.jetbrains.dokka.pages.ModulePageNode
import org.jetbrains.dokka.plugability.DokkaContext
-interface DocumentationToPageTranslator {
+interface DocumentablesToPageTranslator {
operator fun invoke(module: Module, context: DokkaContext): ModulePageNode
} \ No newline at end of file