/* * 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 class ExtensionBuilderStart internal constructor(){ public fun extensionPoint(ext: ExtensionPoint): ProvidedExtension = ProvidedExtension(ext) } public class ProvidedExtension internal constructor( public val ext: ExtensionPoint ) { public fun fromInstance(inst: T): ExtensionBuilder = createBuilder( LazyEvaluated.fromInstance( inst ) ) public fun fromRecipe(recipe: (DokkaContext) -> T): ExtensionBuilder = createBuilder( LazyEvaluated.fromRecipe(recipe) ) private val defaultName = "${ext.pointName}/in/${javaClass.simpleName}" private fun createBuilder(action: LazyEvaluated) = ExtensionBuilder(defaultName, ext, action, emptyList(), emptyList(), OverrideKind.None, emptyList()) } public data class ExtensionBuilder internal constructor( private val name: String, private val ext: ExtensionPoint, private val action: LazyEvaluated, private val before: List>, private val after: List>, private val override: OverrideKind = OverrideKind.None, private val conditions: List<(DokkaConfiguration) -> Boolean> ){ public fun build(): Extension = Extension( ext, javaClass.name, name, action, OrderingKind.ByDsl { before(*before.toTypedArray()) after(*after.toTypedArray()) }, override, conditions ) public fun overrideExtension(extension: Extension): ExtensionBuilder = copy(override = OverrideKind.Present(listOf(extension))) public fun newOrdering(before: Array>, after: Array>): ExtensionBuilder = copy(before = this.before + before, after = this.after + after) public fun before(vararg exts: Extension<*, *, *>): ExtensionBuilder = copy(before = this.before + exts) public fun after(vararg exts: Extension<*, *, *>): ExtensionBuilder = copy(after = this.after + exts) public fun addCondition(c: (DokkaConfiguration) -> Boolean): ExtensionBuilder = copy(conditions = conditions + c) public fun name(name: String): ExtensionBuilder = copy(name = name) } public abstract class DokkaJavaPlugin: DokkaPlugin() { public fun plugin(clazz: Class): T = context?.plugin(clazz.kotlin) ?: throwIllegalQuery() public fun extend(func: (ExtensionBuilderStart) -> ExtensionBuilder): Lazy> = lazy { func(ExtensionBuilderStart()).build() }.also { unsafeInstall(it) } }