aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability/DokkaContext.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-11-25 15:48:08 +0100
committerPaweł Marks <pmarks@virtuslab.com>2019-11-26 15:27:04 +0100
commit893dd637e3727d455e82f72ff90e823c6e017f7a (patch)
tree7b0aadc78c291b2c1efdd6c58f3bbc9112d54535 /core/src/main/kotlin/plugability/DokkaContext.kt
parenta945617725e8df084270aacd5af76da2b911111e (diff)
downloaddokka-893dd637e3727d455e82f72ff90e823c6e017f7a.tar.gz
dokka-893dd637e3727d455e82f72ff90e823c6e017f7a.tar.bz2
dokka-893dd637e3727d455e82f72ff90e823c6e017f7a.zip
Cache for plugin stubs
Diffstat (limited to 'core/src/main/kotlin/plugability/DokkaContext.kt')
-rw-r--r--core/src/main/kotlin/plugability/DokkaContext.kt12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt
index 7727329c..a5bcd695 100644
--- a/core/src/main/kotlin/plugability/DokkaContext.kt
+++ b/core/src/main/kotlin/plugability/DokkaContext.kt
@@ -5,6 +5,7 @@ import java.io.File
import java.net.URLClassLoader
import java.util.*
import kotlin.reflect.KClass
+import kotlin.reflect.full.createInstance
interface DokkaContext {
operator fun <T : Any, E : ExtensionPoint<T>> get(point: E): List<Extension<T>>
@@ -35,13 +36,18 @@ private class DokkaContextConfigurationImpl(
) : DokkaContext, DokkaContextConfiguration {
private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>()
+ private val pluginStubs = mutableMapOf<KClass<*>, DokkaPlugin>()
+
internal val extensions = mutableMapOf<ExtensionPoint<*>, MutableList<Extension<*>>>()
@Suppress("UNCHECKED_CAST")
override operator fun <T : Any, E : ExtensionPoint<T>> get(point: E) = extensions[point] as List<Extension<T>>
@Suppress("UNCHECKED_CAST")
- override fun <T : DokkaPlugin> plugin(kclass: KClass<T>) = plugins[kclass] as T
+ override fun <T : DokkaPlugin> plugin(kclass: KClass<T>) = (plugins[kclass] ?: pluginStubFor(kclass)) as T
+
+ private fun <T : DokkaPlugin> pluginStubFor(kclass: KClass<T>): DokkaPlugin =
+ pluginStubs.getOrPut(kclass) { kclass.createInstance().also { it.context = this } }
fun install(plugin: DokkaPlugin) {
plugins[plugin::class] = plugin
@@ -59,8 +65,8 @@ private class DokkaContextConfigurationImpl(
val loadedListForDebug = extensions.run { keys + values.flatten() }.toList()
.joinToString(prefix = "[\n", separator = ",\n", postfix = "\n]") { "\t$it" }
- logger.progress("Loaded plugins: ${pluginNames}")
- logger.progress("Loaded: ${loadedListForDebug}")
+ logger.progress("Loaded plugins: $pluginNames")
+ logger.progress("Loaded: $loadedListForDebug")
}
}