Add code generation for asList methods in js.libraries.

This commit is contained in:
Ilya Gorbunov
2015-03-26 21:57:43 +03:00
committed by Ilya Gorbunov
parent abdac27b61
commit d724ce3f7e
5 changed files with 121 additions and 0 deletions
@@ -37,3 +37,7 @@ fun generateCollectionsAPI(outDir: File) {
}
}
fun generateCollectionsJsAPI(outDir: File) {
specialJS().writeTo(File(outDir, "kotlin_special.kt")) { build() }
}
@@ -29,6 +29,7 @@ fun main(args: Array<String>) {
generateDomEventsAPI(File(jsCoreDir, "domEvents.kt"))
generateCollectionsAPI(outDir)
generateCollectionsJsAPI(jsCoreDir)
generateDownTos(File(outDir, "_DownTo.kt"), "package kotlin")
}
@@ -0,0 +1,25 @@
package templates
import templates.Family.*
fun specialJS(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("asList()") {
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns a list that wraps the original array" }
returns("List<T>")
body(ArraysOfObjects) {
"""
val al = ArrayList<T>()
(al: dynamic).array = this // black dynamic magic
return al
"""
}
inline(true, ArraysOfPrimitives)
body(ArraysOfPrimitives) {"""return (this as Array<T>).asList()"""}
}
return templates
}