From 6ef35accd16533c84be5d0164739b146cfb55b73 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 11 Dec 2017 16:01:51 +0300 Subject: Fix optional binding --- core/src/main/kotlin/Formats/FormatDescriptor.kt | 10 ++++++---- core/src/main/kotlin/Utilities/DokkaModules.kt | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/Formats/FormatDescriptor.kt b/core/src/main/kotlin/Formats/FormatDescriptor.kt index aa00df97..a1120c00 100644 --- a/core/src/main/kotlin/Formats/FormatDescriptor.kt +++ b/core/src/main/kotlin/Formats/FormatDescriptor.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.Formats import com.google.inject.Binder import org.jetbrains.dokka.* import org.jetbrains.dokka.Utilities.bind +import org.jetbrains.dokka.Utilities.lazyBind import org.jetbrains.dokka.Utilities.toOptional import org.jetbrains.dokka.Utilities.toType import kotlin.reflect.KClass @@ -23,11 +24,12 @@ abstract class FileGeneratorBasedFormatDescriptor : FormatDescriptor { override fun configureOutput(binder: Binder): Unit = with(binder) { bind() toType NodeLocationAwareGenerator::class - - bind() toOptional (outlineServiceClass) - bind() toOptional formatServiceClass bind() toType generatorServiceClass - bind() toOptional packageListServiceClass + + + lazyBind() toOptional (outlineServiceClass) + lazyBind() toOptional formatServiceClass + lazyBind() toOptional packageListServiceClass } abstract val formatServiceClass: KClass? diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 6b5e153e..763e29a9 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -73,7 +73,9 @@ private inline fun Binder.bindNameAnnotat inline fun Binder.bind(): AnnotatedBindingBuilder = bind(T::class.java) -inline infix fun > AnnotatedBindingBuilder.toOptional(kClass: TKClass?) = - kClass?.let { to(it.java) } +inline fun Binder.lazyBind(): Lazy> = lazy { bind(T::class.java) } + +inline infix fun > Lazy>.toOptional(kClass: TKClass?) = + kClass?.let { value toType it } inline infix fun > AnnotatedBindingBuilder.toType(kClass: TKClass) = to(kClass.java) -- cgit