package org.jetbrains.dokka.plugability import org.jetbrains.dokka.DokkaConfiguration data class ExtensionPoint internal constructor( internal val pluginClass: String, internal val pointName: String ) { override fun toString() = "ExtensionPoint: $pluginClass/$pointName" } sealed class OrderingKind { object None : OrderingKind() class ByDsl(val block: (OrderDsl.() -> Unit)) : OrderingKind() } sealed class OverrideKind { object None : OverrideKind() class Present(val overriden: Extension<*, *, *>) : OverrideKind() } class Extension internal constructor( internal val extensionPoint: ExtensionPoint, internal val pluginClass: String, internal val extensionName: String, internal val action: LazyEvaluated, internal val ordering: Ordering, internal val override: Override, internal val conditions: List Boolean> ) { override fun toString() = "Extension: $pluginClass/$extensionName" override fun equals(other: Any?) = if (other is Extension<*, *, *>) this.pluginClass == other.pluginClass && this.extensionName == other.extensionName else false override fun hashCode() = listOf(pluginClass, extensionName).hashCode() val condition: DokkaConfiguration.() -> Boolean get() = { conditions.all { it(this) } } } private fun Extension( extensionPoint: ExtensionPoint, pluginClass: String, extensionName: String, action: LazyEvaluated ) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.None, OverrideKind.None, emptyList()) @DslMarker annotation class ExtensionsDsl @ExtensionsDsl class ExtendingDSL(private val pluginClass: String, private val extensionName: String) { infix fun ExtensionPoint.with(action: T) = Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action)) infix fun ExtensionPoint.providing(action: (DokkaContext) -> T) = Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action)) infix fun Extension.order( block: OrderDsl.() -> Unit ) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.ByDsl(block), override, conditions) infix fun Extension.applyIf( condition: DokkaConfiguration.() -> Boolean ) = Extension(extensionPoint, pluginClass, extensionName, action, ordering, override, conditions + condition) infix fun Extension.override( overriden: Extension ) = Extension(extensionPoint, pluginClass, extensionName, action, ordering, OverrideKind.Present(overriden), conditions) } @ExtensionsDsl class OrderDsl { internal val previous = mutableSetOf>() internal val following = mutableSetOf>() fun after(vararg extensions: Extension<*, *, *>) { previous += extensions } fun before(vararg extensions: Extension<*, *, *>) { following += extensions } }