StdLib generators: Add some infix extensions for DSL, remove unneeded import, simplify declarations.

This commit is contained in:
Ilya Gorbunov
2015-10-09 19:13:54 +03:00
parent 075a8eaf39
commit 2cdd413590
3 changed files with 6 additions and 17 deletions
@@ -5,7 +5,6 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -37,7 +37,6 @@ fun List<GenericFunction>.writeTo(file: File, builder: GenericFunction.() -> Str
its.use {
its.append("package kotlin\n\n")
its.append("$COMMON_AUTOGENERATED_WARNING\n\n")
its.append("import kotlin.platform.*\n") // TODO: Remove unneeded import
its.append("import java.util.*\n\n")
its.append("import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js\n\n")
for (t in this.sortedBy { it.signature }) {
@@ -413,20 +413,11 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
}
fun f(signature: String, init: GenericFunction.() -> Unit): GenericFunction {
val gf = GenericFunction(signature)
gf.init()
return gf
}
infix fun MutableList<GenericFunction>.add(item: GenericFunction) = add(item)
infix fun MutableList<GenericFunction>.addAll(items: Iterable<GenericFunction>) = this.addAll(iterable = items)
fun pval(signature: String, init: GenericFunction.() -> Unit): GenericFunction {
val gf = GenericFunction(signature, "val")
gf.init()
return gf
}
fun f(signature: String, init: GenericFunction.() -> Unit) = GenericFunction(signature).apply(init)
fun pvar(signature: String, init: GenericFunction.() -> Unit): GenericFunction {
val gf = GenericFunction(signature, "var")
gf.init()
return gf
}
fun pval(signature: String, init: GenericFunction.() -> Unit) = GenericFunction(signature, "val").apply(init)
fun pvar(signature: String, init: GenericFunction.() -> Unit) = GenericFunction(signature, "var").apply(init)