From 45001a51049373f81b05db0bb282f585a6f19b62 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 6 Oct 2015 22:15:10 -0700 Subject: [PATCH] Refactoring. --- .../com/beust/kobalt/ProjectGenerator.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt b/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt index 0ed7d919..6b25c8d1 100644 --- a/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/ProjectGenerator.kt @@ -93,27 +93,26 @@ public class ProjectGenerator : KobaltLogger { testDeps.addAll(partition.second) } - private fun updateVersion(dep: Dependency, mapped: Map): Dependency { + private fun updateVersion(dep: Dependency, mapped: Map) = if ( dep.version.startsWith("\${")) { val property = dep.version.substring(2, dep.version.length() - 1) - return Dependency(dep.groupId, dep.artifactId, "\${${mapped.get(property)}}", dep.optional, dep.scope) + Dependency(dep.groupId, dep.artifactId, "\${${mapped.get(property)}}", dep.optional, dep.scope) } else { - return dep + dep } - } - private fun translate(key: String) : String { - val split = key.split('.') - return split.mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("") - } + /** + * Turns a dot property into a proper Kotlin identifier, e.g. common.version -> commonVersion + */ + private fun translate(key: String) = + key.split('.').mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("") - private fun String.upperFirst(): String { + private fun String.upperFirst() = if (this.isBlank()) { - return this + this } else { - return this.substring(0, 1).toUpperCase() + this.substring(1) + this.substring(0, 1).toUpperCase() + this.substring(1) } - } /** * Detect all the languages contained in this project.