Skip to content

Commit

Permalink
Add more support on Kotlin script
Browse files Browse the repository at this point in the history
  • Loading branch information
Omico committed Jun 8, 2023
1 parent 952b790 commit f6d2682
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal val BasicExtensionFunctions_KtFileScope: List<BasicExtensionFunction> b
add(BasicExtensionFunction_addFileComment)
add(BasicExtensionFunction_addFunction)
add(BasicExtensionFunction_addProperty)
add(BasicExtensionFunction_addStatement)
add(BasicExtensionFunction_addType)
}
}
4 changes: 4 additions & 0 deletions elucidator/src/main/kotlin/me/omico/elucidator/KtFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public fun KtFileScope.addProperty(
): Unit =
property(name = name, type = type, modifiers = modifiers, block = block).let(::addProperty)

public fun KtFileScope.addNewline() {
builder.addStatement("")
}

public fun KtFileScope.writeTo(path: Path): Unit = build().writeTo(path)
7 changes: 7 additions & 0 deletions elucidator/src/main/kotlin/me/omico/elucidator/KtsFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ public fun ktsFile(
block: KtFileScope.() -> Unit,
): FileSpec =
FileSpec.scriptBuilder(fileName = fileName, packageName = packageName).applyDslBuilder(block).build()

public fun KtFileScope.addCallExpression(format: String, vararg args: Any, block: KtFileScope.() -> Unit) {
require(builder.isScript) { "CallExpression can only be added to a script file." }
builder.beginControlFlow(controlFlow = format, args = args)
block()
builder.endControlFlow()
}

0 comments on commit f6d2682

Please sign in to comment.