/* * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ package org.jetbrains.dokka.plugability import org.jetbrains.dokka.DokkaConfiguration public data class ExtensionPoint internal constructor( internal val pluginClass: String, internal val pointName: String ) { override fun toString(): String = "ExtensionPoint: $pluginClass/$pointName" } public sealed class OrderingKind { public object None : OrderingKind() public class ByDsl( public val block: (OrderDsl.() -> Unit) ) : OrderingKind() } public sealed class OverrideKind { public object None : OverrideKind() public class Present( public val overriden: List> ) : OverrideKind() } public 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(): String = "Extension: $pluginClass/$extensionName" override fun equals(other: Any?): Boolean = if (other is Extension<*, *, *>) this.pluginClass == other.pluginClass && this.extensionName == other.extensionName else false override fun hashCode(): Int = listOf(pluginClass, extensionName).hashCode() public val condition: DokkaConfiguration.() -> Boolean get() = { conditions.all { it(this) } } } internal fun Extension( extensionPoint: ExtensionPoint, pluginClass: String, extensionName: String, action: LazyEvaluated ) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.None, OverrideKind.None, emptyList()) @DslMarker public annotation class ExtensionsDsl @ExtensionsDsl public class ExtendingDSL(private val pluginClass: String, private val extensionName: String) { public infix fun ExtensionPoint.with(action: T): Extension { return Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action)) } public infix fun ExtensionPoint.providing(action: (DokkaContext) -> T): Extension { return Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action)) } public infix fun Extension.order( block: OrderDsl.() -> Unit ): Extension { return Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.ByDsl(block), override, conditions) } public infix fun Extension.applyIf( condition: DokkaConfiguration.() -> Boolean ): Extension { return Extension(extensionPoint, pluginClass, extensionName, action, ordering, override, conditions + condition) } public infix fun Extension.override( overriden: List> ): Extension { return Extension(extensionPoint, pluginClass, extensionName, action, ordering, OverrideKind.Present(overriden), conditions) } public infix fun Extension.override( overriden: Extension ): Extension { return this.override(listOf(overriden)) } } @ExtensionsDsl public class OrderDsl { internal val previous = mutableSetOf>() internal val following = mutableSetOf>() public fun after(vararg extensions: Extension<*, *, *>) { previous += extensions } public fun before(vararg extensions: Extension<*, *, *>) { following += extensions } }