aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt
blob: dd95f00e6cb224a5786f5e7e702070e315e02f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package  org.jetbrains.dokka.kotlinAsJava


import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Module
import org.jetbrains.dokka.pages.ModulePageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.transformers.documentation.DocumentationToPageTranslator
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor

class KotlinAsJavaPlugin : DokkaPlugin() {
    val kotlinAsJavaDescriptorToDocumentableTranslator by extending {
        CoreExtensions.descriptorToDocumentationTranslator providing ::KotlinAsJavaDescriptorToDocumentationTranslator
    }
    val kotlinAsJavaDocumentableToPageTranslator by extending {
        CoreExtensions.documentationToPageTranslator with KotlinAsJavaDocumentationToPageTranslator
    }
}

object DescriptorCache {
    private val cache: HashMap<DRI, DeclarationDescriptor> = HashMap()

    fun add(dri: DRI, descriptor: DeclarationDescriptor): Boolean = cache.putIfAbsent(dri, descriptor) == null
    operator fun get(dri: DRI): DeclarationDescriptor? = cache[dri]
}

object KotlinAsJavaDocumentationToPageTranslator : DocumentationToPageTranslator {
    override fun invoke(module: Module, context: DokkaContext): ModulePageNode =
        KotlinAsJavaPageBuilder { node, kind, operation ->
            KotlinAsJavaPageContentBuilder.group(
                setOf(node.dri),
                node.platformData,
                kind,
                context.single(CoreExtensions.commentsToContentConverter),
                context.logger,
                operation
            )
        }.pageForModule(module)

}