aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactory.kt
blob: 6fb0502460183fc3446b759ee94a88c232b60467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package org.jetbrains.dokka.base.resolvers.external

import org.jetbrains.dokka.links.DRI


interface ExternalLocationProvider {

    val param: String
    fun DRI.toLocation(): String
}

interface ExternalLocationProviderFactory {

    fun getExternalLocationProvider(param: String): ExternalLocationProvider?
}

class ExternalLocationProviderFactoryWithCache(val ext: ExternalLocationProviderFactory) : ExternalLocationProviderFactory {

    private val locationProviders: MutableList<ExternalLocationProvider> = mutableListOf()

    override fun getExternalLocationProvider(param: String): ExternalLocationProvider? =
        locationProviders.find { it.param == param } ?: ext.getExternalLocationProvider(param)?.also { locationProviders.add(it) }
}