-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa745c9
commit db21563
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.jetbrains.dokka.plugability | ||
|
||
import org.jetbrains.dokka.DokkaConfiguration | ||
|
||
class ExtensionBuilderStart internal constructor(){ | ||
fun <T: Any> extensionPoint(ext: ExtensionPoint<T>): ProvidedExtension<T> = ProvidedExtension(ext) | ||
} | ||
|
||
class ProvidedExtension<T: Any> internal constructor(val ext: ExtensionPoint<T>){ | ||
fun fromInstance(inst: T): ExtensionBuilder<T> = createBuilder( | ||
LazyEvaluated.fromInstance( | ||
inst | ||
) | ||
) | ||
fun fromRecipe(recipe: (DokkaContext) -> T): ExtensionBuilder<T> = createBuilder( | ||
LazyEvaluated.fromRecipe(recipe) | ||
) | ||
|
||
private val defaultName = "${ext.pointName}/in/${javaClass.simpleName}" | ||
|
||
private fun createBuilder(action: LazyEvaluated<T>) = | ||
ExtensionBuilder(defaultName, ext, action, | ||
OrderingKind.None, | ||
OverrideKind.None, emptyList()) | ||
} | ||
|
||
data class ExtensionBuilder<T: Any> internal constructor( | ||
private val name: String, | ||
private val ext: ExtensionPoint<T>, | ||
private val action: LazyEvaluated<T>, | ||
private val ordering: OrderingKind = OrderingKind.None, | ||
private val override: OverrideKind = OverrideKind.None, | ||
private val conditions: List<(DokkaConfiguration) -> Boolean> | ||
){ | ||
fun build(): Extension<T, *, *> = Extension( | ||
ext, | ||
javaClass.name, | ||
name, | ||
action, | ||
ordering, | ||
override, | ||
conditions | ||
) | ||
|
||
fun overrideExtension(extension: Extension<T, *, *>) = copy(override = OverrideKind.Present(extension)) | ||
|
||
fun newOrdering(before: Array<Extension<*, *, *>>, after: Array<Extension<*, *, *>>) { | ||
copy(ordering = OrderingKind.ByDsl { | ||
before(*before) | ||
after(*after) | ||
}) | ||
} | ||
|
||
fun addCondition(c: (DokkaConfiguration) -> Boolean) = copy(conditions = conditions + c) | ||
|
||
fun name(name: String) = copy(name = name) | ||
} | ||
|
||
abstract class DokkaJavaPlugin: DokkaPlugin() { | ||
|
||
fun <T: DokkaPlugin> plugin(clazz: Class<T>): T? = | ||
context?.plugin(clazz.kotlin) ?: throwIllegalQuery() | ||
|
||
|
||
fun <T: Any> extend(func: (ExtensionBuilderStart) -> ExtensionBuilder<T>): Lazy<Extension<T, *, *>> = | ||
lazy { func(ExtensionBuilderStart()).build() }.also { unsafeInstall(it) } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters