From b654e84ca12395a70f0fa4833d9cf6a9c074f8a6 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Mon, 18 Mar 2019 18:58:37 +0300 Subject: [PATCH] Add documentation for Array and String get() function behavior These docs are already added to big kotlin. --- runtime/src/main/kotlin/kotlin/Array.kt | 8 +- runtime/src/main/kotlin/kotlin/Arrays.kt | 80 +++++++++++++++++++ .../src/main/kotlin/kotlin/CharSequence.kt | 2 + runtime/src/main/kotlin/kotlin/String.kt | 5 ++ 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/Array.kt b/runtime/src/main/kotlin/kotlin/Array.kt index 9e96cf84b47..263a79dd000 100644 --- a/runtime/src/main/kotlin/kotlin/Array.kt +++ b/runtime/src/main/kotlin/kotlin/Array.kt @@ -45,10 +45,12 @@ public final class Array { /** * Returns the array element at the specified [index]. This method can be called using the - * index operator: + * index operator. * ``` * value = arr[index] * ``` + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. */ @SymbolName("Kotlin_Array_get") @PointsTo(0b0100, 0, 0b0001) // points to , points to . @@ -56,10 +58,12 @@ public final class Array { /** * Sets the array element at the specified [index] to the specified [value]. This method can - * be called using the index operator: + * be called using the index operator. * ``` * arr[index] = value * ``` + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. */ @SymbolName("Kotlin_Array_set") @PointsTo(0b0100, 0, 0b0001) // points to , points to . diff --git a/runtime/src/main/kotlin/kotlin/Arrays.kt b/runtime/src/main/kotlin/kotlin/Arrays.kt index ccced547ad9..f86be3fcec6 100644 --- a/runtime/src/main/kotlin/kotlin/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/Arrays.kt @@ -35,9 +35,19 @@ public final class ByteArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_ByteArray_get") external public operator fun get(index: Int): Byte + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_ByteArray_set") external public operator fun set(index: Int, value: Byte): Unit @@ -87,9 +97,19 @@ public final class CharArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_CharArray_get") external public operator fun get(index: Int): Char + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_CharArray_set") external public operator fun set(index: Int, value: Char): Unit @@ -139,9 +159,19 @@ public final class ShortArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_ShortArray_get") external public operator fun get(index: Int): Short + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_ShortArray_set") external public operator fun set(index: Int, value: Short): Unit @@ -191,9 +221,19 @@ public final class IntArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_IntArray_get") external public operator fun get(index: Int): Int + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_IntArray_set") external public operator fun set(index: Int, value: Int): Unit @@ -243,9 +283,19 @@ public final class LongArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_LongArray_get") external public operator fun get(index: Int): Long + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_LongArray_set") external public operator fun set(index: Int, value: Long): Unit @@ -295,9 +345,19 @@ public final class FloatArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_FloatArray_get") external public operator fun get(index: Int): Float + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_FloatArray_set") external public operator fun set(index: Int, value: Float): Unit @@ -343,9 +403,19 @@ public final class DoubleArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_DoubleArray_get") external public operator fun get(index: Int): Double + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_DoubleArray_set") external public operator fun set(index: Int, value: Double): Unit @@ -391,9 +461,19 @@ public final class BooleanArray { public val size: Int get() = getArrayLength() + /** + * Returns the array element at the given [index]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_BooleanArray_get") external public operator fun get(index: Int): Boolean + /** + * Sets the element at the given [index] to the given [value]. This method can be called using the index operator. + * + * If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_BooleanArray_set") external public operator fun set(index: Int, value: Boolean): Unit diff --git a/runtime/src/main/kotlin/kotlin/CharSequence.kt b/runtime/src/main/kotlin/kotlin/CharSequence.kt index 549a7b9c48f..f54b904c370 100644 --- a/runtime/src/main/kotlin/kotlin/CharSequence.kt +++ b/runtime/src/main/kotlin/kotlin/CharSequence.kt @@ -16,6 +16,8 @@ public interface CharSequence { /** * Returns the character at the specified [index] in this character sequence. + * + * @throws [IndexOutOfBoundsException] if the [index] is out of bounds of this character sequence. */ public operator fun get(index: Int): Char diff --git a/runtime/src/main/kotlin/kotlin/String.kt b/runtime/src/main/kotlin/kotlin/String.kt index 464f871ac81..a8c91daa9fc 100644 --- a/runtime/src/main/kotlin/kotlin/String.kt +++ b/runtime/src/main/kotlin/kotlin/String.kt @@ -28,6 +28,11 @@ public final class String : Comparable, CharSequence { public override val length: Int get() = getStringLength() + /** + * Returns the character of this string at the specified [index]. + * + * If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException]. + */ @SymbolName("Kotlin_String_get") external override public fun get(index: Int): Char