package org.jetbrains.dokka.plugability data class ExtensionPoint internal constructor( internal val pluginClass: String, internal val pointName: String ) { override fun toString() = "ExtensionPoint: $pluginClass/$pointName" } abstract class Extension internal constructor( internal val extensionPoint: ExtensionPoint, internal val pluginClass: String, internal val extensionName: String, internal val action: LazyEvaluated, internal val ordering: (OrderDsl.() -> Unit)? = null ) { 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() } class ExtensionOrdered internal constructor( extensionPoint: ExtensionPoint, pluginClass: String, extensionName: String, action: LazyEvaluated, ordering: (OrderDsl.() -> Unit) ) : Extension( extensionPoint, pluginClass, extensionName, action, ordering ) class ExtensionUnordered internal constructor( extensionPoint: ExtensionPoint, pluginClass: String, extensionName: String, action: LazyEvaluated ) : Extension( extensionPoint, pluginClass, extensionName, action, null ) internal data class Ordering(val previous: Set>, val following: Set>) @DslMarker annotation class ExtensionsDsl @ExtensionsDsl class ExtendingDSL(private val pluginClass: String, private val extensionName: String) { infix fun ExtensionPoint.with(action: T) = ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action)) infix fun ExtensionPoint.providing(action: (DokkaContext) -> T) = ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action)) infix fun ExtensionUnordered.order(block: OrderDsl.() -> Unit) = ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, block) } @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 } }