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
@@ -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)