From 5b90b573476f63366a5253280f5be5d68ac08a6d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 24 Feb 2017 14:17:12 +0100 Subject: Don't crash on source roots without a platform --- core/src/main/kotlin/Generation/DokkaGenerator.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index f014ec58..6b5df7c9 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -38,7 +38,7 @@ class DokkaGenerator(val logger: DokkaLogger, private val documentationModule = DocumentationModule(moduleName) fun generate() { - val sourcesGroupedByPlatform = sources.groupBy { it.defaultPlatforms[0] } + val sourcesGroupedByPlatform = sources.groupBy { it.defaultPlatforms.firstOrNull() } for ((platform, roots) in sourcesGroupedByPlatform) { appendSourceModule(platform, roots) } @@ -52,7 +52,7 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("done in ${timeBuild / 1000} secs") } - private fun appendSourceModule(defaultPlatform: String, sourceRoots: List) { + private fun appendSourceModule(defaultPlatform: String?, sourceRoots: List) { val sourcePaths = sourceRoots.map { it.path } val environment = createAnalysisEnvironment(sourcePaths) @@ -64,12 +64,13 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() + val defaultPlatformAsList = defaultPlatform?.let { listOf(it) }.orEmpty() val defaultPlatformsProvider = object : DefaultPlatformsProvider { override fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List { val containingFilePath = descriptor.sourcePsi()?.containingFile?.virtualFile?.canonicalPath ?.let { File(it).absolutePath } val sourceRoot = containingFilePath?.let { path -> sourceRoots.find { path.startsWith(it.path) } } - return sourceRoot?.defaultPlatforms ?: listOf(defaultPlatform) + return sourceRoot?.defaultPlatforms ?: defaultPlatformAsList } } -- cgit