plugability.extensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dokka-core Show documentation
Show all versions of dokka-core Show documentation
Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java
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: List>) : 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) } }
}
internal 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, [email protected], extensionName, LazyEvaluated.fromInstance(action))
infix fun ExtensionPoint.providing(action: (DokkaContext) -> T) =
Extension(this, [email protected], 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: List>
) = Extension(extensionPoint, pluginClass, extensionName, action, ordering, OverrideKind.Present(overriden), conditions)
infix fun Extension.override(
overriden: Extension
) = this.override(listOf(overriden))
}
@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
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy