diff --git a/js/js.libraries/src/core/generated/_ArraysJs.kt b/js/js.libraries/src/core/generated/_ArraysJs.kt index 22541397eff..aa42608fd01 100644 --- a/js/js.libraries/src/core/generated/_ArraysJs.kt +++ b/js/js.libraries/src/core/generated/_ArraysJs.kt @@ -5191,6 +5191,8 @@ public fun Array.contentDeepHashCode(): Int { * * If any of arrays contains itself on any nesting level that reference * is rendered as `"[...]"` to prevent recursion. + * + * @sample samples.collections.Arrays.ContentOperations.contentDeepToString */ @SinceKotlin("1.1") @library("arrayDeepToString") @@ -5380,6 +5382,8 @@ public fun CharArray.contentHashCode(): Int { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5389,6 +5393,8 @@ public fun Array.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5398,6 +5404,8 @@ public fun ByteArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5407,6 +5415,8 @@ public fun ShortArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5416,6 +5426,8 @@ public fun IntArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5425,6 +5437,8 @@ public fun LongArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5434,6 +5448,8 @@ public fun FloatArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5443,6 +5459,8 @@ public fun DoubleArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") @@ -5452,6 +5470,8 @@ public fun BooleanArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @library("arrayToString") diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index f8ce1ad42f8..7d92e5f9509 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -2826,6 +2826,8 @@ public header fun Array.contentDeepHashCode(): Int * * If any of arrays contains itself on any nesting level that reference * is rendered as `"[...]"` to prevent recursion. + * + * @sample samples.collections.Arrays.ContentOperations.contentDeepToString */ @SinceKotlin("1.1") public header fun Array.contentDeepToString(): String @@ -2949,54 +2951,72 @@ public header fun CharArray.contentHashCode(): Int /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun Array.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun ByteArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun ShortArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun IntArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun LongArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun FloatArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun DoubleArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun BooleanArray.contentToString(): String /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public header fun CharArray.contentToString(): String diff --git a/libraries/stdlib/samples/test/samples/collections/arrays.kt b/libraries/stdlib/samples/test/samples/collections/arrays.kt new file mode 100644 index 00000000000..bdc3864b251 --- /dev/null +++ b/libraries/stdlib/samples/test/samples/collections/arrays.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package samples.collections + +import samples.* +import kotlin.test.* + + +@RunWith(Enclosed::class) +class Arrays { + + class ContentOperations { + + @Sample + fun contentToString() { + val array = arrayOf("apples", "oranges", "lime") + + assertPrints(array.contentToString(), "[apples, oranges, lime]") + } + + @Sample + fun contentDeepToString() { + val matrix = arrayOf( + intArrayOf(3, 7, 9), + intArrayOf(0, 1, 0), + intArrayOf(2, 4, 8) + ) + + assertPrints(matrix.contentDeepToString(), "[[3, 7, 9], [0, 1, 0], [2, 4, 8]]") + } + + } + +} \ No newline at end of file diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index c95e1707ea8..e3a4869d71b 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -5188,6 +5188,8 @@ public inline fun Array.contentDeepHashCode(): Int { * * If any of arrays contains itself on any nesting level that reference * is rendered as `"[...]"` to prevent recursion. + * + * @sample samples.collections.Arrays.ContentOperations.contentDeepToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5368,6 +5370,8 @@ public inline fun CharArray.contentHashCode(): Int { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5377,6 +5381,8 @@ public inline fun Array.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5386,6 +5392,8 @@ public inline fun ByteArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5395,6 +5403,8 @@ public inline fun ShortArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5404,6 +5414,8 @@ public inline fun IntArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5413,6 +5425,8 @@ public inline fun LongArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5422,6 +5436,8 @@ public inline fun FloatArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5431,6 +5447,8 @@ public inline fun DoubleArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -5440,6 +5458,8 @@ public inline fun BooleanArray.contentToString(): String { /** * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt index 4214756e7b4..fb3a21563a4 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt @@ -93,7 +93,13 @@ fun arrays(): List { only(ArraysOfObjects, ArraysOfPrimitives) since("1.1") inline(Platform.JVM, Inline.Only) - doc { "Returns a string representation of the contents of the specified array as if it is [List]." } + doc { + """ + Returns a string representation of the contents of the specified array as if it is [List]. + + @sample samples.collections.Arrays.ContentOperations.contentToString + """ + } returns("String") body(Platform.JVM) { "return java.util.Arrays.toString(this)" } annotations(Platform.JS, """@library("arrayToString")""") @@ -111,6 +117,8 @@ fun arrays(): List { If any of arrays contains itself on any nesting level that reference is rendered as `"[...]"` to prevent recursion. + + @sample samples.collections.Arrays.ContentOperations.contentDeepToString """ } returns("String")