From 13edb873db122e2088207ca10b94382e30875636 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 16 Jul 2020 10:24:02 +0200 Subject: Use jackson for json serialization and parsing --- core/src/main/kotlin/plugability/DokkaPlugin.kt | 30 ++++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'core/src/main/kotlin/plugability/DokkaPlugin.kt') diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index 2c755a49..a62327d2 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -1,7 +1,8 @@ package org.jetbrains.dokka.plugability -import com.google.gson.Gson import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.utilities.parseJson +import org.jetbrains.dokka.utilities.toJsonString import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty import kotlin.reflect.KProperty1 @@ -15,13 +16,12 @@ abstract class DokkaPlugin { protected inline fun plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery() - protected fun extensionPoint() = - object : ReadOnlyProperty> { - override fun getValue(thisRef: DokkaPlugin, property: KProperty<*>) = ExtensionPoint( - thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), - property.name - ) - } + protected fun extensionPoint() = ReadOnlyProperty> { thisRef, property -> + ExtensionPoint( + thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), + property.name + ) + } protected fun extending(definition: ExtendingDSL.() -> Extension) = ExtensionProvider(definition) @@ -58,7 +58,7 @@ inline fun Configurable val instance = T::class.createInstance().apply(block) val mutablePluginsConfiguration = pluginsConfiguration as MutableMap - mutablePluginsConfiguration[P::class.qualifiedName!!] = Gson().toJson(instance, T::class.java) + mutablePluginsConfiguration[P::class.qualifiedName!!] = toJsonString(instance) } inline fun P.query(extension: P.() -> ExtensionPoint): List = @@ -71,12 +71,10 @@ fun throwIllegalQuery(): Nothing = throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") inline fun configuration(context: DokkaContext): ReadOnlyProperty { - return object : ReadOnlyProperty { - override fun getValue(thisRef: Any?, property: KProperty<*>): R { - return context.configuration.pluginsConfiguration[T::class.qualifiedName - ?: throw AssertionError("Plugin must be named class")].let { - Gson().fromJson(it, R::class.java) - } - } + return ReadOnlyProperty { _, _ -> + val configuration = context.configuration.pluginsConfiguration[ + T::class.qualifiedName ?: throw AssertionError("Plugin must be named class") + ] + parseJson(checkNotNull(configuration)) } } -- cgit