Generate contains, indexOf, lastIndexOf with @NoInfer

This commit is contained in:
Ilya Gorbunov
2015-10-13 22:59:03 +03:00
parent 69a924a3ab
commit 95aac7ade6
4 changed files with 19 additions and 16 deletions
@@ -8,16 +8,17 @@ fun elements(): List<GenericFunction> {
templates add f("contains(element: T)") {
operator(true)
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns `true` if [element] is found in the collection." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "contains(element: @kotlin.internal.NoInfer T)" }
returns("Boolean")
body {
body(Iterables) {
"""
if (this is Collection)
return contains(element)
return indexOf(element) >= 0
if (this is Collection)
return contains(element)
return indexOf(element) >= 0
"""
}
exclude(Strings, Lists, Collections)
body(ArraysOfPrimitives, ArraysOfObjects, Sequences) {
"""
return indexOf(element) >= 0
@@ -41,8 +42,9 @@ fun elements(): List<GenericFunction> {
}
templates add f("indexOf(element: T)") {
exclude(Strings, Lists) // has native implementation
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns first index of [element], or -1 if the collection does not contain element." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "indexOf(element: @kotlin.internal.NoInfer T)" }
returns("Int")
body { f ->
"""
@@ -104,8 +106,9 @@ fun elements(): List<GenericFunction> {
}
templates add f("lastIndexOf(element: T)") {
exclude(Strings, Lists) // has native implementation
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns last index of [element], or -1 if the collection does not contain element." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "lastIndexOf(element: @kotlin.internal.NoInfer T)" }
returns("Int")
body { f ->
"""