Provide toTypedArray method for primitive arrays.

This commit is contained in:
Ilya Gorbunov
2015-07-16 17:33:53 +03:00
parent f57c207ed2
commit 12e3542bce
5 changed files with 177 additions and 0 deletions
@@ -21,6 +21,22 @@ fun specialJS(): List<GenericFunction> {
body(ArraysOfPrimitives) {"""return (this as Array<T>).asList()"""}
}
templates add f("toTypedArray()") {
only(ArraysOfPrimitives)
returns("Array<T>")
doc {
"""
Returns a *typed* object array containing all of the elements of this primitive array.
"""
}
body {
"""
return copyOf() as Array<T>
"""
}
}
templates add f("copyOfRange(from: Int, to: Int)") {
// TODO: Arguments checking as in java?
only(ArraysOfObjects, ArraysOfPrimitives)
@@ -216,5 +216,23 @@ fun specialJVM(): List<GenericFunction> {
}
}
templates add f("toTypedArray()") {
only(ArraysOfPrimitives)
returns("Array<T>")
doc {
"""
Returns a *typed* object array containing all of the elements of this primitive array.
"""
}
body {
"""
val result = arrayOfNulls<T>(size())
for (index in indices)
result[index] = this[index]
return result as Array<T>
"""
}
}
return templates
}