Provide deprecated unconstrained contains, indexOf, lastIndexOf methods for migration.

This commit is contained in:
Ilya Gorbunov
2015-10-16 19:48:05 +03:00
parent 95aac7ade6
commit fc7c008672
4 changed files with 133 additions and 0 deletions
+32
View File
@@ -435,6 +435,16 @@ public operator fun ShortArray.contains(element: Short): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the collection.
*/
@Deprecated("Use 'containsRaw' instead.", ReplaceWith("containsRaw(element)"))
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public operator fun <T> Array<out T>.contains(element: T): Boolean {
return containsRaw(element)
}
/**
* Returns `true` if [element] is found in the collection.
* Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
@@ -1307,6 +1317,17 @@ public fun ShortArray.indexOf(element: Short): Int {
return -1
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Array<out T>.indexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
*/
@@ -1846,6 +1867,17 @@ public fun ShortArray.lastIndexOf(element: Short): Int {
return -1
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Array<out T>.lastIndexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
@@ -61,6 +61,16 @@ public operator fun <T> Iterable<T>.contains(element: @kotlin.internal.NoInfer T
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the collection.
*/
@Deprecated("Use 'containsRaw' instead.", ReplaceWith("containsRaw(element)"))
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public operator fun <T> Iterable<T>.contains(element: T): Boolean {
return containsRaw(element)
}
/**
* Returns `true` if [element] is found in the collection.
* Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
@@ -260,6 +270,17 @@ public fun <T> Iterable<T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
return -1
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Iterable<T>.indexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
*/
@@ -409,6 +430,17 @@ public fun <T> Iterable<T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int
return lastIndex
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Iterable<T>.lastIndexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
@@ -19,6 +19,16 @@ public operator fun <T> Sequence<T>.contains(element: @kotlin.internal.NoInfer T
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the collection.
*/
@Deprecated("Use 'containsRaw' instead.", ReplaceWith("containsRaw(element)"))
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public operator fun <T> Sequence<T>.contains(element: T): Boolean {
return containsRaw(element)
}
/**
* Returns `true` if [element] is found in the collection.
* Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
@@ -132,6 +142,17 @@ public fun <T> Sequence<T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
return -1
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Sequence<T>.indexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
*/
@@ -213,6 +234,17 @@ public fun <T> Sequence<T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int
return lastIndex
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("Use 'indexOfRaw' instead.", ReplaceWith("indexOfRaw(element)"))
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> Sequence<T>.lastIndexOf(element: T): Int {
return indexOfRaw(element)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
@@ -26,6 +26,19 @@ fun elements(): List<GenericFunction> {
}
}
templates add f("contains(element: T)") {
operator(true)
only(Iterables, Sequences, ArraysOfObjects)
doc { "Returns `true` if [element] is found in the collection." }
returns("Boolean")
deprecate(Deprecation("Use 'containsRaw' instead.", "containsRaw(element)"))
annotations("""
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
""".trimIndent())
}
templates add f("containsRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects)
doc {
@@ -89,6 +102,18 @@ fun elements(): List<GenericFunction> {
}
}
templates add f("indexOf(element: T)") {
only(Iterables, Sequences, ArraysOfObjects)
doc { "Returns first index of [element], or -1 if the collection does not contain element." }
returns("Int")
deprecate(Deprecation("Use 'indexOfRaw' instead.", "indexOfRaw(element)"))
annotations("""
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
""".trimIndent())
}
templates add f("indexOfRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects, Lists)
doc {
@@ -154,6 +179,18 @@ fun elements(): List<GenericFunction> {
}
}
templates add f("lastIndexOf(element: T)") {
only(Iterables, Sequences, ArraysOfObjects)
doc { "Returns last index of [element], or -1 if the collection does not contain element." }
returns("Int")
deprecate(Deprecation("Use 'indexOfRaw' instead.", "indexOfRaw(element)"))
annotations("""
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
""".trimIndent())
}
templates add f("lastIndexOfRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects, Lists)
doc {