Unify content[ToString, Equals, HashCode] function templates between JVM and JS

This commit is contained in:
Ilya Gorbunov
2016-12-07 04:58:12 +03:00
parent f3df648f4a
commit 085f476d22
4 changed files with 316 additions and 425 deletions
-30
View File
@@ -5155,7 +5155,6 @@ public fun CharArray.sortedWith(comparator: Comparator<in Char>): List<Char> {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
@@ -5168,7 +5167,6 @@ public inline infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>):
*
* If any of arrays contains itself on any nesting level the behavior is undefined.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.contentDeepHashCode(): Int {
@@ -5182,7 +5180,6 @@ public inline fun <T> Array<out T>.contentDeepHashCode(): Int {
* If any of arrays contains itself on any nesting level that reference
* is rendered as `"[...]"` to prevent recursion.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.contentDeepToString(): String {
@@ -5193,7 +5190,6 @@ public inline fun <T> Array<out T>.contentDeepToString(): String {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
@@ -5204,7 +5200,6 @@ public inline infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boo
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
@@ -5215,7 +5210,6 @@ public inline infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
@@ -5226,7 +5220,6 @@ public inline infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun IntArray.contentEquals(other: IntArray): Boolean {
@@ -5237,7 +5230,6 @@ public inline infix fun IntArray.contentEquals(other: IntArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun LongArray.contentEquals(other: LongArray): Boolean {
@@ -5248,7 +5240,6 @@ public inline infix fun LongArray.contentEquals(other: LongArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
@@ -5259,7 +5250,6 @@ public inline infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
@@ -5270,7 +5260,6 @@ public inline infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
@@ -5281,7 +5270,6 @@ public inline infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
* 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.
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline infix fun CharArray.contentEquals(other: CharArray): Boolean {
@@ -5291,7 +5279,6 @@ public inline infix fun CharArray.contentEquals(other: CharArray): Boolean {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.contentHashCode(): Int {
@@ -5301,7 +5288,6 @@ public inline fun <T> Array<out T>.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun ByteArray.contentHashCode(): Int {
@@ -5311,7 +5297,6 @@ public inline fun ByteArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun ShortArray.contentHashCode(): Int {
@@ -5321,7 +5306,6 @@ public inline fun ShortArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun IntArray.contentHashCode(): Int {
@@ -5331,7 +5315,6 @@ public inline fun IntArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun LongArray.contentHashCode(): Int {
@@ -5341,7 +5324,6 @@ public inline fun LongArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun FloatArray.contentHashCode(): Int {
@@ -5351,7 +5333,6 @@ public inline fun FloatArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun DoubleArray.contentHashCode(): Int {
@@ -5361,7 +5342,6 @@ public inline fun DoubleArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun BooleanArray.contentHashCode(): Int {
@@ -5371,7 +5351,6 @@ public inline fun BooleanArray.contentHashCode(): Int {
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun CharArray.contentHashCode(): Int {
@@ -5381,7 +5360,6 @@ public inline fun CharArray.contentHashCode(): Int {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.contentToString(): String {
@@ -5391,7 +5369,6 @@ public inline fun <T> Array<out T>.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun ByteArray.contentToString(): String {
@@ -5401,7 +5378,6 @@ public inline fun ByteArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun ShortArray.contentToString(): String {
@@ -5411,7 +5387,6 @@ public inline fun ShortArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun IntArray.contentToString(): String {
@@ -5421,7 +5396,6 @@ public inline fun IntArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun LongArray.contentToString(): String {
@@ -5431,7 +5405,6 @@ public inline fun LongArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun FloatArray.contentToString(): String {
@@ -5441,7 +5414,6 @@ public inline fun FloatArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun DoubleArray.contentToString(): String {
@@ -5451,7 +5423,6 @@ public inline fun DoubleArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun BooleanArray.contentToString(): String {
@@ -5461,7 +5432,6 @@ public inline fun BooleanArray.contentToString(): String {
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*/
@kotlin.jvm.JvmVersion
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public inline fun CharArray.contentToString(): String {
@@ -46,9 +46,8 @@ fun arrays(): List<GenericFunction> {
templates add f("contentEquals(other: SELF)") {
only(ArraysOfObjects, ArraysOfPrimitives)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
infix(true)
doc {
"""
@@ -57,14 +56,17 @@ fun arrays(): List<GenericFunction> {
"""
}
returns("Boolean")
body { "return java.util.Arrays.equals(this, other)" }
body(Platform.JVM) { "return java.util.Arrays.equals(this, other)" }
annotations(Platform.JS, """@library("arrayEquals")""")
body(Platform.JS) { "return noImpl" }
}
templates add f("contentDeepEquals(other: SELF)") {
only(ArraysOfObjects)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
infix(true)
doc {
"""
@@ -76,24 +78,26 @@ fun arrays(): List<GenericFunction> {
"""
}
returns("Boolean")
body { "return java.util.Arrays.deepEquals(this, other)" }
body(Platform.JVM) { "return java.util.Arrays.deepEquals(this, other)" }
annotations(Platform.JS, """@library("arrayDeepEquals")""")
body(Platform.JS) { "return noImpl" }
}
templates add f("contentToString()") {
only(ArraysOfObjects, ArraysOfPrimitives)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
doc { "Returns a string representation of the contents of the specified array as if it is [List]." }
returns("String")
body { "return java.util.Arrays.toString(this)" }
body(Platform.JVM) { "return java.util.Arrays.toString(this)" }
annotations(Platform.JS, """@library("arrayToString")""")
body(Platform.JS) { "return noImpl" }
}
templates add f("contentDeepToString()") {
only(ArraysOfObjects)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
doc {
"""
Returns a string representation of the contents of this array as if it is a [List].
@@ -104,26 +108,28 @@ fun arrays(): List<GenericFunction> {
"""
}
returns("String")
body { "return java.util.Arrays.deepToString(this)" }
body(Platform.JVM) { "return java.util.Arrays.deepToString(this)" }
annotations(Platform.JS, """@library("arrayDeepToString")""")
body(Platform.JS) { "return noImpl" }
}
templates add f("contentHashCode()") {
only(ArraysOfObjects, ArraysOfPrimitives)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
doc {
"Returns a hash code based on the contents of this array as if it is [List]."
}
returns("Int")
body { "return java.util.Arrays.hashCode(this)" }
body(Platform.JVM) { "return java.util.Arrays.hashCode(this)" }
annotations(Platform.JS, """@library("arrayHashCode")""")
body(Platform.JS) { "return noImpl" }
}
templates add f("contentDeepHashCode()") {
only(ArraysOfObjects)
jvmOnly(true)
since("1.1")
inline(Inline.Only)
inline(Platform.JVM, Inline.Only)
doc {
"""
Returns a hash code based on the contents of this array as if it is [List].
@@ -133,7 +139,9 @@ fun arrays(): List<GenericFunction> {
"""
}
returns("Int")
body { "return java.util.Arrays.deepHashCode(this)" }
body(Platform.JVM) { "return java.util.Arrays.deepHashCode(this)" }
annotations(Platform.JS, """@library("arrayDeepHashCode")""")
body(Platform.JS) { "return noImpl" }
}
templates addAll PrimitiveType.defaultPrimitives.map { primitive ->
@@ -135,93 +135,6 @@ fun specialJS(): List<GenericFunction> {
}
}
templates add f("contentEquals(other: SELF)") {
only(ArraysOfObjects, ArraysOfPrimitives)
since("1.1")
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.
"""
}
annotations("""@library("arrayEquals")""")
returns("Boolean")
body { "return noImpl" }
}
templates add f("contentDeepEquals(other: SELF)") {
only(ArraysOfObjects)
since("1.1")
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.
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.
"""
}
annotations("""@library("arrayDeepEquals")""")
returns("Boolean")
body { "return noImpl" }
}
templates add f("contentToString()") {
only(ArraysOfObjects, ArraysOfPrimitives)
since("1.1")
doc { "Returns a string representation of the contents of the specified array as if it is a [List]." }
annotations("""@library("arrayToString")""")
returns("String")
body { "return noImpl" }
}
templates add f("contentDeepToString()") {
only(ArraysOfObjects)
since("1.1")
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.
"""
}
annotations("""@library("arrayDeepToString")""")
returns("String")
body { "return noImpl" }
}
templates add f("contentHashCode()") {
only(ArraysOfObjects, ArraysOfPrimitives)
since("1.1")
doc {
"Returns a hash code based on the contents of this array as if it is [List]."
}
annotations("""@library("arrayHashCode")""")
returns("Int")
body { "return noImpl" }
}
templates add f("contentDeepHashCode()") {
only(ArraysOfObjects)
since("1.1")
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.
"""
}
annotations("""@library("arrayDeepHashCode")""")
returns("Int")
body { "return noImpl" }
}
templates add f("sort(noinline comparison: (T, T) -> Int)") {
only(ArraysOfObjects, ArraysOfPrimitives)
exclude(PrimitiveType.Boolean)