Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Improve Kotlin starter generation, fix build problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jun 16, 2021
1 parent ab5ebd9 commit cf589b9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
3 changes: 3 additions & 0 deletions plugin/src/main/kotlin/QuestionerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class QuestionerPlugin : Plugin<Project> {
val reconfigureTesting = project.tasks.register("reconfigureTesting", ReconfigureTesting::class.java).get()
project.tasks.getByName("test").dependsOn(reconfigureTesting)
project.tasks.getByName("test").mustRunAfter(reconfigureTesting)
project.tasks.getByName("compileJava").mustRunAfter(reconfigureTesting)
project.tasks.getByName("compileKotlin").mustRunAfter(reconfigureTesting)
project.tasks.getByName("jar").mustRunAfter(reconfigureTesting)
project.tasks.getByName("test").dependsOn(generateMetatests)
project.tasks.getByName("compileTestKotlin").dependsOn(generateMetatests)
try {
Expand Down
38 changes: 28 additions & 10 deletions plugin/src/main/kotlin/save/ParseKotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,37 @@ data class ParsedKotlinFile(val path: String, val contents: String) {
it.last().text
}
}
val arrayRegex = """Array<(\w+)>""".toRegex()
val starterReturn = when {
returnType == "Unit" -> ""
returnType.endsWith("?") -> " null"
returnType == "Byte" -> " 0"
returnType == "Short" -> " 0"
returnType == "Int" -> " 0"
returnType == "Long" -> " 0"
returnType == "Float" -> " 0.0"
returnType == "Double" -> " 0.0"
returnType == "Char" -> " ' '"
returnType == "Boolean" -> " false"
returnType == "String" -> " \"\""
returnType.endsWith("?") -> "null"
returnType == "Byte" -> "0"
returnType == "Short" -> "0"
returnType == "Int" -> "0"
returnType == "Long" -> "0"
returnType == "Float" -> "0.0"
returnType == "Double" -> "0.0"
returnType == "Char" -> "' '"
returnType == "Boolean" -> "false"
returnType == "String" -> "\"\""
returnType == "ByteArray" -> "byteArrayOf()"
returnType == "ShortArray" -> "shortArrayOf()"
returnType == "IntArray" -> "intArrayOf()"
returnType == "LongArray" -> "longArrayOf()"
returnType == "FloatArray" -> "floatArrayOf()"
returnType == "DoubleArray" -> "doubleArrayOf()"
returnType == "BooleanArray" -> "booleanArrayOf()"
returnType == "CharArray" -> "charArrayOf()"
returnType.matches(arrayRegex) -> arrayRegex.find(returnType)?.let {
"arrayOf<${it.groups[1]!!.value}>()"
} ?: error("regex only matched the first time")
else -> error("Can't generate empty Kotlin return for type $returnType")
}.let {
if (it.isNotBlank()) {
" $it"
} else {
it
}
}
val prefix = (start + 1 until correctSolution.length).find { i -> !correctSolution[i].isWhitespace() }.let {
check(it != null) { "Couldn't find method contents" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.5
version=2021.6.6

0 comments on commit cf589b9

Please sign in to comment.