Nullable Array.contentEquals/contentHashCode/contentToString #KT-34161
This commit is contained in:
@@ -85,6 +85,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
infix(true)
|
||||
doc {
|
||||
"""
|
||||
@@ -93,8 +94,8 @@ object ArrayOps : TemplateGroupBase() {
|
||||
"""
|
||||
}
|
||||
returns("Boolean")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { "return storage.contentEquals(other.storage)" }
|
||||
body { "return this.contentEquals(other)" }
|
||||
if (f == ArraysOfUnsigned) {
|
||||
return@builder
|
||||
}
|
||||
doc {
|
||||
@@ -105,6 +106,36 @@ object ArrayOps : TemplateGroupBase() {
|
||||
}
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentEquals_nullable = fn("contentEquals(other: SELF?)") {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.4")
|
||||
infix(true)
|
||||
doc {
|
||||
"""
|
||||
Returns `true` if the two specified arrays are *structurally* equal to one another,
|
||||
i.e. contain the same number of the same elements in the same order.
|
||||
"""
|
||||
}
|
||||
receiver("SELF?")
|
||||
returns("Boolean")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { "return this?.storage.contentEquals(other?.storage)" }
|
||||
return@builder
|
||||
}
|
||||
|
||||
doc {
|
||||
doc + """
|
||||
The elements are compared for equality with the [equals][Any.equals] function.
|
||||
For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
|
||||
"""
|
||||
}
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentEqualsNullable")""")
|
||||
body { "return java.util.Arrays.equals(this, other)" }
|
||||
}
|
||||
|
||||
@@ -126,6 +157,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
body {
|
||||
"""
|
||||
if (this === other) return true
|
||||
if (this === null || other === null) return false
|
||||
if (size != other.size) return false
|
||||
for (i in indices) {
|
||||
if (${notEq("this[i]", "other[i]")}) return false
|
||||
@@ -140,6 +172,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
infix(true)
|
||||
doc {
|
||||
"""
|
||||
@@ -154,9 +187,37 @@ object ArrayOps : TemplateGroupBase() {
|
||||
"""
|
||||
}
|
||||
returns("Boolean")
|
||||
body { "return this.contentDeepEquals(other)" }
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepEqualsInline")""")
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentDeepEquals_nullable = fn("contentDeepEquals(other: SELF?)") {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.4")
|
||||
infix(true)
|
||||
doc {
|
||||
"""
|
||||
Returns `true` if the two specified arrays are *deeply* equal to one another,
|
||||
i.e. contain the same number of the same elements in the same order.
|
||||
|
||||
The specified arrays are also considered deeply equal if both are `null`.
|
||||
|
||||
If two corresponding elements are nested arrays, they are also compared deeply.
|
||||
If any of arrays contains itself on any nesting level the behavior is undefined.
|
||||
|
||||
The elements of other types are compared for equality with the [equals][Any.equals] function.
|
||||
For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
|
||||
"""
|
||||
}
|
||||
receiver("SELF?")
|
||||
returns("Boolean")
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepEqualsNullable")""")
|
||||
body {
|
||||
"""
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
@@ -185,6 +246,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
doc {
|
||||
"""
|
||||
Returns a string representation of the contents of the specified array as if it is [List].
|
||||
@@ -192,12 +254,35 @@ object ArrayOps : TemplateGroupBase() {
|
||||
}
|
||||
sample("samples.collections.Arrays.ContentOperations.contentToString")
|
||||
returns("String")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { """return joinToString(", ", "[", "]")""" }
|
||||
body { "return this.contentToString()" }
|
||||
if (f == ArraysOfUnsigned) {
|
||||
return@builder
|
||||
}
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentToString_nullable = fn("contentToString()") {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.4")
|
||||
doc {
|
||||
"""
|
||||
Returns a string representation of the contents of the specified array as if it is [List].
|
||||
"""
|
||||
}
|
||||
sample("samples.collections.Arrays.ContentOperations.contentToString")
|
||||
receiver("SELF?")
|
||||
returns("String")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { """return this?.joinToString(", ", "[", "]") ?: "null"""" }
|
||||
return@builder
|
||||
}
|
||||
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentToStringNullable")""")
|
||||
body { "return java.util.Arrays.toString(this)" }
|
||||
}
|
||||
on(Platform.JS) {
|
||||
@@ -206,11 +291,11 @@ object ArrayOps : TemplateGroupBase() {
|
||||
body { "definedExternally" }
|
||||
}
|
||||
on(Backend.IR) {
|
||||
body { """return joinToString(", ", "[", "]")""" }
|
||||
body { """return this?.joinToString(", ", "[", "]") ?: "null"""" }
|
||||
}
|
||||
}
|
||||
on(Platform.Native) {
|
||||
body { """return joinToString(", ", "[", "]")""" }
|
||||
body { """return this?.joinToString(", ", "[", "]") ?: "null"""" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +303,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
doc {
|
||||
"""
|
||||
Returns a string representation of the contents of this array as if it is a [List].
|
||||
@@ -229,9 +315,32 @@ object ArrayOps : TemplateGroupBase() {
|
||||
}
|
||||
sample("samples.collections.Arrays.ContentOperations.contentDeepToString")
|
||||
returns("String")
|
||||
body { "return this.contentDeepToString()" }
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepToStringInline")""")
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentDeepToString_nullable = fn("contentDeepToString()") {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.4")
|
||||
doc {
|
||||
"""
|
||||
Returns a string representation of the contents of this array as if it is a [List].
|
||||
Nested arrays are treated as lists too.
|
||||
|
||||
If any of arrays contains itself on any nesting level that reference
|
||||
is rendered as `"[...]"` to prevent recursion.
|
||||
"""
|
||||
}
|
||||
sample("samples.collections.Arrays.ContentOperations.contentDeepToString")
|
||||
receiver("SELF?")
|
||||
returns("String")
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepToStringNullable")""")
|
||||
body {
|
||||
"""
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
@@ -259,16 +368,37 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
doc {
|
||||
"Returns a hash code based on the contents of this array as if it is [List]."
|
||||
}
|
||||
returns("Int")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { "return storage.contentHashCode()" }
|
||||
body { "return this.contentHashCode()" }
|
||||
if (f == ArraysOfUnsigned) {
|
||||
return@builder
|
||||
}
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentHashCode_nullable = fn("contentHashCode()") {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.4")
|
||||
doc {
|
||||
"Returns a hash code based on the contents of this array as if it is [List]."
|
||||
}
|
||||
receiver("SELF?")
|
||||
returns("Int")
|
||||
if (family == ArraysOfUnsigned) {
|
||||
body { "return this?.storage.contentHashCode()" }
|
||||
return@builder
|
||||
}
|
||||
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentHashCodeNullable")""")
|
||||
body { "return java.util.Arrays.hashCode(this)" }
|
||||
}
|
||||
on(Platform.JS) {
|
||||
@@ -283,6 +413,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
on(Platform.Native) {
|
||||
body {
|
||||
"""
|
||||
if (this === null) return 0
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + element.hashCode()
|
||||
@@ -296,6 +427,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.1")
|
||||
annotation("@kotlin.internal.LowPriorityInOverloadResolution")
|
||||
doc {
|
||||
"""
|
||||
Returns a hash code based on the contents of this array as if it is [List].
|
||||
@@ -305,9 +437,30 @@ object ArrayOps : TemplateGroupBase() {
|
||||
"""
|
||||
}
|
||||
returns("Int")
|
||||
body { "return this.contentDeepHashCode()" }
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepHashCodeInline")""")
|
||||
}
|
||||
}
|
||||
|
||||
val f_contentDeepHashCode_nullable = fn("contentDeepHashCode()") {
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
since("1.4")
|
||||
doc {
|
||||
"""
|
||||
Returns a hash code based on the contents of this array as if it is [List].
|
||||
Nested arrays are treated as lists too.
|
||||
|
||||
If any of arrays contains itself on any nesting level the behavior is undefined.
|
||||
"""
|
||||
}
|
||||
receiver("SELF?")
|
||||
returns("Int")
|
||||
on(Platform.JVM) {
|
||||
inlineOnly()
|
||||
annotation("""@JvmName("contentDeepHashCodeNullable")""")
|
||||
body {
|
||||
"""
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
|
||||
@@ -33,8 +33,8 @@ fun parseTypeParameter(typeString: String): TypeParameter =
|
||||
|
||||
fun parseTypeRef(typeRef: String): TypeRef =
|
||||
typeRef.trim().run {
|
||||
if (contains('<') && endsWith('>')) {
|
||||
val name = substringBefore('<')
|
||||
if (contains('<') && (endsWith('>') || endsWith(">?"))) {
|
||||
val name = substringBefore('<') + if (endsWith(">?")) "?" else ""
|
||||
val params = substringAfter('<').substringBeforeLast('>')
|
||||
TypeRef(name, parseArguments(params))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user