Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Deprecate methods with old parameter names and remove @SinceKotlin fr…
Browse files Browse the repository at this point in the history
…om new ones
  • Loading branch information
Abduqodiri Qurbonzoda committed Dec 3, 2019
1 parent 938da9a commit dc2dec5
Showing 1 changed file with 26 additions and 82 deletions.
108 changes: 26 additions & 82 deletions runtime/src/main/kotlin/kotlin/text/StringBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ actual class StringBuilder private constructor (
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was appended to this string builder.
*/
@SinceKotlin("1.3")
actual fun append(value: Any?): StringBuilder = append(value.toString())

/**
Expand All @@ -152,32 +151,24 @@ actual class StringBuilder private constructor (
* The overall effect is exactly as if the [value] were converted to a string by the `value.toString()` method,
* and then that string was appended to this string builder.
*/
@SinceKotlin("1.3")
// TODO: optimize those!
actual fun append(value: Boolean): StringBuilder = append(value.toString())
@SinceKotlin("1.3")
fun append(value: Byte): StringBuilder = append(value.toString())
@SinceKotlin("1.3")
fun append(value: Short): StringBuilder = append(value.toString())
@SinceKotlin("1.3")
fun append(value: Int): StringBuilder {
ensureExtraCapacity(11)
_length += insertInt(array, _length, value)
return this
}
@SinceKotlin("1.3")
fun append(value: Long): StringBuilder = append(value.toString())
@SinceKotlin("1.3")
fun append(value: Float): StringBuilder = append(value.toString())
@SinceKotlin("1.3")
fun append(value: Double): StringBuilder = append(value.toString())

/**
* Appends characters in the specified character array [value] to this string builder and returns this instance.
*
* Characters are appended in order, starting at the index 0.
*/
@SinceKotlin("1.3")
actual fun append(value: CharArray): StringBuilder {
ensureExtraCapacity(value.size)
value.copyInto(array, _length)
Expand All @@ -188,7 +179,6 @@ actual class StringBuilder private constructor (
/**
* Appends the specified string [value] to this string builder and returns this instance.
*/
@SinceKotlin("1.3")
actual fun append(value: String): StringBuilder {
ensureExtraCapacity(value.length)
_length += insertString(array, _length, value)
Expand Down Expand Up @@ -289,7 +279,6 @@ actual class StringBuilder private constructor (
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
actual fun insert(index: Int, value: Char): StringBuilder {
checkInsertIndex(index)
ensureExtraCapacity(1)
Expand All @@ -309,7 +298,6 @@ actual class StringBuilder private constructor (
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
actual fun insert(index: Int, value: CharArray): StringBuilder {
checkInsertIndex(index)
ensureExtraCapacity(value.size)
Expand All @@ -331,7 +319,6 @@ actual class StringBuilder private constructor (
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
@UseExperimental(ExperimentalStdlibApi::class)
actual fun insert(index: Int, value: CharSequence?): StringBuilder {
// Kotlin/JVM inserts the "null" string if the argument is null.
Expand All @@ -354,7 +341,6 @@ actual class StringBuilder private constructor (
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@SinceKotlin("1.3")
actual fun insert(index: Int, value: String): StringBuilder {
checkInsertIndex(index)
ensureExtraCapacity(value.length)
Expand Down Expand Up @@ -811,103 +797,81 @@ public actual inline fun StringBuilder.insertRange(index: Int, value: CharSequen
this.insertRange(index, value, startIndex, endIndex)

// Method parameters renamings
/**
* Appends the string representation of the specified boolean [it] to this string builder and returns this instance.
*
* The overall effect is exactly as if the boolean [it] were converted to a string by the `boolean.toString()` method,
* and then that string was appended to this string builder.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Boolean) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Boolean): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Byte) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Byte): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Short) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Short): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Int) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Int): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Long) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Long): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Float) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Float): StringBuilder = this.append(value = it)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: Double) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: Double): StringBuilder = this.append(value = it)

/**
* Appends the specified string [it] to this string builder and returns this instance.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: String) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: String): StringBuilder = this.append(value = it)

/**
* Appends characters in the specified [CharArray] [it] to this string builder and returns this instance.
*
* Characters are appended in order, starting at the index 0.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use append(value: CharArray) instead", ReplaceWith("append(value = it)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.append(it: CharArray): StringBuilder = this.append(value = it)

/**
* Ensures that the capacity of this string builder is at least equal to the specified [capacity].
*
* If the current capacity is less than the specified [capacity], a new backing storage is allocated with greater capacity.
* Otherwise, this method takes no action and simply returns.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use ensureCapacity(minimumCapacity: Int) instead", ReplaceWith("ensureCapacity(minimumCapacity = capacity)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.ensureCapacity(capacity: Int): Unit = this.ensureCapacity(minimumCapacity = capacity)

/**
* Inserts the specified character char [c] into this string builder at the specified [index] and returns this instance.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use insert(index: Int, value: Char) instead", ReplaceWith("insert(index, value = c)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.insert(index: Int, c: Char): StringBuilder = this.insert(index, value = c)

/**
* Inserts characters in the specified [chars] array into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in same order as in the [chars] array, starting at [index].
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use insert(index: Int, value: CharArray) instead", ReplaceWith("insert(index, value = chars)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.insert(index: Int, chars: CharArray): StringBuilder = this.insert(index, value = chars)

/**
* Inserts characters in the specified character sequence [csq] into this string builder at the specified [index] and returns this instance.
*
* The inserted characters go in the same order as in the [csq] character sequence, starting at [index].
*
* @param index the position in this string builder to insert at.
* @param csq the character sequence from which characters are inserted. If [csq] is `null`, then the four characters `"null"` are inserted.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use insert(index: Int, value: CharSequence?) instead", ReplaceWith("insert(index, value = csq)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.insert(index: Int, csq: CharSequence?): StringBuilder = this.insert(index, value = csq)

/**
* Inserts the [string] into this string builder at the specified [index] and returns this instance.
*
* @throws IndexOutOfBoundsException if [index] is less than zero or greater than the length of this string builder.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use insert(index: Int, value: String) instead", ReplaceWith("insert(index, value = string)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.insert(index: Int, string: String): StringBuilder = this.insert(index, value = string)

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@Deprecated("Use setLength(newLength: Int) instead", ReplaceWith("setLength(newLength = l)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.setLength(l: Int) = this.setLength(newLength = l)

// Method renamings
/**
* Inserts characters in a subsequence of the specified character sequence [csq] into this string builder at the specified [index] and returns this instance.
Expand All @@ -928,27 +892,7 @@ public inline fun StringBuilder.insert(index: Int, string: String): StringBuilde
public inline fun StringBuilder.insert(index: Int, csq: CharSequence?, start: Int, end: Int): StringBuilder =
this.insertRange(index, csq, start, end)

/**
* Sets the length of this string builder to the specified length [l].
*
* If the [l] is less than the current length, it is changed to the specified length [l].
* Otherwise, null characters '\u0000' are appended to this string builder until its length is less than the [l].
*
* Note that in Kotlin/JS [set] operator function has non-constant execution time complexity.
* Therefore, increasing length of this string builder and then updating each character by index may slow down your program.
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] if [l] is less than zero.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
@kotlin.internal.InlineOnly
public inline fun StringBuilder.setLength(l: Int) = this.setLength(newLength = l)

/**
* Sets the character at the specified [index] to the specified [value].
*
* @throws IndexOutOfBoundsException if [index] is out of bounds of this string builder.
*/
@UseExperimental(ExperimentalStdlibApi::class)
@Deprecated("Use set(index: Int, value: Char) instead", ReplaceWith("set(index, value)"), DeprecationLevel.WARNING)
@kotlin.internal.InlineOnly
public inline fun StringBuilder.setCharAt(index: Int, value: Char) = this.set(index, value)

Expand Down

0 comments on commit dc2dec5

Please sign in to comment.