Add code generation for asList methods in js.libraries.
This commit is contained in:
committed by
Ilya Gorbunov
parent
abdac27b61
commit
d724ce3f7e
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user