aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability/extensions.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-06-30 21:05:16 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-07 10:07:21 +0200
commit9b7e163ae69272c7e56088d6f256d6b19f9a01d4 (patch)
tree333c56d610ae7e612d9f49d579e4931f7e8f9863 /core/src/main/kotlin/plugability/extensions.kt
parent33cf9d62f409dd5d98678fdcd29227763af11586 (diff)
downloaddokka-9b7e163ae69272c7e56088d6f256d6b19f9a01d4.tar.gz
dokka-9b7e163ae69272c7e56088d6f256d6b19f9a01d4.tar.bz2
dokka-9b7e163ae69272c7e56088d6f256d6b19f9a01d4.zip
Refactor Extension DSL and remove fallback mechanism
Diffstat (limited to 'core/src/main/kotlin/plugability/extensions.kt')
-rw-r--r--core/src/main/kotlin/plugability/extensions.kt101
1 files changed, 35 insertions, 66 deletions
diff --git a/core/src/main/kotlin/plugability/extensions.kt b/core/src/main/kotlin/plugability/extensions.kt
index 20b60469..c6dd0b85 100644
--- a/core/src/main/kotlin/plugability/extensions.kt
+++ b/core/src/main/kotlin/plugability/extensions.kt
@@ -9,79 +9,43 @@ data class ExtensionPoint<T : Any> internal constructor(
override fun toString() = "ExtensionPoint: $pluginClass/$pointName"
}
-abstract class Extension<T : Any> internal constructor(
+sealed class OrderingKind {
+ object None : OrderingKind()
+ class ByDsl(val block: (OrderDsl.() -> Unit)) : OrderingKind()
+}
+
+sealed class OverrideKind {
+ object None : OverrideKind()
+ class Present(val overriden: Extension<*, *, *>) : OverrideKind()
+}
+
+class Extension<T : Any, Ordering : OrderingKind, Override : OverrideKind> internal constructor(
internal val extensionPoint: ExtensionPoint<T>,
internal val pluginClass: String,
internal val extensionName: String,
internal val action: LazyEvaluated<T>,
- internal val ordering: (OrderDsl.() -> Unit)? = null,
- internal val conditions: Array<DokkaConfiguration.() -> Boolean> = emptyArray(),
- internal val isFallback: Boolean
+ internal val ordering: Ordering,
+ internal val override: Override,
+ internal val conditions: List<DokkaConfiguration.() -> Boolean>
) {
override fun toString() = "Extension: $pluginClass/$extensionName"
override fun equals(other: Any?) =
- if (other is Extension<*>) this.pluginClass == other.pluginClass && this.extensionName == other.extensionName
+ if (other is Extension<*, *, *>) this.pluginClass == other.pluginClass && this.extensionName == other.extensionName
else false
override fun hashCode() = listOf(pluginClass, extensionName).hashCode()
- abstract fun addCondition(condition: (DokkaConfiguration.() -> Boolean)): Extension<T>
-
- abstract fun markedAsFallback(): Extension<T>
-
- open val condition: DokkaConfiguration.() -> Boolean
- get() = { conditions.all { it(this) }}
+ val condition: DokkaConfiguration.() -> Boolean
+ get() = { conditions.all { it(this) } }
}
-class ExtensionOrdered<T : Any> internal constructor(
+private fun <T : Any> Extension(
extensionPoint: ExtensionPoint<T>,
pluginClass: String,
extensionName: String,
- action: LazyEvaluated<T>,
- ordering: (OrderDsl.() -> Unit),
- conditions: Array<DokkaConfiguration.() -> Boolean> = emptyArray(),
- isFallback: Boolean = false
-) : Extension<T>(
- extensionPoint,
- pluginClass,
- extensionName,
- action,
- ordering,
- conditions,
- isFallback
-) {
- override fun addCondition(condition: DokkaConfiguration.() -> Boolean) =
- ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, ordering!!, conditions + condition)
-
- override fun markedAsFallback() =
- ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, ordering!!, conditions, true)
-}
-
-class ExtensionUnordered<T : Any> internal constructor(
- extensionPoint: ExtensionPoint<T>,
- pluginClass: String,
- extensionName: String,
- action: LazyEvaluated<T>,
- conditions: Array<DokkaConfiguration.() -> Boolean> = emptyArray(),
- isFallback: Boolean = false
-) : Extension<T>(
- extensionPoint,
- pluginClass,
- extensionName,
- action,
- null,
- conditions,
- isFallback
-) {
- override fun addCondition(condition: DokkaConfiguration.() -> Boolean) =
- ExtensionUnordered(extensionPoint, pluginClass, extensionName, action, conditions + condition)
-
- override fun markedAsFallback() =
- ExtensionUnordered(extensionPoint, pluginClass, extensionName, action, conditions, true)
-}
-
-internal data class Ordering(val previous: Set<Extension<*>>, val following: Set<Extension<*>>)
+ action: LazyEvaluated<T>
+) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.None, OverrideKind.None, emptyList())
@DslMarker
annotation class ExtensionsDsl
@@ -90,29 +54,34 @@ annotation class ExtensionsDsl
class ExtendingDSL(private val pluginClass: String, private val extensionName: String) {
infix fun <T : Any> ExtensionPoint<T>.with(action: T) =
- ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action))
+ Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action))
infix fun <T : Any> ExtensionPoint<T>.providing(action: (DokkaContext) -> T) =
- ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action))
+ Extension(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action))
- infix fun <T : Any> ExtensionUnordered<T>.order(block: OrderDsl.() -> Unit) =
- ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, block)
+ infix fun <T : Any, Override : OverrideKind> Extension<T, OrderingKind.None, Override>.order(
+ block: OrderDsl.() -> Unit
+ ) = Extension(extensionPoint, pluginClass, extensionName, action, OrderingKind.ByDsl(block), override, conditions)
- infix fun <T : Any> Extension<T>.applyIf(condition: DokkaConfiguration.() -> Boolean): Extension<T> =
- this.addCondition(condition)
+ infix fun <T : Any, Override : OverrideKind, Ordering: OrderingKind> Extension<T, Ordering, Override>.applyIf(
+ condition: DokkaConfiguration.() -> Boolean
+ ) = Extension(extensionPoint, pluginClass, extensionName, action, ordering, override, conditions + condition)
+ infix fun <T : Any, Override : OverrideKind, Ordering: OrderingKind> Extension<T, Ordering, Override>.override(
+ overriden: Extension<T, *, *>
+ ) = Extension(extensionPoint, pluginClass, extensionName, action, ordering, OverrideKind.Present(overriden), conditions)
}
@ExtensionsDsl
class OrderDsl {
- internal val previous = mutableSetOf<Extension<*>>()
- internal val following = mutableSetOf<Extension<*>>()
+ internal val previous = mutableSetOf<Extension<*, *, *>>()
+ internal val following = mutableSetOf<Extension<*, *, *>>()
- fun after(vararg extensions: Extension<*>) {
+ fun after(vararg extensions: Extension<*, *, *>) {
previous += extensions
}
- fun before(vararg extensions: Extension<*>) {
+ fun before(vararg extensions: Extension<*, *, *>) {
following += extensions
}
} \ No newline at end of file