From fc7c008672024ce0b2c5ad2adcaea527959783c9 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 16 Oct 2015 19:48:05 +0300 Subject: [PATCH] Provide deprecated unconstrained contains, indexOf, lastIndexOf methods for migration. --- libraries/stdlib/src/generated/_Arrays.kt | 32 ++++++++++++++++ .../stdlib/src/generated/_Collections.kt | 32 ++++++++++++++++ libraries/stdlib/src/generated/_Sequences.kt | 32 ++++++++++++++++ .../src/templates/Elements.kt | 37 +++++++++++++++++++ 4 files changed, 133 insertions(+) diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 6eee501e14e..5b821f8bb84 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -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 Array.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 Array.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 Array.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`. diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 6a4ce7ab0d2..129873d9033 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -61,6 +61,16 @@ public operator fun Iterable.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 Iterable.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 Iterable.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 Iterable.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 Iterable.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 Iterable.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`. diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 6bf5e875ff9..7a5ffc3d6fe 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -19,6 +19,16 @@ public operator fun Sequence.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 Sequence.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 Sequence.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 Sequence.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 Sequence.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 Sequence.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`. diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index f3ef40d7b5e..0f6140f1d0d 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -26,6 +26,19 @@ fun elements(): List { } } + + 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 { } } + 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 { } } + 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 {