From 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 31 Aug 2023 20:16:01 +0200 Subject: Enable explicit API mode (#3139) --- core/src/main/kotlin/plugability/DokkaPlugin.kt | 51 ++++++++++++++----------- 1 file changed, 29 insertions(+), 22 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 521404e2..7e15c325 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -22,16 +22,16 @@ import kotlin.reflect.KProperty1 ) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.FIELD) @Retention(AnnotationRetention.BINARY) -annotation class DokkaPluginApiPreview +public annotation class DokkaPluginApiPreview /** * Acknowledgement for empty methods that inform users about [DokkaPluginApiPreview] * Also, it allows to not propagates the annotation in IDE by default when a user autogenerate methods. */ @DokkaPluginApiPreview -object PluginApiPreviewAcknowledgement +public object PluginApiPreviewAcknowledgement -abstract class DokkaPlugin { +public abstract class DokkaPlugin { private val extensionDelegates = mutableListOf>() private val unsafePlugins = mutableListOf>>() @@ -47,29 +47,36 @@ abstract class DokkaPlugin { protected abstract fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement protected inline fun plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery() - protected fun extensionPoint() = ReadOnlyProperty> { thisRef, property -> - ExtensionPoint( - thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), - property.name - ) + protected fun extensionPoint(): ReadOnlyProperty> { + return ReadOnlyProperty { thisRef, property -> + ExtensionPoint( + thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), + property.name + ) + } + } + protected fun extending(definition: ExtendingDSL.() -> Extension): ExtensionProvider { + return ExtensionProvider(definition) } - protected fun extending(definition: ExtendingDSL.() -> Extension) = ExtensionProvider(definition) protected class ExtensionProvider internal constructor( private val definition: ExtendingDSL.() -> Extension ) { - operator fun provideDelegate(thisRef: DokkaPlugin, property: KProperty<*>) = lazy { - ExtendingDSL( - thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), - property.name - ).definition() - }.also { thisRef.extensionDelegates += property } + public operator fun provideDelegate(thisRef: DokkaPlugin, property: KProperty<*>): Lazy> { + return lazy { + ExtendingDSL( + thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"), + property.name + ).definition() + }.also { thisRef.extensionDelegates += property } + } } internal fun internalInstall(ctx: DokkaContextConfiguration, configuration: DokkaConfiguration) { val extensionsToInstall = extensionDelegates.asSequence() .filterIsInstance>>() // should be always true .map { it.get(this) } + unsafePlugins.map { it.value } + extensionsToInstall.forEach { if (configuration.(it.condition)()) ctx.installExtension(it) } } @@ -78,22 +85,22 @@ abstract class DokkaPlugin { } } -interface WithUnsafeExtensionSuppression { - val extensionsSuppressed: List> +public interface WithUnsafeExtensionSuppression { + public val extensionsSuppressed: List> } -interface ConfigurableBlock +public interface ConfigurableBlock -inline fun P.query(extension: P.() -> ExtensionPoint): List = +public inline fun P.query(extension: P.() -> ExtensionPoint): List = context?.let { it[extension()] } ?: throwIllegalQuery() -inline fun P.querySingle(extension: P.() -> ExtensionPoint): E = +public inline fun P.querySingle(extension: P.() -> ExtensionPoint): E = context?.single(extension()) ?: throwIllegalQuery() -fun throwIllegalQuery(): Nothing = +public fun throwIllegalQuery(): Nothing = throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") -inline fun configuration(context: DokkaContext): R? = +public inline fun configuration(context: DokkaContext): R? = context.configuration.pluginsConfiguration.firstOrNull { it.fqPluginName == T::class.qualifiedName } ?.let { configuration -> when (configuration.serializationFormat) { -- cgit