aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/external/JavadocExternalLocationProviderFactory.kt
blob: c52c9bbbd347ce87265c4296f42d8f4082b184b7 (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
package org.jetbrains.dokka.base.resolvers.external

import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.utilities.htmlEscape

class JavadocExternalLocationProviderFactory : ExternalLocationProviderFactory by ExternalLocationProviderFactoryWithCache(
    object : ExternalLocationProviderFactory {
        override fun getExternalLocationProvider(param: String): ExternalLocationProvider? =
            when(param) {
                "javadoc1"  -> JavadocExternalLocationProvider(param, "()", ", ") // Covers JDK 1 - 7
                "javadoc8"  -> JavadocExternalLocationProvider(param, "--", "-") // Covers JDK 8 - 9
                "javadoc10" -> JavadocExternalLocationProvider(param, "()", ",") // Covers JDK 10
                else -> null
            }
    }
)

class JavadocExternalLocationProvider(override val param: String, val brackets: String, val separator: String) : ExternalLocationProvider {

    override fun DRI.toLocation(): String {

        val packageLink = packageName?.replace(".", "/")
        if (classNames == null) {
            return "$packageLink/package-summary.html".htmlEscape()
        }
        val classLink = if (packageLink == null) "$classNames.html" else "$packageLink/$classNames.html"
        val callableChecked = callable ?: return classLink.htmlEscape()

        val callableLink = "$classLink#" +
                callableChecked.name +
                "${brackets.first()}" +
                callableChecked.params.joinToString(separator) +
                "${brackets.last()}"

        return callableLink.htmlEscape()
    }
}