From 9f3f09ea6a312e8c1896d21505574e5cc13c38ff Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 20 Feb 2016 13:07:25 -0800 Subject: [PATCH] Refactor. --- .../com/beust/kobalt/internal/SourceSet.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SourceSet.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SourceSet.kt index 1ca707ca..31f13e08 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SourceSet.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SourceSet.kt @@ -8,21 +8,21 @@ enum class SourceSet { MAIN, TEST; - private fun unknown(sourceSet: SourceSet) = throw KobaltException("Unknown source set: $this") + fun correctSourceSet(project: Project) = when(this) { + SourceSet.MAIN -> project.sourceDirectories + SourceSet.TEST -> project.sourceDirectoriesTest + else -> unknown(this) + } - fun correctSourceSet(project: Project) = - if (this == SourceSet.MAIN) project.sourceDirectories - else if (this == SourceSet.TEST) project.sourceDirectoriesTest - else unknown(this) - - fun correctOutputDir(project: Project) = - if (this == SourceSet.MAIN) KFiles.CLASSES_DIR - else if (this == SourceSet.TEST) KFiles.TEST_CLASSES_DIR - else unknown(this) + fun correctOutputDir(project: Project) = when(this) { + SourceSet.MAIN -> KFiles.CLASSES_DIR + SourceSet.TEST -> KFiles.TEST_CLASSES_DIR + else -> unknown(this) + } companion object { fun of(isTest: Boolean) = if (isTest) TEST else MAIN - + private fun unknown(sourceSet: SourceSet) = throw KobaltException("Unknown source set: $sourceSet") } }