aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability/DokkaPlugin.kt
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-08-31 20:16:01 +0200
committerGitHub <noreply@github.com>2023-08-31 20:16:01 +0200
commit02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 (patch)
tree66f6d6f089a93b863bf1144666491eca6729ad05 /core/src/main/kotlin/plugability/DokkaPlugin.kt
parent6a181a7a2b03ec263788d137610e86937a57d434 (diff)
downloaddokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.gz
dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.bz2
dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.zip
Enable explicit API mode (#3139)
Diffstat (limited to 'core/src/main/kotlin/plugability/DokkaPlugin.kt')
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt51
1 files changed, 29 insertions, 22 deletions
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<KProperty<*>>()
private val unsafePlugins = mutableListOf<Lazy<Extension<*, *, *>>>()
@@ -47,29 +47,36 @@ abstract class DokkaPlugin {
protected abstract fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement
protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery()
- protected fun <T : Any> extensionPoint() = ReadOnlyProperty<DokkaPlugin, ExtensionPoint<T>> { thisRef, property ->
- ExtensionPoint(
- thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"),
- property.name
- )
+ protected fun <T : Any> extensionPoint(): ReadOnlyProperty<DokkaPlugin, ExtensionPoint<T>> {
+ return ReadOnlyProperty { thisRef, property ->
+ ExtensionPoint(
+ thisRef::class.qualifiedName ?: throw AssertionError("Plugin must be named class"),
+ property.name
+ )
+ }
+ }
+ protected fun <T : Any> extending(definition: ExtendingDSL.() -> Extension<T, *, *>): ExtensionProvider<T> {
+ return ExtensionProvider(definition)
}
- protected fun <T : Any> extending(definition: ExtendingDSL.() -> Extension<T, *, *>) = ExtensionProvider(definition)
protected class ExtensionProvider<T : Any> internal constructor(
private val definition: ExtendingDSL.() -> Extension<T, *, *>
) {
- 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<Extension<T, *, *>> {
+ 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<KProperty1<DokkaPlugin, Extension<*, *, *>>>() // 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<Extension<*, *, *>>
+public interface WithUnsafeExtensionSuppression {
+ public val extensionsSuppressed: List<Extension<*, *, *>>
}
-interface ConfigurableBlock
+public interface ConfigurableBlock
-inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> =
+public inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> =
context?.let { it[extension()] } ?: throwIllegalQuery()
-inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P.() -> ExtensionPoint<E>): E =
+public inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P.() -> ExtensionPoint<E>): 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 <reified T : DokkaPlugin, reified R : ConfigurableBlock> configuration(context: DokkaContext): R? =
+public inline fun <reified T : DokkaPlugin, reified R : ConfigurableBlock> configuration(context: DokkaContext): R? =
context.configuration.pluginsConfiguration.firstOrNull { it.fqPluginName == T::class.qualifiedName }
?.let { configuration ->
when (configuration.serializationFormat) {