From 17492c5f48c459dd44eafb0e747c1164193ca7f7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 30 Oct 2015 17:15:15 +0100 Subject: correctly working optional injection --- src/Generation/FileGenerator.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Generation/FileGenerator.kt b/src/Generation/FileGenerator.kt index 08a885ab..c4025088 100644 --- a/src/Generation/FileGenerator.kt +++ b/src/Generation/FileGenerator.kt @@ -7,8 +7,9 @@ import java.io.IOException import java.io.OutputStreamWriter public class FileGenerator @Inject constructor(val locationService: FileLocationService, - val formatService: FormatService, - @Inject(optional = true) val outlineService: OutlineFormatService?) : Generator { + val formatService: FormatService) : Generator { + + @set:Inject(optional = true) var outlineService: OutlineFormatService? = null override fun buildPages(nodes: Iterable) { val specificLocationService = locationService.withExtension(formatService.extension) @@ -30,9 +31,7 @@ public class FileGenerator @Inject constructor(val locationService: FileLocation } override fun buildOutlines(nodes: Iterable) { - if (outlineService == null) { - return - } + val outlineService = this.outlineService ?: return for ((location, items) in nodes.groupBy { locationService.location(it) }) { val file = outlineService.getOutlineFileName(location) file.parentFile?.mkdirsOrFail() -- cgit