diff --git a/libraries/stdlib/common/src/kotlin/CoroutinesIntrinsicsH.kt b/libraries/stdlib/common/src/kotlin/CoroutinesIntrinsicsH.kt index d83f70b1f3b..3c0eb58f9bd 100644 --- a/libraries/stdlib/common/src/kotlin/CoroutinesIntrinsicsH.kt +++ b/libraries/stdlib/common/src/kotlin/CoroutinesIntrinsicsH.kt @@ -16,7 +16,7 @@ import kotlin.coroutines.experimental.Continuation */ @SinceKotlin("1.1") public expect inline fun (suspend () -> T).startCoroutineUninterceptedOrReturn( - completion: Continuation + completion: Continuation ): Any? /** @@ -28,17 +28,17 @@ public expect inline fun (suspend () -> T).startCoroutineUninterceptedOrRetu */ @SinceKotlin("1.1") public expect inline fun (suspend R.() -> T).startCoroutineUninterceptedOrReturn( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ): Any? @SinceKotlin("1.1") public expect fun (suspend () -> T).createCoroutineUnchecked( - completion: Continuation + completion: Continuation ): Continuation @SinceKotlin("1.1") public expect fun (suspend R.() -> T).createCoroutineUnchecked( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ): Continuation diff --git a/libraries/stdlib/common/src/kotlin/MathH.kt b/libraries/stdlib/common/src/kotlin/MathH.kt index f401b22b24e..7f2ce574192 100644 --- a/libraries/stdlib/common/src/kotlin/MathH.kt +++ b/libraries/stdlib/common/src/kotlin/MathH.kt @@ -345,6 +345,7 @@ public expect fun sign(x: Double): Double */ @SinceKotlin("1.2") public expect fun min(a: Double, b: Double): Double + /** * Returns the greater of two values. * @@ -432,6 +433,7 @@ public expect val Double.ulp: Double */ @SinceKotlin("1.2") public expect fun Double.nextUp(): Double + /** * Returns the [Double] value nearest to this value in direction of negative infinity. */ @@ -805,6 +807,7 @@ public expect fun sign(x: Float): Float */ @SinceKotlin("1.2") public expect fun min(a: Float, b: Float): Float + /** * Returns the greater of two values. * @@ -868,6 +871,7 @@ public expect val Float.sign: Float */ @SinceKotlin("1.2") public expect fun Float.withSign(sign: Float): Float + /** * Returns this value with the sign bit same as of the [sign] value. */ diff --git a/libraries/stdlib/common/src/kotlin/TextH.kt b/libraries/stdlib/common/src/kotlin/TextH.kt index f7ea24fa976..54a44fe36d0 100644 --- a/libraries/stdlib/common/src/kotlin/TextH.kt +++ b/libraries/stdlib/common/src/kotlin/TextH.kt @@ -109,20 +109,24 @@ public expect fun CharSequence.repeat(n: Int): String * Returns a new string with all occurrences of [oldChar] replaced with [newChar]. */ expect fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String + /** * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string * with the specified [newValue] string. */ expect fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String + /** * Returns a new string with the first occurrence of [oldChar] replaced with [newChar]. */ expect fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String + /** * Returns a new string obtained by replacing the first occurrence of the [oldValue] substring in this string * with the specified [newValue] string. */ expect fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String + /** * Returns `true` if this string is equal to [other], optionally ignoring character case. * @@ -143,8 +147,13 @@ expect fun CharSequence.isBlank(): Boolean * @param otherOffset the start offset in the other char sequence of the substring to compare. * @param length the length of the substring to compare. */ -expect fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean - +expect fun CharSequence.regionMatches( + thisOffset: Int, + other: CharSequence, + otherOffset: Int, + length: Int, + ignoreCase: Boolean = false +): Boolean /** @@ -228,4 +237,5 @@ expect fun String.toFloatOrNull(): Float? @PublishedApi internal expect fun checkRadix(radix: Int): Int + internal expect fun digitOf(char: Char, radix: Int): Int diff --git a/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt b/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt index d5a26d390c5..838e41459dd 100644 --- a/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt +++ b/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt @@ -20,7 +20,7 @@ public fun compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<* return compareValuesByImpl(a, b, selectors) } -private fun compareValuesByImpl(a: T, b: T, selectors: ArrayComparable<*>?>): Int { +private fun compareValuesByImpl(a: T, b: T, selectors: Array Comparable<*>?>): Int { for (fn in selectors) { val v1 = fn(a) val v2 = fn(b) @@ -92,7 +92,6 @@ public fun compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator } - /** * Creates a comparator using the function to transform value to a [Comparable] instance for comparison. * @@ -100,7 +99,7 @@ public fun compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator */ @kotlin.internal.InlineOnly public inline fun compareBy(crossinline selector: (T) -> Comparable<*>?): Comparator = - Comparator { a, b -> compareValuesBy(a, b, selector) } + Comparator { a, b -> compareValuesBy(a, b, selector) } /** * Creates a comparator using the [selector] function to transform values being compared and then applying @@ -110,7 +109,7 @@ public inline fun compareBy(crossinline selector: (T) -> Comparable<*>?): Co */ @kotlin.internal.InlineOnly public inline fun compareBy(comparator: Comparator, crossinline selector: (T) -> K): Comparator = - Comparator { a, b -> compareValuesBy(a, b, comparator, selector) } + Comparator { a, b -> compareValuesBy(a, b, comparator, selector) } /** * Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison. @@ -119,7 +118,7 @@ public inline fun compareBy(comparator: Comparator, crossinline sel */ @kotlin.internal.InlineOnly public inline fun compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator = - Comparator { a, b -> compareValuesBy(b, a, selector) } + Comparator { a, b -> compareValuesBy(b, a, selector) } /** * Creates a descending comparator using the [selector] function to transform values being compared and then applying @@ -131,7 +130,7 @@ public inline fun compareByDescending(crossinline selector: (T) -> Comparabl */ @kotlin.internal.InlineOnly public inline fun compareByDescending(comparator: Comparator, crossinline selector: (T) -> K): Comparator = - Comparator { a, b -> compareValuesBy(b, a, comparator, selector) } + Comparator { a, b -> compareValuesBy(b, a, comparator, selector) } /** * Creates a comparator comparing values after the primary comparator defined them equal. It uses @@ -141,10 +140,10 @@ public inline fun compareByDescending(comparator: Comparator, cross */ @kotlin.internal.InlineOnly public inline fun Comparator.thenBy(crossinline selector: (T) -> Comparable<*>?): Comparator = - Comparator { a, b -> - val previousCompare = this@thenBy.compare(a, b) - if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector) - } + Comparator { a, b -> + val previousCompare = this@thenBy.compare(a, b) + if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector) + } /** * Creates a comparator comparing values after the primary comparator defined them equal. It uses @@ -154,10 +153,10 @@ public inline fun Comparator.thenBy(crossinline selector: (T) -> Comparab */ @kotlin.internal.InlineOnly public inline fun Comparator.thenBy(comparator: Comparator, crossinline selector: (T) -> K): Comparator = - Comparator { a, b -> - val previousCompare = this@thenBy.compare(a, b) - if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparator, selector) - } + Comparator { a, b -> + val previousCompare = this@thenBy.compare(a, b) + if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparator, selector) + } /** * Creates a descending comparator using the primary comparator and @@ -167,10 +166,10 @@ public inline fun Comparator.thenBy(comparator: Comparator, cros */ @kotlin.internal.InlineOnly public inline fun Comparator.thenByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator = - Comparator { a, b -> - val previousCompare = this@thenByDescending.compare(a, b) - if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector) - } + Comparator { a, b -> + val previousCompare = this@thenByDescending.compare(a, b) + if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector) + } /** * Creates a descending comparator comparing values after the primary comparator defined them equal. It uses @@ -180,10 +179,10 @@ public inline fun Comparator.thenByDescending(crossinline selector: (T) - */ @kotlin.internal.InlineOnly public inline fun Comparator.thenByDescending(comparator: Comparator, crossinline selector: (T) -> K): Comparator = - Comparator { a, b -> - val previousCompare = this@thenByDescending.compare(a, b) - if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparator, selector) - } + Comparator { a, b -> + val previousCompare = this@thenByDescending.compare(a, b) + if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparator, selector) + } /** @@ -193,10 +192,10 @@ public inline fun Comparator.thenByDescending(comparator: Comparator Comparator.thenComparator(crossinline comparison: (a: T, b: T) -> Int): Comparator = - Comparator { a, b -> - val previousCompare = this@thenComparator.compare(a, b) - if (previousCompare != 0) previousCompare else comparison(a, b) - } + Comparator { a, b -> + val previousCompare = this@thenComparator.compare(a, b) + if (previousCompare != 0) previousCompare else comparison(a, b) + } /** * Combines this comparator and the given [comparator] such that the latter is applied only @@ -205,10 +204,10 @@ public inline fun Comparator.thenComparator(crossinline comparison: (a: T * @sample samples.comparisons.Comparisons.then */ public infix fun Comparator.then(comparator: Comparator): Comparator = - Comparator { a, b -> - val previousCompare = this@then.compare(a, b) - if (previousCompare != 0) previousCompare else comparator.compare(a, b) - } + Comparator { a, b -> + val previousCompare = this@then.compare(a, b) + if (previousCompare != 0) previousCompare else comparator.compare(a, b) + } /** * Combines this comparator and the given [comparator] such that the latter is applied only @@ -217,10 +216,10 @@ public infix fun Comparator.then(comparator: Comparator): Comparato * @sample samples.comparisons.Comparisons.thenDescending */ public infix fun Comparator.thenDescending(comparator: Comparator): Comparator = - Comparator { a, b -> - val previousCompare = this@thenDescending.compare(a, b) - if (previousCompare != 0) previousCompare else comparator.compare(b, a) - } + Comparator { a, b -> + val previousCompare = this@thenDescending.compare(a, b) + if (previousCompare != 0) previousCompare else comparator.compare(b, a) + } // Not so useful without type inference for receiver of expression /** @@ -229,15 +228,15 @@ public infix fun Comparator.thenDescending(comparator: Comparator): * * @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator */ -public fun nullsFirst(comparator: Comparator): Comparator = - Comparator { a, b -> - when { - a === b -> 0 - a == null -> -1 - b == null -> 1 - else -> comparator.compare(a, b) - } +public fun nullsFirst(comparator: Comparator): Comparator = + Comparator { a, b -> + when { + a === b -> 0 + a == null -> -1 + b == null -> 1 + else -> comparator.compare(a, b) } + } /** * Provides a comparator of nullable [Comparable] values @@ -246,7 +245,7 @@ public fun nullsFirst(comparator: Comparator): Comparator = * @sample samples.comparisons.Comparisons.nullsFirstLastComparator */ @kotlin.internal.InlineOnly -public inline fun > nullsFirst(): Comparator = nullsFirst(naturalOrder()) +public inline fun > nullsFirst(): Comparator = nullsFirst(naturalOrder()) /** * Extends the given [comparator] of non-nullable values to a comparator of nullable values @@ -254,15 +253,15 @@ public inline fun > nullsFirst(): Comparator = nullsFirst(n * * @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator */ -public fun nullsLast(comparator: Comparator): Comparator = - Comparator { a, b -> - when { - a === b -> 0 - a == null -> 1 - b == null -> -1 - else -> comparator.compare(a, b) - } +public fun nullsLast(comparator: Comparator): Comparator = + Comparator { a, b -> + when { + a === b -> 0 + a == null -> 1 + b == null -> -1 + else -> comparator.compare(a, b) } + } /** * Provides a comparator of nullable [Comparable] values @@ -271,21 +270,21 @@ public fun nullsLast(comparator: Comparator): Comparator = * @sample samples.comparisons.Comparisons.nullsFirstLastComparator */ @kotlin.internal.InlineOnly -public inline fun > nullsLast(): Comparator = nullsLast(naturalOrder()) +public inline fun > nullsLast(): Comparator = nullsLast(naturalOrder()) /** * Returns a comparator that compares [Comparable] objects in natural order. * * @sample samples.comparisons.Comparisons.naturalOrderComparator */ -public fun > naturalOrder(): Comparator = @Suppress("UNCHECKED_CAST") (NaturalOrderComparator as Comparator) +public fun > naturalOrder(): Comparator = @Suppress("UNCHECKED_CAST") (NaturalOrderComparator as Comparator) /** * Returns a comparator that compares [Comparable] objects in reversed natural order. * * @sample samples.comparisons.Comparisons.nullsFirstLastWithComparator */ -public fun > reverseOrder(): Comparator = @Suppress("UNCHECKED_CAST") (ReverseOrderComparator as Comparator) +public fun > reverseOrder(): Comparator = @Suppress("UNCHECKED_CAST") (ReverseOrderComparator as Comparator) /** * Returns a comparator that imposes the reverse ordering of this comparator. @@ -300,7 +299,7 @@ public fun Comparator.reversed(): Comparator = when (this) { } -private class ReversedComparator(public val comparator: Comparator): Comparator { +private class ReversedComparator(public val comparator: Comparator) : Comparator { override fun compare(a: T, b: T): Int = comparator.compare(b, a) @Suppress("VIRTUAL_MEMBER_HIDDEN") fun reversed(): Comparator = comparator @@ -312,7 +311,7 @@ private object NaturalOrderComparator : Comparator> { fun reversed(): Comparator> = ReverseOrderComparator } -private object ReverseOrderComparator: Comparator> { +private object ReverseOrderComparator : Comparator> { override fun compare(a: Comparable, b: Comparable): Int = b.compareTo(a) @Suppress("VIRTUAL_MEMBER_HIDDEN") fun reversed(): Comparator> = NaturalOrderComparator diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContext.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContext.kt index fe5c0c5ff04..6ba14317173 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContext.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContext.kt @@ -30,19 +30,19 @@ public interface CoroutineContext { * The elements from this context with the same key as in the other one are dropped. */ public operator fun plus(context: CoroutineContext): CoroutineContext = - if (context === EmptyCoroutineContext) this else // fast path -- avoid lambda creation - context.fold(this) { acc, element -> - val removed = acc.minusKey(element.key) - if (removed === EmptyCoroutineContext) element else { - // make sure interceptor is always last in the context (and thus is fast to get when present) - val interceptor = removed[ContinuationInterceptor] - if (interceptor == null) CombinedContext(removed, element) else { - val left = removed.minusKey(ContinuationInterceptor) - if (left === EmptyCoroutineContext) CombinedContext(element, interceptor) else - CombinedContext(CombinedContext(left, element), interceptor) - } + if (context === EmptyCoroutineContext) this else // fast path -- avoid lambda creation + context.fold(this) { acc, element -> + val removed = acc.minusKey(element.key) + if (removed === EmptyCoroutineContext) element else { + // make sure interceptor is always last in the context (and thus is fast to get when present) + val interceptor = removed[ContinuationInterceptor] + if (interceptor == null) CombinedContext(removed, element) else { + val left = removed.minusKey(ContinuationInterceptor) + if (left === EmptyCoroutineContext) CombinedContext(element, interceptor) else + CombinedContext(CombinedContext(left, element), interceptor) } } + } /** * Returns a context containing elements from this context, but without an element with @@ -62,13 +62,13 @@ public interface CoroutineContext { @Suppress("UNCHECKED_CAST") public override operator fun get(key: Key): E? = - if (this.key === key) this as E else null + if (this.key === key) this as E else null public override fun fold(initial: R, operation: (R, Element) -> R): R = - operation(initial, this) + operation(initial, this) public override fun minusKey(key: Key<*>): CoroutineContext = - if (this.key === key) EmptyCoroutineContext else this + if (this.key === key) EmptyCoroutineContext else this } /** diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContextImpl.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContextImpl.kt index c9cda742c41..92f9fcc31b2 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContextImpl.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutineContextImpl.kt @@ -45,7 +45,7 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element) } public override fun fold(initial: R, operation: (R, Element) -> R): R = - operation(left.fold(initial, operation), element) + operation(left.fold(initial, operation), element) public override fun minusKey(key: Key<*>): CoroutineContext { element[key]?.let { return left } @@ -58,10 +58,10 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element) } private fun size(): Int = - if (left is CombinedContext) left.size() + 1 else 2 + if (left is CombinedContext) left.size() + 1 else 2 private fun contains(element: Element): Boolean = - get(element.key) == element + get(element.key) == element private fun containsAll(context: CombinedContext): Boolean { var cur = context @@ -77,12 +77,12 @@ internal class CombinedContext(val left: CoroutineContext, val element: Element) } override fun equals(other: Any?): Boolean = - this === other || other is CombinedContext && other.size() == size() && other.containsAll(this) + this === other || other is CombinedContext && other.size() == size() && other.containsAll(this) override fun hashCode(): Int = left.hashCode() + element.hashCode() override fun toString(): String = - "[" + fold("") { acc, element -> - if (acc.isEmpty()) element.toString() else acc + ", " + element - } + "]" + "[" + fold("") { acc, element -> + if (acc.isEmpty()) element.toString() else acc + ", " + element + } + "]" } diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutinesLibrary.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutinesLibrary.kt index 517ba341c2f..3b7e8698e80 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutinesLibrary.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/CoroutinesLibrary.kt @@ -4,6 +4,7 @@ */ @file:kotlin.jvm.JvmName("CoroutinesKt") + package kotlin.coroutines.experimental import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED @@ -19,8 +20,8 @@ import kotlin.internal.InlineOnly @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") public fun (suspend R.() -> T).startCoroutine( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ) { createCoroutineUnchecked(receiver, completion).resume(Unit) } @@ -32,8 +33,8 @@ public fun (suspend R.() -> T).startCoroutine( */ @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") -public fun (suspend () -> T).startCoroutine( - completion: Continuation +public fun (suspend () -> T).startCoroutine( + completion: Continuation ) { createCoroutineUnchecked(completion).resume(Unit) } @@ -49,8 +50,8 @@ public fun (suspend () -> T).startCoroutine( @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") public fun (suspend R.() -> T).createCoroutine( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ): Continuation = SafeContinuation(createCoroutineUnchecked(receiver, completion), COROUTINE_SUSPENDED) /** @@ -64,7 +65,7 @@ public fun (suspend R.() -> T).createCoroutine( @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") public fun (suspend () -> T).createCoroutine( - completion: Continuation + completion: Continuation ): Continuation = SafeContinuation(createCoroutineUnchecked(completion), COROUTINE_SUSPENDED) /** @@ -77,11 +78,11 @@ public fun (suspend () -> T).createCoroutine( */ @SinceKotlin("1.1") public suspend inline fun suspendCoroutine(crossinline block: (Continuation) -> Unit): T = - suspendCoroutineOrReturn { c: Continuation -> - val safe = SafeContinuation(c) - block(safe) - safe.getResult() - } + suspendCoroutineOrReturn { c: Continuation -> + val safe = SafeContinuation(c) + block(safe) + safe.getResult() + } /** * Continuation context of current coroutine. diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/SequenceBuilder.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/SequenceBuilder.kt index 5d8c2d673bf..c7982fafa7c 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/SequenceBuilder.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/SequenceBuilder.kt @@ -5,6 +5,7 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("SequenceBuilderKt") + package kotlin.coroutines.experimental import kotlin.* @@ -84,6 +85,7 @@ public abstract class SequenceBuilder internal constructor() { } private typealias State = Int + private const val State_NotReady: State = 0 private const val State_ManyNotReady: State = 1 private const val State_ManyReady: State = 2 @@ -129,7 +131,7 @@ private class SequenceBuilderIterator : SequenceBuilder(), Iterator, Co } State_Ready -> { state = State_NotReady - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST") val result = nextValue as T nextValue = null return result diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt index 20f2e2ee6bd..ece69c476f8 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt @@ -31,7 +31,7 @@ import kotlin.coroutines.experimental.* @kotlin.internal.InlineOnly @Suppress("UNUSED_PARAMETER") public suspend inline fun suspendCoroutineOrReturn(crossinline block: (Continuation) -> Any?): T = - suspendCoroutineUninterceptedOrReturn { cont -> block(cont.intercepted()) } + suspendCoroutineUninterceptedOrReturn { cont -> block(cont.intercepted()) } /** * Obtains the current continuation instance inside suspend functions and either suspends @@ -42,7 +42,7 @@ public suspend inline fun suspendCoroutineOrReturn(crossinline block: (Conti @SinceKotlin("1.2") @kotlin.internal.InlineOnly public suspend inline fun suspendCoroutineUninterceptedOrReturn(crossinline block: (Continuation) -> Any?): T = - throw NotImplementedError("Implementation of suspendCoroutineUninterceptedOrReturn is intrinsic") + throw NotImplementedError("Implementation of suspendCoroutineUninterceptedOrReturn is intrinsic") /** * Intercept continuation with [ContinuationInterceptor]. @@ -50,7 +50,7 @@ public suspend inline fun suspendCoroutineUninterceptedOrReturn(crossinline @SinceKotlin("1.2") @kotlin.internal.InlineOnly public inline fun Continuation.intercepted(): Continuation = - throw NotImplementedError("Implementation of intercepted is intrinsic") + throw NotImplementedError("Implementation of intercepted is intrinsic") /** * Continuation context of current coroutine. diff --git a/libraries/stdlib/src/kotlin/experimental/bitwiseOperations.kt b/libraries/stdlib/src/kotlin/experimental/bitwiseOperations.kt index b40a849a746..0ba8717235d 100644 --- a/libraries/stdlib/src/kotlin/experimental/bitwiseOperations.kt +++ b/libraries/stdlib/src/kotlin/experimental/bitwiseOperations.kt @@ -9,14 +9,17 @@ package kotlin.experimental @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Byte.and(other: Byte): Byte = (this.toInt() and other.toInt()).toByte() + /** Performs a bitwise OR operation between the two values. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Byte.or(other: Byte): Byte = (this.toInt() or other.toInt()).toByte() + /** Performs a bitwise XOR operation between the two values. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Byte.xor(other: Byte): Byte = (this.toInt() xor other.toInt()).toByte() + /** Inverts the bits in this value. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly @@ -27,14 +30,17 @@ public inline fun Byte.inv(): Byte = (this.toInt().inv()).toByte() @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Short.and(other: Short): Short = (this.toInt() and other.toInt()).toShort() + /** Performs a bitwise OR operation between the two values. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Short.or(other: Short): Short = (this.toInt() or other.toInt()).toShort() + /** Performs a bitwise XOR operation between the two values. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline infix fun Short.xor(other: Short): Short = (this.toInt() xor other.toInt()).toShort() + /** Inverts the bits in this value. */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly diff --git a/libraries/stdlib/src/kotlin/internal/Annotations.kt b/libraries/stdlib/src/kotlin/internal/Annotations.kt index 4ed3893ea54..3efa319859b 100644 --- a/libraries/stdlib/src/kotlin/internal/Annotations.kt +++ b/libraries/stdlib/src/kotlin/internal/Annotations.kt @@ -86,11 +86,11 @@ internal annotation class AccessibleLateinitPropertyLiteral @Retention(AnnotationRetention.SOURCE) @SinceKotlin("1.2") internal annotation class RequireKotlin( - val version: String, - val message: String = "", - val level: DeprecationLevel = DeprecationLevel.ERROR, - val versionKind: RequireKotlinVersionKind = RequireKotlinVersionKind.LANGUAGE_VERSION, - val errorCode: Int = -1 + val version: String, + val message: String = "", + val level: DeprecationLevel = DeprecationLevel.ERROR, + val versionKind: RequireKotlinVersionKind = RequireKotlinVersionKind.LANGUAGE_VERSION, + val errorCode: Int = -1 ) /** diff --git a/libraries/stdlib/src/kotlin/properties/Delegates.kt b/libraries/stdlib/src/kotlin/properties/Delegates.kt index bb7226cad43..a648857c9d8 100644 --- a/libraries/stdlib/src/kotlin/properties/Delegates.kt +++ b/libraries/stdlib/src/kotlin/properties/Delegates.kt @@ -19,7 +19,7 @@ public object Delegates { * * @sample samples.properties.Delegates.notNullDelegate */ - public fun notNull(): ReadWriteProperty = NotNullVar() + public fun notNull(): ReadWriteProperty = NotNullVar() /** * Returns a property delegate for a read/write property that calls a specified callback function when changed. @@ -30,7 +30,8 @@ public object Delegates { * @sample samples.properties.Delegates.observableDelegate */ public inline fun observable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Unit): - ReadWriteProperty = object : ObservableProperty(initialValue) { + ReadWriteProperty = + object : ObservableProperty(initialValue) { override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) = onChange(property, oldValue, newValue) } @@ -47,14 +48,15 @@ public object Delegates { * @sample samples.properties.Delegates.throwVetoableDelegate */ public inline fun vetoable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Boolean): - ReadWriteProperty = object : ObservableProperty(initialValue) { + ReadWriteProperty = + object : ObservableProperty(initialValue) { override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean = onChange(property, oldValue, newValue) } } -private class NotNullVar() : ReadWriteProperty { +private class NotNullVar() : ReadWriteProperty { private var value: T? = null public override fun getValue(thisRef: Any?, property: KProperty<*>): T { diff --git a/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt b/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt index 95f369e25f5..4636e4f90cb 100644 --- a/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt +++ b/libraries/stdlib/src/kotlin/properties/ObservableProperty.kt @@ -26,7 +26,7 @@ public abstract class ObservableProperty(initialValue: T) : ReadWriteProperty * The callback which is called after the change of the property is made. The value of the property * has already been changed when this callback is invoked. */ - protected open fun afterChange (property: KProperty<*>, oldValue: T, newValue: T): Unit {} + protected open fun afterChange(property: KProperty<*>, oldValue: T, newValue: T): Unit {} public override fun getValue(thisRef: Any?, property: KProperty<*>): T { return value diff --git a/libraries/stdlib/src/kotlin/ranges/Ranges.kt b/libraries/stdlib/src/kotlin/ranges/Ranges.kt index ab18c2b251b..0abc26bb6f5 100644 --- a/libraries/stdlib/src/kotlin/ranges/Ranges.kt +++ b/libraries/stdlib/src/kotlin/ranges/Ranges.kt @@ -5,6 +5,7 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("RangesKt") + package kotlin.ranges import kotlin.* @@ -17,7 +18,7 @@ import kotlin.* * achieve IEEE-754 comparison order instead of total order of floating point numbers. */ @SinceKotlin("1.1") -public interface ClosedFloatingPointRange> : ClosedRange { +public interface ClosedFloatingPointRange> : ClosedRange { override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive) override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive) @@ -30,10 +31,10 @@ public interface ClosedFloatingPointRange> : ClosedRange { /** * Represents a range of [Comparable] values. */ -private open class ComparableRange> ( - override val start: T, - override val endInclusive: T -): ClosedRange { +private open class ComparableRange>( + override val start: T, + override val endInclusive: T +) : ClosedRange { override fun equals(other: Any?): Boolean { return other is ComparableRange<*> && (isEmpty() && other.isEmpty() || @@ -52,9 +53,9 @@ private open class ComparableRange> ( * * Numbers are compared with the ends of this range according to IEEE-754. */ -private class ClosedDoubleRange ( - start: Double, - endInclusive: Double +private class ClosedDoubleRange( + start: Double, + endInclusive: Double ) : ClosedFloatingPointRange { private val _start = start private val _endInclusive = endInclusive @@ -74,6 +75,7 @@ private class ClosedDoubleRange ( override fun hashCode(): Int { return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode() } + override fun toString(): String = "$_start..$_endInclusive" } @@ -84,7 +86,7 @@ private class ClosedDoubleRange ( * This value needs to be smaller than [that] value, otherwise the returned range will be empty. * @sample samples.ranges.Ranges.rangeFromComparable */ -public operator fun > T.rangeTo(that: T): ClosedRange = ComparableRange(this, that) +public operator fun > T.rangeTo(that: T): ClosedRange = ComparableRange(this, that) /** * Creates a range from this [Double] value to the specified [that] value. diff --git a/libraries/stdlib/src/kotlin/text/Char.kt b/libraries/stdlib/src/kotlin/text/Char.kt index a0b1dbd8c81..492379e7972 100644 --- a/libraries/stdlib/src/kotlin/text/Char.kt +++ b/libraries/stdlib/src/kotlin/text/Char.kt @@ -12,7 +12,7 @@ package kotlin.text * Concatenates this Char and a String. */ @kotlin.internal.InlineOnly -public inline operator fun Char.plus(other: String) : String = this.toString() + other +public inline operator fun Char.plus(other: String): String = this.toString() + other /** * Returns `true` if this character is equal to the [other] character, optionally ignoring character case. diff --git a/libraries/stdlib/src/kotlin/text/Indent.kt b/libraries/stdlib/src/kotlin/text/Indent.kt index b4016179ccd..959a1ede286 100644 --- a/libraries/stdlib/src/kotlin/text/Indent.kt +++ b/libraries/stdlib/src/kotlin/text/Indent.kt @@ -69,9 +69,9 @@ public fun String.replaceIndent(newIndent: String = ""): String { val lines = lines() val minCommonIndent = lines - .filter(String::isNotBlank) - .map(String::indentWidth) - .min() ?: 0 + .filter(String::isNotBlank) + .map(String::indentWidth) + .min() ?: 0 return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) }) } @@ -83,18 +83,18 @@ public fun String.replaceIndent(newIndent: String = ""): String { */ public fun String.prependIndent(indent: String = " "): String = lineSequence() - .map { - when { - it.isBlank() -> { - when { - it.length < indent.length -> indent - else -> it + .map { + when { + it.isBlank() -> { + when { + it.length < indent.length -> indent + else -> it + } } + else -> indent + it } - else -> indent + it } - } - .joinToString("\n") + .joinToString("\n") private fun String.indentWidth(): Int = indexOfFirst { !it.isWhitespace() }.let { if (it == -1) length else it } @@ -103,14 +103,18 @@ private fun getIndentFunction(indent: String) = when { else -> { line: String -> indent + line } } -private inline fun List.reindent(resultSizeEstimate: Int, indentAddFunction: (String) -> String, indentCutFunction: (String) -> String?): String { +private inline fun List.reindent( + resultSizeEstimate: Int, + indentAddFunction: (String) -> String, + indentCutFunction: (String) -> String? +): String { val lastIndex = lastIndex return mapIndexedNotNull { index, value -> - if ((index == 0 || index == lastIndex) && value.isBlank()) - null - else - indentCutFunction(value)?.let(indentAddFunction) ?: value - } + if ((index == 0 || index == lastIndex) && value.isBlank()) + null + else + indentCutFunction(value)?.let(indentAddFunction) ?: value + } .joinTo(StringBuilder(resultSizeEstimate), "\n") .toString() } diff --git a/libraries/stdlib/src/kotlin/text/StringBuilder.kt b/libraries/stdlib/src/kotlin/text/StringBuilder.kt index 74758397d2e..5733480f8d2 100644 --- a/libraries/stdlib/src/kotlin/text/StringBuilder.kt +++ b/libraries/stdlib/src/kotlin/text/StringBuilder.kt @@ -14,7 +14,7 @@ package kotlin.text */ @kotlin.internal.InlineOnly public inline fun buildString(builderAction: StringBuilder.() -> Unit): String = - StringBuilder().apply(builderAction).toString() + StringBuilder().apply(builderAction).toString() /** * Builds new string by populating newly created [StringBuilder] initialized with the given [capacity] @@ -23,7 +23,7 @@ public inline fun buildString(builderAction: StringBuilder.() -> Unit): String = @SinceKotlin("1.1") @kotlin.internal.InlineOnly public inline fun buildString(capacity: Int, builderAction: StringBuilder.() -> Unit): String = - StringBuilder(capacity).apply(builderAction).toString() + StringBuilder(capacity).apply(builderAction).toString() /** * Appends all arguments to the given [Appendable]. @@ -53,7 +53,6 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder { } - internal fun Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) { when { transform != null -> append(transform(element)) diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index f40c28b22b9..e6b2e1b98b4 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -31,8 +31,7 @@ public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence startFound = true else startIndex += 1 - } - else { + } else { if (!match) break else @@ -46,8 +45,8 @@ public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence /** * Returns a string having leading and trailing characters matching the [predicate] removed. */ -public inline fun String.trim(predicate: (Char) -> Boolean): String - = (this as CharSequence).trim(predicate).toString() +public inline fun String.trim(predicate: (Char) -> Boolean): String = + (this as CharSequence).trim(predicate).toString() /** * Returns a sub sequence of this char sequence having leading characters matching the [predicate] removed. @@ -63,8 +62,8 @@ public inline fun CharSequence.trimStart(predicate: (Char) -> Boolean): CharSequ /** * Returns a string having leading characters matching the [predicate] removed. */ -public inline fun String.trimStart(predicate: (Char) -> Boolean): String - = (this as CharSequence).trimStart(predicate).toString() +public inline fun String.trimStart(predicate: (Char) -> Boolean): String = + (this as CharSequence).trimStart(predicate).toString() /** * Returns a sub sequence of this char sequence having trailing characters matching the [predicate] removed. @@ -80,8 +79,8 @@ public inline fun CharSequence.trimEnd(predicate: (Char) -> Boolean): CharSequen /** * Returns a string having trailing characters matching the [predicate] removed. */ -public inline fun String.trimEnd(predicate: (Char) -> Boolean): String - = (this as CharSequence).trimEnd(predicate).toString() +public inline fun String.trimEnd(predicate: (Char) -> Boolean): String = + (this as CharSequence).trimEnd(predicate).toString() /** * Returns a sub sequence of this char sequence having leading and trailing characters from the [chars] array removed. @@ -176,8 +175,8 @@ public fun CharSequence.padStart(length: Int, padChar: Char = ' '): CharSequence * @returns Returns a string, of length at least [length], consisting of string prepended with [padChar] as many times. * as are necessary to reach that length. */ -public fun String.padStart(length: Int, padChar: Char = ' '): String - = (this as CharSequence).padStart(length, padChar).toString() +public fun String.padStart(length: Int, padChar: Char = ' '): String = + (this as CharSequence).padStart(length, padChar).toString() /** * Returns a char sequence with content of this char sequence padded at the end @@ -209,8 +208,8 @@ public fun CharSequence.padEnd(length: Int, padChar: Char = ' '): CharSequence { * @returns Returns a string, of length at least [length], consisting of string prepended with [padChar] as many times. * as are necessary to reach that length. */ -public fun String.padEnd(length: Int, padChar: Char = ' '): String - = (this as CharSequence).padEnd(length, padChar).toString() +public fun String.padEnd(length: Int, padChar: Char = ' '): String = + (this as CharSequence).padEnd(length, padChar).toString() /** * Returns `true` if this nullable char sequence is either `null` or empty. @@ -423,8 +422,8 @@ public fun CharSequence.replaceRange(startIndex: Int, endIndex: Int, replacement * @param endIndex the index of the first character after the replacement to keep in the string. */ @kotlin.internal.InlineOnly -public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): String - = (this as CharSequence).replaceRange(startIndex, endIndex, replacement).toString() +public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): String = + (this as CharSequence).replaceRange(startIndex, endIndex, replacement).toString() /** * Returns a char sequence with content of this char sequence where its part at the given [range] @@ -432,8 +431,8 @@ public inline fun String.replaceRange(startIndex: Int, endIndex: Int, replacemen * * The end index of the [range] is included in the part to be replaced. */ -public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence): CharSequence - = replaceRange(range.start, range.endInclusive + 1, replacement) +public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence): CharSequence = + replaceRange(range.start, range.endInclusive + 1, replacement) /** * Replace the part of string at the given [range] with the [replacement] string. @@ -441,8 +440,8 @@ public fun CharSequence.replaceRange(range: IntRange, replacement: CharSequence) * The end index of the [range] is included in the part to be replaced. */ @kotlin.internal.InlineOnly -public inline fun String.replaceRange(range: IntRange, replacement: CharSequence): String - = (this as CharSequence).replaceRange(range, replacement).toString() +public inline fun String.replaceRange(range: IntRange, replacement: CharSequence): String = + (this as CharSequence).replaceRange(range, replacement).toString() /** * Returns a char sequence with content of this char sequence where its part at the given range is removed. @@ -473,8 +472,8 @@ public fun CharSequence.removeRange(startIndex: Int, endIndex: Int): CharSequenc * [endIndex] is not included in the removed part. */ @kotlin.internal.InlineOnly -public inline fun String.removeRange(startIndex: Int, endIndex: Int): String - = (this as CharSequence).removeRange(startIndex, endIndex).toString() +public inline fun String.removeRange(startIndex: Int, endIndex: Int): String = + (this as CharSequence).removeRange(startIndex, endIndex).toString() /** * Returns a char sequence with content of this char sequence where its part at the given [range] is removed. @@ -489,8 +488,8 @@ public fun CharSequence.removeRange(range: IntRange): CharSequence = removeRange * The end index of the [range] is included in the removed part. */ @kotlin.internal.InlineOnly -public inline fun String.removeRange(range: IntRange): String - = (this as CharSequence).removeRange(range).toString() +public inline fun String.removeRange(range: IntRange): String = + (this as CharSequence).removeRange(range).toString() /** * If this char sequence starts with the given [prefix], returns a new char sequence @@ -666,7 +665,8 @@ public inline fun CharSequence.replace(regex: Regex, replacement: String): Strin * replacement for that match. */ @kotlin.internal.InlineOnly -public inline fun CharSequence.replace(regex: Regex, noinline transform: (MatchResult) -> CharSequence): String = regex.replace(this, transform) +public inline fun CharSequence.replace(regex: Regex, noinline transform: (MatchResult) -> CharSequence): String = + regex.replace(this, transform) /** * Replaces the first occurrence of the given regular expression [regex] in this char sequence with specified [replacement] expression. @@ -688,8 +688,7 @@ public inline infix fun CharSequence.matches(regex: Regex): Boolean = regex.matc * Invoked when it's already known that arguments are not Strings, so that no additional type checks are performed. */ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean): Boolean { - if ((otherOffset < 0) || (thisOffset < 0) || (thisOffset > this.length - length) - || (otherOffset > other.length - length)) { + if ((otherOffset < 0) || (thisOffset < 0) || (thisOffset > this.length - length) || (otherOffset > other.length - length)) { return false } @@ -704,13 +703,13 @@ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence * Returns `true` if this char sequence starts with the specified character. */ public fun CharSequence.startsWith(char: Char, ignoreCase: Boolean = false): Boolean = - this.length > 0 && this[0].equals(char, ignoreCase) + this.length > 0 && this[0].equals(char, ignoreCase) /** * Returns `true` if this char sequence ends with the specified character. */ public fun CharSequence.endsWith(char: Char, ignoreCase: Boolean = false): Boolean = - this.length > 0 && this[lastIndex].equals(char, ignoreCase) + this.length > 0 && this[lastIndex].equals(char, ignoreCase) /** * Returns `true` if this char sequence starts with the specified prefix. @@ -1024,7 +1023,7 @@ public operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boole */ @Suppress("INAPPLICABLE_OPERATOR_MODIFIER") public operator fun CharSequence.contains(char: Char, ignoreCase: Boolean = false): Boolean = - indexOf(char, ignoreCase = ignoreCase) >= 0 + indexOf(char, ignoreCase = ignoreCase) >= 0 /** * Returns `true` if this char sequence contains at least one match of the specified regular expression [regex]. @@ -1036,7 +1035,12 @@ public inline operator fun CharSequence.contains(regex: Regex): Boolean = regex. // rangesDelimitedBy -private class DelimitedRangesSequence(private val input: CharSequence, private val startIndex: Int, private val limit: Int, private val getNextMatch: CharSequence.(Int) -> Pair?): Sequence { +private class DelimitedRangesSequence( + private val input: CharSequence, + private val startIndex: Int, + private val limit: Int, + private val getNextMatch: CharSequence.(Int) -> Pair? +) : Sequence { override fun iterator(): Iterator = object : Iterator { var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue @@ -1049,20 +1053,17 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v if (nextSearchIndex < 0) { nextState = 0 nextItem = null - } - else { + } else { if (limit > 0 && ++counter >= limit || nextSearchIndex > input.length) { nextItem = currentStartIndex..input.lastIndex nextSearchIndex = -1 - } - else { + } else { val match = input.getNextMatch(nextSearchIndex) if (match == null) { nextItem = currentStartIndex..input.lastIndex nextSearchIndex = -1 - } - else { - val (index,length) = match + } else { + val (index, length) = match nextItem = currentStartIndex until index currentStartIndex = index + length nextSearchIndex = currentStartIndex + if (length == 0) 1 else 0 @@ -1106,7 +1107,8 @@ private fun CharSequence.rangesDelimitedBy(delimiters: CharArray, startIndex: In require(limit >= 0, { "Limit must be non-negative, but was $limit." }) return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> - indexOfAny(delimiters, startIndex, ignoreCase = ignoreCase).let { if (it < 0) null else it to 1 } }) + indexOfAny(delimiters, startIndex, ignoreCase = ignoreCase).let { if (it < 0) null else it to 1 } + }) } @@ -1147,7 +1149,7 @@ private fun CharSequence.rangesDelimitedBy(delimiters: Array, startI * that matches this string at that position. */ public fun CharSequence.splitToSequence(vararg delimiters: String, ignoreCase: Boolean = false, limit: Int = 0): Sequence = - rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) } + rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) } /** * Splits this char sequence to a list of strings around occurrences of the specified [delimiters]. @@ -1179,7 +1181,7 @@ public fun CharSequence.split(vararg delimiters: String, ignoreCase: Boolean = f * @param limit The maximum number of substrings to return. */ public fun CharSequence.splitToSequence(vararg delimiters: Char, ignoreCase: Boolean = false, limit: Int = 0): Sequence = - rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) } + rangesDelimitedBy(delimiters, ignoreCase = ignoreCase, limit = limit).map { substring(it) } /** * Splits this char sequence to a list of strings around occurrences of the specified [delimiters]. diff --git a/libraries/stdlib/src/kotlin/text/regex/MatchResult.kt b/libraries/stdlib/src/kotlin/text/regex/MatchResult.kt index b1c32cad019..c913f031ba4 100644 --- a/libraries/stdlib/src/kotlin/text/regex/MatchResult.kt +++ b/libraries/stdlib/src/kotlin/text/regex/MatchResult.kt @@ -112,6 +112,7 @@ public interface MatchResult { public operator inline fun component9(): String = match.groupValues[9] @kotlin.internal.InlineOnly public operator inline fun component10(): String = match.groupValues[10] + /** * Returns destructured group values as a list of strings. * First value in the returned list corresponds to the value of the first group, and so on. diff --git a/libraries/stdlib/src/kotlin/util/KotlinVersion.kt b/libraries/stdlib/src/kotlin/util/KotlinVersion.kt index e3d422ccd7d..52f791ab58e 100644 --- a/libraries/stdlib/src/kotlin/util/KotlinVersion.kt +++ b/libraries/stdlib/src/kotlin/util/KotlinVersion.kt @@ -48,20 +48,18 @@ public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Com * Returns `true` if this version is not less than the version specified * with the provided [major] and [minor] components. */ - public fun isAtLeast(major: Int, minor: Int): Boolean = - // or this.version >= versionOf(major, minor, 0) - this.major > major || (this.major == major && - this.minor >= minor) + public fun isAtLeast(major: Int, minor: Int): Boolean = // this.version >= versionOf(major, minor, 0) + this.major > major || (this.major == major && + this.minor >= minor) /** * Returns `true` if this version is not less than the version specified * with the provided [major], [minor] and [patch] components. */ - public fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean = - // or this.version >= versionOf(major, minor, patch) - this.major > major || (this.major == major && - (this.minor > minor || this.minor == minor && - this.patch >= patch)) + public fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean = // this.version >= versionOf(major, minor, patch) + this.major > major || (this.major == major && + (this.minor > minor || this.minor == minor && + this.patch >= patch)) companion object { /** diff --git a/libraries/stdlib/src/kotlin/util/Lazy.kt b/libraries/stdlib/src/kotlin/util/Lazy.kt index 0102bbbbd72..28d93023719 100644 --- a/libraries/stdlib/src/kotlin/util/Lazy.kt +++ b/libraries/stdlib/src/kotlin/util/Lazy.kt @@ -21,6 +21,7 @@ public interface Lazy { * Once the value was initialized it must not change during the rest of lifetime of this Lazy instance. */ public val value: T + /** * Returns `true` if a value for this Lazy instance has been already initialized, and `false` otherwise. * Once this function has returned `true` it stays `true` for the rest of lifetime of this Lazy instance. diff --git a/libraries/stdlib/src/kotlin/util/Preconditions.kt b/libraries/stdlib/src/kotlin/util/Preconditions.kt index cb4137b5146..97511d75f78 100644 --- a/libraries/stdlib/src/kotlin/util/Preconditions.kt +++ b/libraries/stdlib/src/kotlin/util/Preconditions.kt @@ -5,6 +5,7 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("PreconditionsKt") + package kotlin import kotlin.internal.contracts.* @@ -42,7 +43,7 @@ public inline fun require(value: Boolean, lazyMessage: () -> Any): Unit { * Throws an [IllegalArgumentException] if the [value] is null. Otherwise returns the not null value. */ @kotlin.internal.InlineOnly -public inline fun requireNotNull(value: T?): T { +public inline fun requireNotNull(value: T?): T { contract { returns() implies (value != null) } @@ -56,7 +57,7 @@ public inline fun requireNotNull(value: T?): T { * @sample samples.misc.Preconditions.failRequireWithLazyMessage */ @kotlin.internal.InlineOnly -public inline fun requireNotNull(value: T?, lazyMessage: () -> Any): T { +public inline fun requireNotNull(value: T?, lazyMessage: () -> Any): T { contract { returns() implies (value != null) } @@ -105,7 +106,7 @@ public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit { * @sample samples.misc.Preconditions.failCheckWithLazyMessage */ @kotlin.internal.InlineOnly -public inline fun checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null." } +public inline fun checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null." } /** * Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is null. Otherwise @@ -114,7 +115,7 @@ public inline fun checkNotNull(value: T?): T = checkNotNull(value) { "Re * @sample samples.misc.Preconditions.failCheckWithLazyMessage */ @kotlin.internal.InlineOnly -public inline fun checkNotNull(value: T?, lazyMessage: () -> Any): T { +public inline fun checkNotNull(value: T?, lazyMessage: () -> Any): T { contract { returns() implies (value != null) } diff --git a/libraries/stdlib/src/kotlin/util/Tuples.kt b/libraries/stdlib/src/kotlin/util/Tuples.kt index 92cdd9996cf..907b9ae8793 100644 --- a/libraries/stdlib/src/kotlin/util/Tuples.kt +++ b/libraries/stdlib/src/kotlin/util/Tuples.kt @@ -4,6 +4,7 @@ */ @file:kotlin.jvm.JvmName("TuplesKt") + package kotlin @@ -23,9 +24,9 @@ package kotlin * @constructor Creates a new instance of Pair. */ public data class Pair( - public val first: A, - public val second: B - ) : Serializable { + public val first: A, + public val second: B +) : Serializable { /** * Returns string representation of the [Pair] including its [first] and [second] values. @@ -62,10 +63,10 @@ public fun Pair.toList(): List = listOf(first, second) * @property third Third value. */ public data class Triple( - public val first: A, - public val second: B, - public val third: C - ) : Serializable { + public val first: A, + public val second: B, + public val third: C +) : Serializable { /** * Returns string representation of the [Triple] including its [first], [second] and [third] values.