aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/plugability')
-rw-r--r--core/src/main/kotlin/plugability/DefaultExtensions.kt5
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt12
2 files changed, 9 insertions, 8 deletions
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt
index 1a367d30..242eb6b8 100644
--- a/core/src/main/kotlin/plugability/DefaultExtensions.kt
+++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt
@@ -1,23 +1,20 @@
package org.jetbrains.dokka.plugability
import org.jetbrains.dokka.CoreExtensions
-import org.jetbrains.dokka.pages.DocTagToContentConverter
import org.jetbrains.dokka.renderers.FileWriter
import org.jetbrains.dokka.renderers.OutputWriter
import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory
internal object DefaultExtensions {
- private val converter: LazyEvaluated<DocTagToContentConverter> = LazyEvaluated.fromRecipe { DocTagToContentConverter(it) }
private val providerFactory: LazyEvaluated<DefaultLocationProviderFactory> = LazyEvaluated.fromRecipe { DefaultLocationProviderFactory(it) }
private val outputWriter: LazyEvaluated<OutputWriter> = LazyEvaluated.fromRecipe { FileWriter(it) }
@Suppress("IMPLICIT_CAST_TO_ANY", "UNCHECKED_CAST")
internal fun <T : Any, E : ExtensionPoint<T>> get(point: E, fullContext: DokkaContext): List<T> =
when (point) {
- CoreExtensions.commentsToContentConverter -> converter.get(fullContext)
CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext)
- CoreExtensions.outputWriter -> outputWriter.get(fullContext)
+ CoreExtensions.outputWriter -> outputWriter.get(fullContext)
else -> null
}.let { listOfNotNull( it ) as List<T> }
} \ No newline at end of file
diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt
index c00b0af3..d8fb7892 100644
--- a/core/src/main/kotlin/plugability/DokkaPlugin.kt
+++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt
@@ -13,8 +13,7 @@ abstract class DokkaPlugin {
@PublishedApi
internal var context: DokkaContext? = null
- protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class)
- ?: throw IllegalStateException("Querying about plugins is only possible with dokka context initialised")
+ protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery()
protected fun <T : Any> extensionPoint() =
object : ReadOnlyProperty<DokkaPlugin, ExtensionPoint<T>> {
@@ -51,5 +50,10 @@ abstract class DokkaPlugin {
}
inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> =
- context?.let { it[extension()] }
- ?: throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") \ No newline at end of file
+ context?.let { it[extension()] } ?: throwIllegalQuery()
+
+inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P.() -> ExtensionPoint<E>): E =
+ context?.single(extension()) ?: throwIllegalQuery()
+
+fun throwIllegalQuery(): Nothing =
+ throw IllegalStateException("Querying about plugins is only possible with dokka context initialised")