plus: do not generate ambiguos overloads.

This commit is contained in:
Ilya Gorbunov
2015-07-07 05:07:40 +03:00
parent d89af24d6c
commit a7bf415ad5
2 changed files with 21 additions and 34 deletions
@@ -52,7 +52,7 @@ fun generators(): List<GenericFunction> {
only(Iterables, Collections, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." }
returns("List<T>")
returns("SELF", ArraysOfObjects, ArraysOfPrimitives, Sets, Sequences)
returns("SELF", Sets, Sequences)
body {
"""
if (this is Collection) return this.plus(collection)
@@ -64,14 +64,19 @@ fun generators(): List<GenericFunction> {
}
body(Collections) {
"""
if (collection is Collection) return this.plus(collection)
val result = ArrayList<T>(this)
result.addAll(collection)
return result
if (collection is Collection) {
val result = ArrayList<T>(this.size() + collection.size())
result.addAll(this)
result.addAll(collection)
return result
} else {
val result = ArrayList<T>(this)
result.addAll(collection)
return result
}
"""
}
// TODO: try to precalculate size
// TODO: use immutable set builder when available
doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." }
body(Sets) {
@@ -91,20 +96,6 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("plus(collection: Collection<T>)") {
only(Collections)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." }
returns("List<T>")
body {
"""
val result = ArrayList<T>(this.size() + collection.size())
result.addAll(this)
result.addAll(collection)
return result
"""
}
}
templates add f("plus(array: Array<out T>)") {
only(Iterables, Collections, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [array]." }