Deprecate contains, indexOf, lastIndexOf functions of Float/DoubleArray #KT-28753

This commit is contained in:
Abduqodiri Qurbonzoda
2020-06-08 23:36:38 +03:00
parent 97c688057d
commit c923b2e139
3 changed files with 29 additions and 4 deletions
@@ -27,6 +27,10 @@ object Elements : TemplateGroupBase() {
}
}
private fun floatingSearchDeprecationMessage(signature: String, replacement: String): String {
return "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use '$replacement' instead to continue using this behavior, or '.asList().$signature' to get the same search behavior as in a list."
}
val f_contains = fn("contains(element: T)") {
include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
} builder {
@@ -34,12 +38,17 @@ object Elements : TemplateGroupBase() {
doc { "Returns `true` if [element] is found in the ${f.collection}." }
typeParam("@kotlin.internal.OnlyInputTypes T")
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val replacement = "any { it == element }"
deprecate(Deprecation(floatingSearchDeprecationMessage(signature, replacement), replacement, DeprecationLevel.WARNING))
annotation("""@Suppress("DEPRECATION")""")
}
returns("Boolean")
body(Iterables) {
"""
if (this is Collection)
return contains(element)
return indexOf(element) >= 0
if (this is Collection)
return contains(element)
return indexOf(element) >= 0
"""
}
body(ArraysOfPrimitives, ArraysOfObjects, Sequences) {
@@ -57,6 +66,10 @@ object Elements : TemplateGroupBase() {
specialFor(Lists) {
annotation("""@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // false warning, extension takes precedence in some cases""")
}
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val replacement = "indexOfFirst { it == element }"
deprecate(Deprecation(floatingSearchDeprecationMessage(signature, replacement), replacement, DeprecationLevel.WARNING))
}
returns("Int")
body {
"""
@@ -117,6 +130,10 @@ object Elements : TemplateGroupBase() {
specialFor(Lists) {
annotation("""@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // false warning, extension takes precedence in some cases""")
}
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val replacement = "indexOfLast { it == element }"
deprecate(Deprecation(floatingSearchDeprecationMessage(signature, replacement), replacement, DeprecationLevel.WARNING))
}
returns("Int")
body {
"""