aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt
blob: 05896d111b35539c76d4111a37249cd4c365e243 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.jetbrains.dokka.kotlinAsJava

import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.transformers.psi.JavaTypeWrapper
import org.jetbrains.dokka.utilities.DokkaLogger

class KotlinAsJavaPageContentBuilder(
    private val dri: Set<DRI>,
    private val platformData: Set<PlatformData>,
    private val kind: Kind,
    private val commentsConverter: CommentsToContentConverter,
    override val logger: DokkaLogger,
    private val styles: Set<Style> = emptySet(),
    private val extras: Set<Extra> = emptySet()
) : DefaultPageContentBuilder(dri, platformData, kind, commentsConverter, logger, styles, extras) {

    override fun signature(f: Function) = signature(f) {

        //        DokkaConsoleLogger.info("KotlinAsJavaSignature")
        val returnType = f.returnType
        if (!f.isConstructor) {
            if (returnType != null &&
                returnType.constructorFqName != Unit::class.qualifiedName
            ) {
                if ((returnType as? JavaTypeWrapper)?.isPrimitive == true)
                    text(returnType.constructorFqName ?: "")
                else
                    type(returnType)
                text(" ")
            } else text("void ")

        }

        link(f.name, f.dri)
        text("(")
        val params = listOfNotNull(f.receiver) + f.parameters
        list(params) {
            if ((it.type as? JavaTypeWrapper)?.isPrimitive == true)
                text(it.type.constructorFqName ?: "")
            else
                type(it.type)

            text(" ")
            link(it.name ?: "receiver", it.dri)
        }
        text(")")
    }

    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 =
            KotlinAsJavaPageContentBuilder(dri, platformData, kind, commentsConverter, logger).apply(block).build()
    }
}