aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt
blob: 02e6ff82dbf6df7091b75f7704d5b44ae21b00e4 (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
70
71
72
package org.jetbrains.dokka.kotlinAsJava

import org.jetbrains.dokka.base.transformers.documentables.DefaultPageContentBuilder
import org.jetbrains.dokka.base.transformers.documentables.PageContentBuilderFunction
import org.jetbrains.dokka.base.transformers.documentables.type
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.model.JavaTypeWrapper
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.utilities.DokkaLogger

class KotlinAsJavaPageContentBuilder(
    dri: Set<DRI>,
    platformData: Set<PlatformData>,
    kind: Kind,
    commentsConverter: CommentsToContentConverter,
    logger: DokkaLogger,
    styles: Set<Style> = emptySet(),
    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()
    }
}