From dc85d80e264370d0747f17613b259735f14a2fe1 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 29 Nov 2017 18:38:34 +0300 Subject: Support wide-range Since Kotlin versions --- .../main/kotlin/Formats/StructuredFormatService.kt | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index a8b000b7..5167a102 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -398,10 +398,29 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, else -> it.platformsToShow.toSet() } } + + fun String.isKotlinVersion() = this.startsWith("Kotlin") + // Calculating common platforms for items - return platforms.fold(platforms.first()) { - result, platforms -> - result.intersect(platforms) + return platforms.reduce { result, platformsOfItem -> + val otherKotlinVersion = result.find { it.isKotlinVersion() } + val (kotlinVersions, otherPlatforms) = platformsOfItem.partition { it.isKotlinVersion() } + + // When no Kotlin version specified, it means that version is 1.0 + if (otherKotlinVersion != null && kotlinVersions.isNotEmpty()) { + val allKotlinVersions = (kotlinVersions + otherKotlinVersion).distinct() + + val minVersion = allKotlinVersions.min()!! + val resultVersion = when { + allKotlinVersions.size == 1 -> allKotlinVersions.single() + minVersion.endsWith("+") -> minVersion + else -> minVersion + "+" + } + + result.intersect(otherPlatforms) + resultVersion + } else { + result.intersect(platformsOfItem) + } } } -- cgit