New stdlib generators

This commit is contained in:
Ilya Ryzhenkov
2014-03-18 13:45:31 +04:00
committed by Andrey Breslav
parent 0980f5e40a
commit e37d8174c3
109 changed files with 13317 additions and 7735 deletions
@@ -3,12 +3,11 @@ package templates
import templates.Family.*
fun arrays(): List<GenericFunction> {
val templates = iterables()
val templates = arrayListOf<GenericFunction>()
templates add f("isEmpty()") {
absentFor(Arrays)
isInline = false
doc = "Returns true if the array is empty"
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns true if the array is empty" }
returns("Boolean")
body {
"return size == 0"
@@ -16,57 +15,13 @@ fun arrays(): List<GenericFunction> {
}
templates add f("isNotEmpty()") {
absentFor(Arrays)
isInline = false
doc = "Returns true if the array is empty"
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns true if the array is not empty" }
returns("Boolean")
body {
"return !isEmpty()"
}
}
templates add f("indexOf(item: T)") {
absentFor(PrimitiveArrays)
isInline = false
doc = "Returns first index of item, or -1 if the array does not contain item"
returns("Int")
body {
"""
if (item == null) {
for (i in indices) {
if (this[i] == null) {
return i
}
}
} else {
for (i in indices) {
if (item == this[i]) {
return i
}
}
}
return -1
"""
}
}
// implementation for PrimitiveArrays is separate from Arrays, because they cannot hold null elements
templates add f("indexOf(item: T)") {
absentFor(Arrays)
isInline = false
doc = "Returns first index of item, or -1 if the array does not contain item"
returns("Int")
body {
"""
for (i in indices) {
if (item == this[i]) {
return i
}
}
return -1
"""
}
}
return templates.sort()
return templates
}