From e3883d8d6ddd609e8c0d2ae9af9ab6fb1059dd36 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 20 Apr 2018 23:33:11 +0300 Subject: [PATCH] Reformat stdlib: jvm part #KT-5558 --- .../src/kotlin/collections/Collections.kt | 9 +- .../jdk8/JDK8PlatformImplementations.kt | 2 +- .../stdlib/jdk8/src/kotlin/streams/Streams.kt | 3 +- .../jdk8/src/kotlin/text/RegexExtensions.kt | 4 +- .../jdk8/test/collections/CollectionTest.kt | 8 +- .../jdk8/test/collections/StreamsTest.kt | 8 +- .../stdlib/jvm/runtime/kotlin/Metadata.kt | 98 +++++++++---------- .../jvm/runtime/kotlin/jvm/JvmClassMapping.kt | 6 +- .../kotlin/jvm/internal/ClassReference.kt | 6 +- .../kotlin/jvm/internal/PackageReference.kt | 10 +- .../jvm/internal/PrimitiveCompanionObjects.kt | 12 +-- .../jvm/src/kotlin/concurrent/Thread.kt | 12 ++- .../experimental/SafeContinuationJvm.kt | 9 +- .../experimental/intrinsics/IntrinsicsJvm.kt | 70 ++++++------- .../jvm/internal/CoroutineImpl.kt | 6 +- .../jvm/internal/CoroutineIntrinsics.kt | 7 +- .../internal/PlatformImplementations.kt | 14 +-- .../stdlib/jvm/src/kotlin/io/Constants.kt | 3 +- .../stdlib/jvm/src/kotlin/io/Exceptions.kt | 31 +++--- .../stdlib/jvm/src/kotlin/io/FileReadWrite.kt | 18 ++-- .../stdlib/jvm/src/kotlin/io/IOStreams.kt | 59 +++++------ .../stdlib/jvm/src/kotlin/io/ReadWrite.kt | 11 ++- .../src/kotlin/io/files/FilePathComponents.kt | 5 +- .../jvm/src/kotlin/io/files/FileTreeWalk.kt | 19 ++-- .../stdlib/jvm/src/kotlin/io/files/Utils.kt | 43 ++++---- .../src/kotlin/jvm/internal/unsafe/monitor.kt | 6 +- .../stdlib/jvm/src/kotlin/ranges/RangesJVM.kt | 6 +- .../stdlib/jvm/src/kotlin/system/Timing.kt | 4 +- .../stdlib/jvm/src/kotlin/text/CharJVM.kt | 2 +- .../kotlin/text/StringNumberConversionsJVM.kt | 2 +- .../stdlib/jvm/src/kotlin/text/StringsJVM.kt | 59 ++++++----- .../stdlib/jvm/src/kotlin/text/regex/Regex.kt | 32 +++--- .../jvm/src/kotlin/util/AssertionsJVM.kt | 3 +- .../stdlib/jvm/src/kotlin/util/BigIntegers.kt | 2 +- .../stdlib/jvm/src/kotlin/util/LazyJVM.kt | 6 +- .../stdlib/jvm/src/kotlin/util/MathJVM.kt | 13 ++- 36 files changed, 337 insertions(+), 271 deletions(-) diff --git a/libraries/stdlib/jdk8/src/kotlin/collections/Collections.kt b/libraries/stdlib/jdk8/src/kotlin/collections/Collections.kt index f67aa631c6b..c393a3f8194 100644 --- a/libraries/stdlib/jdk8/src/kotlin/collections/Collections.kt +++ b/libraries/stdlib/jdk8/src/kotlin/collections/Collections.kt @@ -17,6 +17,7 @@ @file:Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @file:JvmName("CollectionsJDK8Kt") @file:kotlin.jvm.JvmPackageName("kotlin.collections.jdk8") + package kotlin.collections /** @@ -25,8 +26,8 @@ package kotlin.collections */ @SinceKotlin("1.2") @kotlin.internal.InlineOnly -public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map.getOrDefault(key: K, defaultValue: V): V - = (this as Map).getOrDefault(key, defaultValue) +public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map.getOrDefault(key: K, defaultValue: V): V = + (this as Map).getOrDefault(key, defaultValue) /** @@ -35,5 +36,5 @@ public inline fun <@kotlin.internal.OnlyInputTypes K, V> Map.getOrDefa */ @SinceKotlin("1.2") @kotlin.internal.InlineOnly -public inline fun <@kotlin.internal.OnlyInputTypes K, @kotlin.internal.OnlyInputTypes V> MutableMap.remove(key: K, value: V): Boolean - = (this as MutableMap).remove(key, value) +public inline fun <@kotlin.internal.OnlyInputTypes K, @kotlin.internal.OnlyInputTypes V> MutableMap.remove(key: K, value: V): Boolean = + (this as MutableMap).remove(key, value) diff --git a/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt b/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt index e8f0b59ff5c..25f14adbd2d 100644 --- a/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt +++ b/libraries/stdlib/jdk8/src/kotlin/internal/jdk8/JDK8PlatformImplementations.kt @@ -27,7 +27,7 @@ internal open class JDK8PlatformImplementations : JDK7PlatformImplementations() override fun getMatchResultNamedGroup(matchResult: MatchResult, name: String): MatchGroup? { val matcher = matchResult as? Matcher ?: throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.") - val range = matcher.start(name)..matcher.end(name)-1 + val range = matcher.start(name)..matcher.end(name) - 1 return if (range.start >= 0) MatchGroup(matcher.group(name), range) else diff --git a/libraries/stdlib/jdk8/src/kotlin/streams/Streams.kt b/libraries/stdlib/jdk8/src/kotlin/streams/Streams.kt index 4c7cda20474..4402d5f55a8 100644 --- a/libraries/stdlib/jdk8/src/kotlin/streams/Streams.kt +++ b/libraries/stdlib/jdk8/src/kotlin/streams/Streams.kt @@ -50,7 +50,8 @@ public fun DoubleStream.asSequence(): Sequence = Sequence { iterator() } * Creates a sequential [Stream] instance that produces elements from the original sequence. */ @SinceKotlin("1.2") -public fun Sequence.asStream(): Stream = StreamSupport.stream({ Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED) }, Spliterator.ORDERED, false) +public fun Sequence.asStream(): Stream = + StreamSupport.stream({ Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED) }, Spliterator.ORDERED, false) /** * Returns a [List] containing all elements produced by this stream. diff --git a/libraries/stdlib/jdk8/src/kotlin/text/RegexExtensions.kt b/libraries/stdlib/jdk8/src/kotlin/text/RegexExtensions.kt index b88f240f59d..133bbf7e08c 100644 --- a/libraries/stdlib/jdk8/src/kotlin/text/RegexExtensions.kt +++ b/libraries/stdlib/jdk8/src/kotlin/text/RegexExtensions.kt @@ -27,8 +27,8 @@ package kotlin.text */ @SinceKotlin("1.2") public operator fun MatchGroupCollection.get(name: String): MatchGroup? { - val namedGroups = this as? MatchNamedGroupCollection ?: - throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.") + val namedGroups = this as? MatchNamedGroupCollection + ?: throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.") return namedGroups[name] } diff --git a/libraries/stdlib/jdk8/test/collections/CollectionTest.kt b/libraries/stdlib/jdk8/test/collections/CollectionTest.kt index ef79925ef4c..6796ce4813f 100644 --- a/libraries/stdlib/jdk8/test/collections/CollectionTest.kt +++ b/libraries/stdlib/jdk8/test/collections/CollectionTest.kt @@ -28,10 +28,10 @@ class CollectionTest { @Test fun stream() { assertEquals( - data.flatMap { it.asIterable() }, - data.stream() - .flatMap { it.chars().boxed().map { it.toChar() } } - .collect(Collectors.toList())) + data.flatMap { it.asIterable() }, + data.stream() + .flatMap { it.chars().boxed().map { it.toChar() } } + .collect(Collectors.toList())) assertEquals(data, data.parallelStream().toList()) } diff --git a/libraries/stdlib/jdk8/test/collections/StreamsTest.kt b/libraries/stdlib/jdk8/test/collections/StreamsTest.kt index 86a122e9151..8a192299f41 100644 --- a/libraries/stdlib/jdk8/test/collections/StreamsTest.kt +++ b/libraries/stdlib/jdk8/test/collections/StreamsTest.kt @@ -39,13 +39,13 @@ class StreamsTest { fun assertSequenceContent(expected: List, actual: Sequence) { assertEquals(expected, actual.toList()) - assertFailsWith ("Second iteration fails") { actual.toList() } + assertFailsWith("Second iteration fails") { actual.toList() } } - assertSequenceContent(data.asList(), Stream.of(*data).asSequence()) - assertSequenceContent(listOf(1, 2), IntStream.of(1, 2).asSequence()) - assertSequenceContent(listOf(1L, 2L), LongStream.of(1L, 2L).asSequence()) + assertSequenceContent(data.asList(), Stream.of(*data).asSequence()) + assertSequenceContent(listOf(1, 2), IntStream.of(1, 2).asSequence()) + assertSequenceContent(listOf(1L, 2L), LongStream.of(1L, 2L).asSequence()) assertSequenceContent(listOf(1.0, 2.0), DoubleStream.of(1.0, 2.0).asSequence()) } diff --git a/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt b/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt index 7a7eb5ff8fd..bc2e895ac60 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt @@ -12,53 +12,53 @@ package kotlin @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.CLASS) internal annotation class Metadata( - /** - * A kind of the metadata this annotation encodes. Kotlin compiler recognizes the following kinds (see KotlinClassHeader.Kind): - * - * 1 Class - * 2 File - * 3 Synthetic class - * 4 Multi-file class facade - * 5 Multi-file class part - * - * The class file with a kind not listed here is treated as a non-Kotlin file. - */ - val k: Int = 1, - /** - * The version of the metadata provided in the arguments of this annotation. - */ - val mv: IntArray = intArrayOf(), - /** - * The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation. - */ - val bv: IntArray = intArrayOf(), - /** - * Metadata in a custom format. The format may be different (or even absent) for different kinds. - */ - val d1: Array = arrayOf(), - /** - * An addition to [d1]: array of strings which occur in metadata, written in plain text so that strings already present - * in the constant pool are reused. These strings may be then indexed in the metadata by an integer index in this array. - */ - val d2: Array = arrayOf(), - /** - * An extra string. For a multi-file part class, internal name of the facade class. - */ - val xs: String = "", - /** - * Fully qualified name of the package this class is located in, from Kotlin's point of view, or empty string if this name - * does not differ from the JVM's package FQ name. These names can be different in case the [JvmPackageName] annotation is used. - * Note that this information is also stored in the corresponding module's `.kotlin_module` file. - */ - @SinceKotlin("1.2") - val pn: String = "", - /** - * An extra int. Bits of this number represent the following flags: - * - * 0 - this is a multi-file class facade or part, compiled with `-Xmultifile-parts-inherit`. - * 1 - this class file is compiled by a pre-release version of Kotlin and is not visible to release versions. - * 2 - this class file is a compiled Kotlin script source file (.kts). - */ - @SinceKotlin("1.1") - val xi: Int = 0 + /** + * A kind of the metadata this annotation encodes. Kotlin compiler recognizes the following kinds (see KotlinClassHeader.Kind): + * + * 1 Class + * 2 File + * 3 Synthetic class + * 4 Multi-file class facade + * 5 Multi-file class part + * + * The class file with a kind not listed here is treated as a non-Kotlin file. + */ + val k: Int = 1, + /** + * The version of the metadata provided in the arguments of this annotation. + */ + val mv: IntArray = intArrayOf(), + /** + * The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation. + */ + val bv: IntArray = intArrayOf(), + /** + * Metadata in a custom format. The format may be different (or even absent) for different kinds. + */ + val d1: Array = arrayOf(), + /** + * An addition to [d1]: array of strings which occur in metadata, written in plain text so that strings already present + * in the constant pool are reused. These strings may be then indexed in the metadata by an integer index in this array. + */ + val d2: Array = arrayOf(), + /** + * An extra string. For a multi-file part class, internal name of the facade class. + */ + val xs: String = "", + /** + * Fully qualified name of the package this class is located in, from Kotlin's point of view, or empty string if this name + * does not differ from the JVM's package FQ name. These names can be different in case the [JvmPackageName] annotation is used. + * Note that this information is also stored in the corresponding module's `.kotlin_module` file. + */ + @SinceKotlin("1.2") + val pn: String = "", + /** + * An extra int. Bits of this number represent the following flags: + * + * 0 - this is a multi-file class facade or part, compiled with `-Xmultifile-parts-inherit`. + * 1 - this class file is compiled by a pre-release version of Kotlin and is not visible to release versions. + * 2 - this class file is a compiled Kotlin script source file (.kts). + */ + @SinceKotlin("1.1") + val xi: Int = 0 ) diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/JvmClassMapping.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/JvmClassMapping.kt index 960c76f5765..caf23eec414 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/JvmClassMapping.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/JvmClassMapping.kt @@ -83,12 +83,12 @@ public val Class.kotlin: KClass /** * Returns the runtime Java class of this object. */ -public inline val T.javaClass : Class +public inline val T.javaClass: Class @Suppress("UsePropertyAccessSyntax") get() = (this as java.lang.Object).getClass() as Class @Deprecated("Use 'java' property to get Java class corresponding to this Kotlin class or cast this instance to Any if you really want to get the runtime Java class of this implementation of KClass.", ReplaceWith("(this as Any).javaClass"), level = DeprecationLevel.ERROR) -public inline val KClass.javaClass: Class> +public inline val KClass.javaClass: Class> @JvmName("getRuntimeClassOfKClassInstance") @Suppress("UsePropertyAccessSyntax") get() = (this as java.lang.Object).getClass() as Class> @@ -98,7 +98,7 @@ public inline val KClass.javaClass: Class> */ @Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") public fun Array<*>.isArrayOf(): Boolean = - T::class.java.isAssignableFrom(this::class.java.componentType) + T::class.java.isAssignableFrom(this::class.java.componentType) /** * Returns a [KClass] instance corresponding to the annotation type of this annotation. diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ClassReference.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ClassReference.kt index 247fa776ad5..fd9db187426 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ClassReference.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ClassReference.kt @@ -75,11 +75,11 @@ public class ClassReference(override val jClass: Class<*>) : KClass, ClassB private fun error(): Nothing = throw KotlinReflectionNotSupportedError() override fun equals(other: Any?) = - other is ClassReference && javaObjectType == other.javaObjectType + other is ClassReference && javaObjectType == other.javaObjectType override fun hashCode() = - javaObjectType.hashCode() + javaObjectType.hashCode() override fun toString() = - jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE + jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE } diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PackageReference.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PackageReference.kt index a1a068f3c97..93f4bb03a3d 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PackageReference.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PackageReference.kt @@ -9,18 +9,18 @@ import kotlin.reflect.KCallable @SinceKotlin("1.1") public class PackageReference( - override val jClass: Class<*>, - @Suppress("unused") private val moduleName: String + override val jClass: Class<*>, + @Suppress("unused") private val moduleName: String ) : ClassBasedDeclarationContainer { override val members: Collection> get() = throw KotlinReflectionNotSupportedError() override fun equals(other: Any?) = - other is PackageReference && jClass == other.jClass + other is PackageReference && jClass == other.jClass override fun hashCode() = - jClass.hashCode() + jClass.hashCode() override fun toString() = - jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE + jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE } diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt index 8b6878124a4..1fc1352c3a5 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt @@ -8,17 +8,17 @@ package kotlin.jvm.internal internal object DoubleCompanionObject { val MIN_VALUE: Double = java.lang.Double.MIN_VALUE val MAX_VALUE: Double = java.lang.Double.MAX_VALUE - val POSITIVE_INFINITY : Double = java.lang.Double.POSITIVE_INFINITY - val NEGATIVE_INFINITY : Double = java.lang.Double.NEGATIVE_INFINITY - val NaN : Double = java.lang.Double.NaN + val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY + val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY + val NaN: Double = java.lang.Double.NaN } internal object FloatCompanionObject { val MIN_VALUE: Float = java.lang.Float.MIN_VALUE val MAX_VALUE: Float = java.lang.Float.MAX_VALUE - val POSITIVE_INFINITY : Float = java.lang.Float.POSITIVE_INFINITY - val NEGATIVE_INFINITY : Float = java.lang.Float.NEGATIVE_INFINITY - val NaN : Float = java.lang.Float.NaN + val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY + val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY + val NaN: Float = java.lang.Float.NaN } internal object IntCompanionObject { diff --git a/libraries/stdlib/jvm/src/kotlin/concurrent/Thread.kt b/libraries/stdlib/jvm/src/kotlin/concurrent/Thread.kt index 3cafe7eb94d..dc6d24b3cb6 100644 --- a/libraries/stdlib/jvm/src/kotlin/concurrent/Thread.kt +++ b/libraries/stdlib/jvm/src/kotlin/concurrent/Thread.kt @@ -4,6 +4,7 @@ */ @file:JvmName("ThreadsKt") + package kotlin.concurrent /** @@ -16,7 +17,14 @@ package kotlin.concurrent * @param name the name of the thread. * @param priority the priority of the thread. */ -public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread { +public fun thread( + start: Boolean = true, + isDaemon: Boolean = false, + contextClassLoader: ClassLoader? = null, + name: String? = null, + priority: Int = -1, + block: () -> Unit +): Thread { val thread = object : Thread() { public override fun run() { block() @@ -47,6 +55,6 @@ public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClass * is stored for the current thread and then returned. */ @kotlin.internal.InlineOnly -public inline fun ThreadLocal.getOrSet(default: () -> T): T { +public inline fun ThreadLocal.getOrSet(default: () -> T): T { return get() ?: default().also(this::set) } diff --git a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/SafeContinuationJvm.kt b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/SafeContinuationJvm.kt index 8f326cce248..c1d0c7f458a 100644 --- a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/SafeContinuationJvm.kt +++ b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/SafeContinuationJvm.kt @@ -11,8 +11,8 @@ import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED @PublishedApi internal actual class SafeContinuation internal actual constructor( - private val delegate: Continuation, - initialResult: Any? + private val delegate: Continuation, + initialResult: Any? ) : Continuation { @PublishedApi @@ -31,7 +31,8 @@ internal actual constructor( @Suppress("UNCHECKED_CAST") @JvmStatic private val RESULT = AtomicReferenceFieldUpdater.newUpdater, Any?>( - SafeContinuation::class.java, Any::class.java as Class, "result") + SafeContinuation::class.java, Any::class.java as Class, "result" + ) } private class Fail(val exception: Throwable) @@ -53,7 +54,7 @@ internal actual constructor( actual override fun resumeWithException(exception: Throwable) { while (true) { // lock-free loop val result = this.result // atomic read - when { + when { result === UNDECIDED -> if (RESULT.compareAndSet(this, UNDECIDED, Fail(exception))) return result === COROUTINE_SUSPENDED -> if (RESULT.compareAndSet(this, COROUTINE_SUSPENDED, RESUMED)) { delegate.resumeWithException(exception) diff --git a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/intrinsics/IntrinsicsJvm.kt b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/intrinsics/IntrinsicsJvm.kt index 2d9a07ae889..63e426927bd 100644 --- a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/intrinsics/IntrinsicsJvm.kt +++ b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/intrinsics/IntrinsicsJvm.kt @@ -5,7 +5,9 @@ @file:kotlin.jvm.JvmName("IntrinsicsKt") @file:kotlin.jvm.JvmMultifileClass + package kotlin.coroutines.experimental.intrinsics + import kotlin.coroutines.experimental.* /** @@ -19,7 +21,7 @@ import kotlin.coroutines.experimental.* @Suppress("UNCHECKED_CAST") @kotlin.internal.InlineOnly public actual inline fun (suspend () -> T).startCoroutineUninterceptedOrReturn( - completion: Continuation + completion: Continuation ): Any? = (this as Function1, Any?>).invoke(completion) /** @@ -33,8 +35,8 @@ public actual inline fun (suspend () -> T).startCoroutineUninterceptedOrRetu @Suppress("UNCHECKED_CAST") @kotlin.internal.InlineOnly public actual inline fun (suspend R.() -> T).startCoroutineUninterceptedOrReturn( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ): Any? = (this as Function2, Any?>).invoke(receiver, completion) @@ -52,15 +54,15 @@ public actual inline fun (suspend R.() -> T).startCoroutineUninterceptedO */ @SinceKotlin("1.1") public actual fun (suspend () -> T).createCoroutineUnchecked( - completion: Continuation + completion: Continuation ): Continuation = - if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl) - buildContinuationByInvokeCall(completion) { - @Suppress("UNCHECKED_CAST") - (this as Function1, Any?>).invoke(completion) - } - else - (this.create(completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade + if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl) + buildContinuationByInvokeCall(completion) { + @Suppress("UNCHECKED_CAST") + (this as Function1, Any?>).invoke(completion) + } + else + (this.create(completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade /** * Creates a coroutine with receiver type [R] and result type [T]. @@ -74,36 +76,36 @@ public actual fun (suspend () -> T).createCoroutineUnchecked( */ @SinceKotlin("1.1") public actual fun (suspend R.() -> T).createCoroutineUnchecked( - receiver: R, - completion: Continuation + receiver: R, + completion: Continuation ): Continuation = - if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl) - buildContinuationByInvokeCall(completion) { - @Suppress("UNCHECKED_CAST") - (this as Function2, Any?>).invoke(receiver, completion) - } - else - (this.create(receiver, completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade + if (this !is kotlin.coroutines.experimental.jvm.internal.CoroutineImpl) + buildContinuationByInvokeCall(completion) { + @Suppress("UNCHECKED_CAST") + (this as Function2, Any?>).invoke(receiver, completion) + } + else + (this.create(receiver, completion) as kotlin.coroutines.experimental.jvm.internal.CoroutineImpl).facade // INTERNAL DEFINITIONS private inline fun buildContinuationByInvokeCall( - completion: Continuation, - crossinline block: () -> Any? + completion: Continuation, + crossinline block: () -> Any? ): Continuation { - val continuation = - object : Continuation { - override val context: CoroutineContext - get() = completion.context + val continuation = + object : Continuation { + override val context: CoroutineContext + get() = completion.context - override fun resume(value: Unit) { - processBareContinuationResume(completion, block) - } + override fun resume(value: Unit) { + processBareContinuationResume(completion, block) + } - override fun resumeWithException(exception: Throwable) { - completion.resumeWithException(exception) - } - } + override fun resumeWithException(exception: Throwable) { + completion.resumeWithException(exception) + } + } - return kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded(completion.context, continuation) + return kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded(completion.context, continuation) } diff --git a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt index 7e8aa48ecd8..22140358274 100644 --- a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt +++ b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt @@ -15,9 +15,9 @@ import kotlin.jvm.internal.Lambda * @suppress */ abstract class CoroutineImpl( - arity: Int, - @JvmField - protected var completion: Continuation? + arity: Int, + @JvmField + protected var completion: Continuation? ) : Lambda(arity), Continuation { // label == -1 when coroutine cannot be started (it is just a factory object) or has already finished execution diff --git a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt index b5a5180f052..37fcb0dceb0 100644 --- a/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt +++ b/libraries/stdlib/jvm/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt @@ -4,6 +4,7 @@ */ @file:JvmName("CoroutineIntrinsics") + package kotlin.coroutines.experimental.jvm.internal import kotlin.coroutines.experimental.Continuation @@ -14,9 +15,9 @@ import kotlin.coroutines.experimental.CoroutineContext * @suppress */ fun normalizeContinuation(continuation: Continuation): Continuation = - (continuation as? CoroutineImpl)?.facade ?: continuation + (continuation as? CoroutineImpl)?.facade ?: continuation internal fun interceptContinuationIfNeeded( - context: CoroutineContext, - continuation: Continuation + context: CoroutineContext, + continuation: Continuation ) = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation diff --git a/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt b/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt index 5a06fccc374..4e180e040bd 100644 --- a/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt +++ b/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt @@ -26,23 +26,19 @@ internal val IMPLEMENTATIONS: PlatformImplementations = run { if (version >= 0x10008) { try { return@run Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance() as PlatformImplementations - } - catch (e: ClassNotFoundException) { } + } catch (e: ClassNotFoundException) { } try { return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations - } - catch (e: ClassNotFoundException) { } + } catch (e: ClassNotFoundException) { } } if (version >= 0x10007) { try { return@run Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance() as PlatformImplementations - } - catch (e: ClassNotFoundException) { } + } catch (e: ClassNotFoundException) { } try { return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations - } - catch (e: ClassNotFoundException) { } + } catch (e: ClassNotFoundException) { } } PlatformImplementations() @@ -78,4 +74,4 @@ private fun getJavaVersion(): Int { @PublishedApi @SinceKotlin("1.2") internal fun apiVersionIsAtLeast(major: Int, minor: Int, patch: Int) = - KotlinVersion.CURRENT.isAtLeast(major, minor, patch) \ No newline at end of file + KotlinVersion.CURRENT.isAtLeast(major, minor, patch) \ No newline at end of file diff --git a/libraries/stdlib/jvm/src/kotlin/io/Constants.kt b/libraries/stdlib/jvm/src/kotlin/io/Constants.kt index 94e2f60a5ad..b220c76220e 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/Constants.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/Constants.kt @@ -4,11 +4,12 @@ */ @file:JvmName("ConstantsKt") + package kotlin.io /** * Returns the default buffer size when working with buffered streams. -*/ + */ public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024 /** diff --git a/libraries/stdlib/jvm/src/kotlin/io/Exceptions.kt b/libraries/stdlib/jvm/src/kotlin/io/Exceptions.kt index c205788d1b3..4c41428db06 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/Exceptions.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/Exceptions.kt @@ -26,29 +26,36 @@ private fun constructMessage(file: File, other: File?, reason: String?): String * @property other the second file involved in the operation, if any (for example, the target of a copy or move) * @property reason the description of the error */ -open public class FileSystemException(public val file: File, - public val other: File? = null, - public val reason: String? = null +open public class FileSystemException( + public val file: File, + public val other: File? = null, + public val reason: String? = null ) : IOException(constructMessage(file, other, reason)) /** * An exception class which is used when some file to create or copy to already exists. */ -public class FileAlreadyExistsException(file: File, - other: File? = null, - reason: String? = null) : FileSystemException(file, other, reason) +public class FileAlreadyExistsException( + file: File, + other: File? = null, + reason: String? = null +) : FileSystemException(file, other, reason) /** * An exception class which is used when we have not enough access for some operation. */ -public class AccessDeniedException(file: File, - other: File? = null, - reason: String? = null) : FileSystemException(file, other, reason) +public class AccessDeniedException( + file: File, + other: File? = null, + reason: String? = null +) : FileSystemException(file, other, reason) /** * An exception class which is used when file to copy does not exist. */ -public class NoSuchFileException(file: File, - other: File? = null, - reason: String? = null) : FileSystemException(file, other, reason) +public class NoSuchFileException( + file: File, + other: File? = null, + reason: String? = null +) : FileSystemException(file, other, reason) diff --git a/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt b/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt index f04dd1b2de1..03f3ae4086f 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/FileReadWrite.kt @@ -5,6 +5,7 @@ @file:JvmMultifileClass @file:JvmName("FilesKt") + package kotlin.io import java.io.* @@ -17,7 +18,8 @@ import kotlin.internal.* * Returns a new [FileReader] for reading the content of this file. */ @kotlin.internal.InlineOnly -public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamReader = inputStream().reader(charset) +public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamReader = + inputStream().reader(charset) /** * Returns a new [BufferedReader] for reading the content of this file. @@ -25,13 +27,15 @@ public inline fun File.reader(charset: Charset = Charsets.UTF_8): InputStreamRea * @param bufferSize necessary size of the buffer. */ @kotlin.internal.InlineOnly -public inline fun File.bufferedReader(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader = reader(charset).buffered(bufferSize) +public inline fun File.bufferedReader(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader = + reader(charset).buffered(bufferSize) /** * Returns a new [FileWriter] for writing the content of this file. */ @kotlin.internal.InlineOnly -public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWriter = outputStream().writer(charset) +public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWriter = + outputStream().writer(charset) /** * Returns a new [BufferedWriter] for writing the content of this file. @@ -39,13 +43,15 @@ public inline fun File.writer(charset: Charset = Charsets.UTF_8): OutputStreamWr * @param bufferSize necessary size of the buffer. */ @kotlin.internal.InlineOnly -public inline fun File.bufferedWriter(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter = writer(charset).buffered(bufferSize) +public inline fun File.bufferedWriter(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter = + writer(charset).buffered(bufferSize) /** * Returns a new [PrintWriter] for writing the content of this file. */ @kotlin.internal.InlineOnly -public inline fun File.printWriter(charset: Charset = Charsets.UTF_8): PrintWriter = PrintWriter(bufferedWriter(charset)) +public inline fun File.printWriter(charset: Charset = Charsets.UTF_8): PrintWriter = + PrintWriter(bufferedWriter(charset)) /** * Gets the entire content of this file as a byte array. @@ -199,4 +205,4 @@ public fun File.readLines(charset: Charset = Charsets.UTF_8): List { */ @RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.") public inline fun File.useLines(charset: Charset = Charsets.UTF_8, block: (Sequence) -> T): T = - bufferedReader(charset).use { block(it.lineSequence()) } + bufferedReader(charset).use { block(it.lineSequence()) } diff --git a/libraries/stdlib/jvm/src/kotlin/io/IOStreams.kt b/libraries/stdlib/jvm/src/kotlin/io/IOStreams.kt index f84f06063d3..b69b567cf41 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/IOStreams.kt @@ -4,6 +4,7 @@ */ @file:JvmName("ByteStreamsKt") + package kotlin.io import java.io.* @@ -12,37 +13,37 @@ import java.util.NoSuchElementException /** Returns an [Iterator] of bytes read from this input stream. */ public operator fun BufferedInputStream.iterator(): ByteIterator = - object : ByteIterator() { + object : ByteIterator() { - var nextByte = -1 + var nextByte = -1 - var nextPrepared = false + var nextPrepared = false - var finished = false + var finished = false - private fun prepareNext() { - if (!nextPrepared && !finished) { - nextByte = read() - nextPrepared = true - finished = (nextByte == -1) - } - } - - public override fun hasNext(): Boolean { - prepareNext() - return !finished - } - - public override fun nextByte(): Byte { - prepareNext() - if (finished) - throw NoSuchElementException("Input stream is over.") - val res = nextByte.toByte() - nextPrepared = false - return res + private fun prepareNext() { + if (!nextPrepared && !finished) { + nextByte = read() + nextPrepared = true + finished = (nextByte == -1) } } + public override fun hasNext(): Boolean { + prepareNext() + return !finished + } + + public override fun nextByte(): Byte { + prepareNext() + if (finished) + throw NoSuchElementException("Input stream is over.") + val res = nextByte.toByte() + nextPrepared = false + return res + } + } + /** Creates a new byte input stream for the string. */ @kotlin.internal.InlineOnly @@ -60,15 +61,15 @@ public inline fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInput * @param length the length of the portion of the array to read. */ @kotlin.internal.InlineOnly -public inline fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStream = ByteArrayInputStream(this, offset, length) +public inline fun ByteArray.inputStream(offset: Int, length: Int): ByteArrayInputStream = ByteArrayInputStream(this, offset, length) /** * Creates a buffered input stream wrapping this stream. * @param bufferSize the buffer size to use. */ @kotlin.internal.InlineOnly -public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream - = if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize) +public inline fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream = + if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize) /** Creates a reader on this input stream using UTF-8 or the specified [charset]. */ @kotlin.internal.InlineOnly @@ -83,8 +84,8 @@ public inline fun InputStream.bufferedReader(charset: Charset = Charsets.UTF_8): * @param bufferSize the buffer size to use. */ @kotlin.internal.InlineOnly -public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream - = if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize) +public inline fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream = + if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize) /** Creates a writer on this output stream using UTF-8 or the specified [charset]. */ @kotlin.internal.InlineOnly diff --git a/libraries/stdlib/jvm/src/kotlin/io/ReadWrite.kt b/libraries/stdlib/jvm/src/kotlin/io/ReadWrite.kt index 03a1d485402..3986ecedc9d 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/ReadWrite.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/ReadWrite.kt @@ -4,6 +4,7 @@ */ @file:JvmName("TextStreamsKt") + package kotlin.io import java.io.* @@ -15,13 +16,13 @@ import kotlin.internal.* /** Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered. */ @kotlin.internal.InlineOnly -public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader - = if (this is BufferedReader) this else BufferedReader(this, bufferSize) +public inline fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader = + if (this is BufferedReader) this else BufferedReader(this, bufferSize) /** Returns a buffered reader wrapping this Writer, or this Writer itself if it is already buffered. */ @kotlin.internal.InlineOnly -public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter - = if (this is BufferedWriter) this else BufferedWriter(this, bufferSize) +public inline fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter = + if (this is BufferedWriter) this else BufferedWriter(this, bufferSize) /** * Iterates through each line of this reader, calls [action] for each line read @@ -49,7 +50,7 @@ public fun Reader.readLines(): List { */ @RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.") public inline fun Reader.useLines(block: (Sequence) -> T): T = - buffered().use { block(it.lineSequence()) } + buffered().use { block(it.lineSequence()) } /** Creates a new reader for the string. */ @kotlin.internal.InlineOnly diff --git a/libraries/stdlib/jvm/src/kotlin/io/files/FilePathComponents.kt b/libraries/stdlib/jvm/src/kotlin/io/files/FilePathComponents.kt index 1e8bb2cb3f4..91494259adc 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/files/FilePathComponents.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/files/FilePathComponents.kt @@ -5,6 +5,7 @@ @file:JvmMultifileClass @file:JvmName("FilesKt") + package kotlin.io import java.io.File @@ -141,7 +142,7 @@ internal fun File.toComponents(): FilePathComponents { * Number 0 belongs to a component closest to the root, * number count-1 belongs to a component farthest from the root. * @throws IllegalArgumentException if [beginIndex] is negative, -* or [endIndex] is greater than existing number of components, -* or [beginIndex] is greater than [endIndex]. + * or [endIndex] is greater than existing number of components, + * or [beginIndex] is greater than [endIndex]. */ internal fun File.subPath(beginIndex: Int, endIndex: Int): File = toComponents().subPath(beginIndex, endIndex) diff --git a/libraries/stdlib/jvm/src/kotlin/io/files/FileTreeWalk.kt b/libraries/stdlib/jvm/src/kotlin/io/files/FileTreeWalk.kt index acd197e58d9..82cf6547a3c 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/files/FileTreeWalk.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/files/FileTreeWalk.kt @@ -5,6 +5,7 @@ @file:JvmMultifileClass @file:JvmName("FilesKt") + package kotlin.io import kotlin.* @@ -35,15 +36,15 @@ public enum class FileWalkDirection { * If the file path given does not exist, walker iterates nothing, i.e. it's equivalent to an empty sequence. */ public class FileTreeWalk private constructor( - private val start: File, - private val direction: FileWalkDirection = FileWalkDirection.TOP_DOWN, - private val onEnter: ((File) -> Boolean)?, - private val onLeave: ((File) -> Unit)?, - private val onFail: ((f: File, e: IOException) -> Unit)?, - private val maxDepth: Int = Int.MAX_VALUE + private val start: File, + private val direction: FileWalkDirection = FileWalkDirection.TOP_DOWN, + private val onEnter: ((File) -> Boolean)?, + private val onLeave: ((File) -> Unit)?, + private val onFail: ((f: File, e: IOException) -> Unit)?, + private val maxDepth: Int = Int.MAX_VALUE ) : Sequence { - internal constructor(start: File, direction: FileWalkDirection = FileWalkDirection.TOP_DOWN): this(start, direction, null, null, null) + internal constructor(start: File, direction: FileWalkDirection = FileWalkDirection.TOP_DOWN) : this(start, direction, null, null, null) /** Returns an iterator walking through files. */ @@ -56,7 +57,7 @@ public class FileTreeWalk private constructor( } /** Abstract class that encapsulates directory visiting in some order, beginning from a given [rootDir] */ - private abstract class DirectoryState(rootDir: File): WalkState(rootDir) { + private abstract class DirectoryState(rootDir: File) : WalkState(rootDir) { init { if (_Assertions.ENABLED) assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." } @@ -265,7 +266,7 @@ public class FileTreeWalk private constructor( * @param direction walk direction, top-down (by default) or bottom-up. */ public fun File.walk(direction: FileWalkDirection = FileWalkDirection.TOP_DOWN): FileTreeWalk = - FileTreeWalk(this, direction) + FileTreeWalk(this, direction) /** * Gets a sequence for visiting this directory and all its content in top-down order. diff --git a/libraries/stdlib/jvm/src/kotlin/io/files/Utils.kt b/libraries/stdlib/jvm/src/kotlin/io/files/Utils.kt index 40aaec6637b..4d3dbe8499d 100644 --- a/libraries/stdlib/jvm/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/jvm/src/kotlin/io/files/Utils.kt @@ -5,6 +5,7 @@ @file:JvmMultifileClass @file:JvmName("FilesKt") + package kotlin.io import java.io.* @@ -21,7 +22,7 @@ import kotlin.comparisons.* * If [directory] is not specified then the default temporary-file directory will be used. * * @return a file object corresponding to a newly-created directory. -* + * * @throws IOException in case of input/output error. * @throws IllegalArgumentException if [prefix] is shorter than three symbols. */ @@ -43,7 +44,7 @@ public fun createTempDir(prefix: String = "tmp", suffix: String? = null, directo * If [directory] is not specified then the default temporary-file directory will be used. * * @return a file object corresponding to a newly-created file. -* + * * @throws IOException in case of input/output error. * @throws IllegalArgumentException if [prefix] is shorter than three symbols. */ @@ -79,8 +80,8 @@ public val File.nameWithoutExtension: String * * @throws IllegalArgumentException if this and base paths have different roots. */ -public fun File.toRelativeString(base: File): String - = toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.") +public fun File.toRelativeString(base: File): String = + toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.") /** * Calculates the relative path for this file from [base] file. @@ -100,8 +101,8 @@ public fun File.relativeTo(base: File): File = File(this.toRelativeString(base)) * * @return File with relative path from [base] to this, or `this` if this and base paths have different roots. */ -public fun File.relativeToOrSelf(base: File): File - = toRelativeStringOrNull(base)?.let(::File) ?: this +public fun File.relativeToOrSelf(base: File): File = + toRelativeStringOrNull(base)?.let(::File) ?: this /** * Calculates the relative path for this file from [base] file. @@ -110,8 +111,8 @@ public fun File.relativeToOrSelf(base: File): File * * @return File with relative path from [base] to this, or `null` if this and base paths have different roots. */ -public fun File.relativeToOrNull(base: File): File? - = toRelativeStringOrNull(base)?.let(::File) +public fun File.relativeToOrNull(base: File): File? = + toRelativeStringOrNull(base)?.let(::File) private fun File.toRelativeStringOrNull(base: File): String? { @@ -125,7 +126,7 @@ private fun File.toRelativeStringOrNull(base: File): String? { val baseCount = baseComponents.size val thisCount = thisComponents.size - val sameCount = run countSame@ { + val sameCount = run countSame@{ var i = 0 val maxSameCount = minOf(thisCount, baseCount) while (i < maxSameCount && thisComponents.segments[i] == baseComponents.segments[i]) @@ -189,9 +190,11 @@ public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int val stillExists = if (!overwrite) true else !target.delete() if (stillExists) { - throw FileAlreadyExistsException(file = this, - other = target, - reason = "The destination file already exists.") + throw FileAlreadyExistsException( + file = this, + other = target, + reason = "The destination file already exists." + ) } } @@ -254,10 +257,10 @@ private class TerminateException(file: File) : FileSystemException(file) {} * @param overwrite `true` if it is allowed to overwrite existing destination files and directories. * @return `false` if the copying was terminated, `true` otherwise. */ -public fun File.copyRecursively(target: File, - overwrite: Boolean = false, - onError: (File, IOException) -> OnErrorAction = - { _, exception -> throw exception } +public fun File.copyRecursively( + target: File, + overwrite: Boolean = false, + onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception } ): Boolean { if (!exists()) { return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) != @@ -375,11 +378,11 @@ public fun File.endsWith(other: String): Boolean = endsWith(File(other)) * * @return normalized pathname with . and possibly .. removed. */ -public fun File.normalize(): File - = with (toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) } +public fun File.normalize(): File = + with(toComponents()) { root.resolve(segments.normalize().joinToString(File.separator)) } -private fun FilePathComponents.normalize(): FilePathComponents - = FilePathComponents(root, segments.normalize()) +private fun FilePathComponents.normalize(): FilePathComponents = + FilePathComponents(root, segments.normalize()) private fun List.normalize(): List { val list: MutableList = ArrayList(this.size) diff --git a/libraries/stdlib/jvm/src/kotlin/jvm/internal/unsafe/monitor.kt b/libraries/stdlib/jvm/src/kotlin/jvm/internal/unsafe/monitor.kt index eb1b46ff77c..224793c2fcb 100644 --- a/libraries/stdlib/jvm/src/kotlin/jvm/internal/unsafe/monitor.kt +++ b/libraries/stdlib/jvm/src/kotlin/jvm/internal/unsafe/monitor.kt @@ -7,6 +7,8 @@ package kotlin.jvm.internal.unsafe import kotlin.* -private fun monitorEnter(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") +private fun monitorEnter(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = + throw UnsupportedOperationException("This function can only be used privately") -private fun monitorExit(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") +private fun monitorExit(@Suppress("UNUSED_PARAMETER") monitor: Any): Unit = + throw UnsupportedOperationException("This function can only be used privately") diff --git a/libraries/stdlib/jvm/src/kotlin/ranges/RangesJVM.kt b/libraries/stdlib/jvm/src/kotlin/ranges/RangesJVM.kt index 881e8339a7b..5067f3ece80 100644 --- a/libraries/stdlib/jvm/src/kotlin/ranges/RangesJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/ranges/RangesJVM.kt @@ -5,6 +5,7 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("RangesKt") + package kotlin.ranges import kotlin.* @@ -14,10 +15,10 @@ import kotlin.* * * Numbers are compared with the ends of this range according to IEEE-754. */ -private class ClosedFloatRange ( +private class ClosedFloatRange( start: Float, endInclusive: Float -): ClosedFloatingPointRange { +) : ClosedFloatingPointRange { private val _start = start private val _endInclusive = endInclusive override val start: Float get() = _start @@ -36,6 +37,7 @@ private class ClosedFloatRange ( override fun hashCode(): Int { return if (isEmpty()) -1 else 31 * _start.hashCode() + _endInclusive.hashCode() } + override fun toString(): String = "$_start..$_endInclusive" } diff --git a/libraries/stdlib/jvm/src/kotlin/system/Timing.kt b/libraries/stdlib/jvm/src/kotlin/system/Timing.kt index 0784946d32e..d74d0de6c27 100644 --- a/libraries/stdlib/jvm/src/kotlin/system/Timing.kt +++ b/libraries/stdlib/jvm/src/kotlin/system/Timing.kt @@ -9,7 +9,7 @@ package kotlin.system /** * Executes the given block and returns elapsed time in milliseconds. */ -public inline fun measureTimeMillis(block: () -> Unit) : Long { +public inline fun measureTimeMillis(block: () -> Unit): Long { val start = System.currentTimeMillis() block() return System.currentTimeMillis() - start @@ -18,7 +18,7 @@ public inline fun measureTimeMillis(block: () -> Unit) : Long { /** * Executes the given block and returns elapsed time in nanoseconds. */ -public inline fun measureNanoTime(block: () -> Unit) : Long { +public inline fun measureNanoTime(block: () -> Unit): Long { val start = System.nanoTime() block() return System.nanoTime() - start diff --git a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt index 6482a725306..f9afd6046c0 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt @@ -141,7 +141,7 @@ internal actual fun digitOf(char: Char, radix: Int): Int = Character.digit(char. */ @PublishedApi internal actual fun checkRadix(radix: Int): Int { - if(radix !in Character.MIN_RADIX..Character.MAX_RADIX) { + if (radix !in Character.MIN_RADIX..Character.MAX_RADIX) { throw IllegalArgumentException("radix $radix was not in valid range ${Character.MIN_RADIX..Character.MAX_RADIX}") } return radix diff --git a/libraries/stdlib/jvm/src/kotlin/text/StringNumberConversionsJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/StringNumberConversionsJVM.kt index 88b4022cbb5..b039a67b128 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/StringNumberConversionsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/StringNumberConversionsJVM.kt @@ -267,7 +267,7 @@ private inline fun screenFloatValue(str: String, parse: (String) -> T): T? { parse(str) else null - } catch(e: NumberFormatException) { // overflow + } catch (e: NumberFormatException) { // overflow null } } diff --git a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt index 83071542ab7..fe22b774faa 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/StringsJVM.kt @@ -70,7 +70,7 @@ public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boole */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = - splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue) + splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue) /** @@ -119,7 +119,12 @@ public inline fun String.toCharArray(): CharArray = (this as java.lang.String).t * @param endIndex the end offset (exclusive) of the substring to copy. */ @kotlin.internal.InlineOnly -public inline fun String.toCharArray(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = length): CharArray { +public inline fun String.toCharArray( + destination: CharArray, + destinationOffset: Int = 0, + startIndex: Int = 0, + endIndex: Int = length +): CharArray { (this as java.lang.String).getChars(startIndex, endIndex, destination, destinationOffset) return destination } @@ -143,14 +148,15 @@ public inline fun String.Companion.format(format: String, vararg args: Any?): St * using the specified locale. */ @kotlin.internal.InlineOnly -public inline fun String.format(locale: Locale, vararg args : Any?) : String = java.lang.String.format(locale, this, *args) +public inline fun String.format(locale: Locale, vararg args: Any?): String = java.lang.String.format(locale, this, *args) /** * Uses the provided [format] as a format string and returns a string obtained by substituting the specified arguments, * using the specified locale. */ @kotlin.internal.InlineOnly -public inline fun String.Companion.format(locale: Locale, format: String, vararg args: Any?): String = java.lang.String.format(locale, format, *args) +public inline fun String.Companion.format(locale: Locale, format: String, vararg args: Any?): String = + java.lang.String.format(locale, format, *args) /** * Splits this char sequence around matches of the given regular expression. @@ -158,9 +164,8 @@ public inline fun String.Companion.format(locale: Locale, format: String, vararg * @param limit Non-negative value specifying the maximum number of substrings to return. * Zero by default means no limit is set. */ -public fun CharSequence.split(regex: Pattern, limit: Int = 0): List -{ - require(limit >= 0, { "Limit must be non-negative, but was $limit." } ) +public fun CharSequence.split(regex: Pattern, limit: Int = 0): List { + require(limit >= 0, { "Limit must be non-negative, but was $limit." }) return regex.split(this, if (limit == 0) -1 else limit).asList() } @@ -221,7 +226,8 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean * @param charset the character set to use. */ @kotlin.internal.InlineOnly -public inline fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = java.lang.String(bytes, offset, length, charset) as String +public inline fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = + java.lang.String(bytes, offset, length, charset) as String /** * Converts the data from the specified array of bytes to characters using the specified character set @@ -239,44 +245,51 @@ public inline fun String(bytes: ByteArray, charset: Charset): String = java.lang * @param length the number of bytes to be converted. */ @kotlin.internal.InlineOnly -public inline fun String(bytes: ByteArray, offset: Int, length: Int): String = java.lang.String(bytes, offset, length, Charsets.UTF_8) as String +public inline fun String(bytes: ByteArray, offset: Int, length: Int): String = + java.lang.String(bytes, offset, length, Charsets.UTF_8) as String /** * Converts the data from the specified array of bytes to characters using the UTF-8 character set * and returns the conversion result as a string. */ @kotlin.internal.InlineOnly -public inline fun String(bytes: ByteArray): String = java.lang.String(bytes, Charsets.UTF_8) as String +public inline fun String(bytes: ByteArray): String = + java.lang.String(bytes, Charsets.UTF_8) as String /** * Converts the characters in the specified array to a string. */ @kotlin.internal.InlineOnly -public inline fun String(chars: CharArray): String = java.lang.String(chars) as String +public inline fun String(chars: CharArray): String = + java.lang.String(chars) as String /** * Converts the characters from a portion of the specified array to a string. */ @kotlin.internal.InlineOnly -public inline fun String(chars: CharArray, offset: Int, length: Int): String = java.lang.String(chars, offset, length) as String +public inline fun String(chars: CharArray, offset: Int, length: Int): String = + java.lang.String(chars, offset, length) as String /** * Converts the code points from a portion of the specified Unicode code point array to a string. */ @kotlin.internal.InlineOnly -public inline fun String(codePoints: IntArray, offset: Int, length: Int): String = java.lang.String(codePoints, offset, length) as String +public inline fun String(codePoints: IntArray, offset: Int, length: Int): String = + java.lang.String(codePoints, offset, length) as String /** * Converts the contents of the specified StringBuffer to a string. */ @kotlin.internal.InlineOnly -public inline fun String(stringBuffer: java.lang.StringBuffer): String = java.lang.String(stringBuffer) as String +public inline fun String(stringBuffer: java.lang.StringBuffer): String = + java.lang.String(stringBuffer) as String /** * Converts the contents of the specified StringBuilder to a string. */ @kotlin.internal.InlineOnly -public inline fun String(stringBuilder: java.lang.StringBuilder): String = java.lang.String(stringBuilder) as String +public inline fun String(stringBuilder: java.lang.StringBuilder): String = + java.lang.String(stringBuilder) as String /** * Returns the character (Unicode code point) at the specified index. @@ -294,7 +307,8 @@ public inline fun String.codePointBefore(index: Int): Int = (this as java.lang.S * Returns the number of Unicode code points in the specified text range of this String. */ @kotlin.internal.InlineOnly -public inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = (this as java.lang.String).codePointCount(beginIndex, endIndex) +public inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int = + (this as java.lang.String).codePointCount(beginIndex, endIndex) /** * Compares two strings lexicographically, optionally ignoring case differences. @@ -333,7 +347,8 @@ public actual fun CharSequence.isBlank(): Boolean = length == 0 || indices.all { * Returns the index within this string that is offset from the given [index] by [codePointOffset] code points. */ @kotlin.internal.InlineOnly -public inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset) +public inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int = + (this as java.lang.String).offsetByCodePoints(index, codePointOffset) /** * Returns `true` if the specified range in this char sequence is equal to the specified range in another char sequence. @@ -358,10 +373,10 @@ public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequenc * @param length the length of the substring to compare. */ public fun String.regionMatches(thisOffset: Int, other: String, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean = - if (!ignoreCase) - (this as java.lang.String).regionMatches(thisOffset, other, otherOffset, length) - else - (this as java.lang.String).regionMatches(ignoreCase, thisOffset, other, otherOffset, length) + if (!ignoreCase) + (this as java.lang.String).regionMatches(thisOffset, other, otherOffset, length) + else + (this as java.lang.String).regionMatches(ignoreCase, thisOffset, other, otherOffset, length) /** * Returns a copy of this string converted to lower case using the rules of the specified locale. @@ -418,7 +433,7 @@ public actual fun String.decapitalize(): String { * @sample samples.text.Strings.repeat */ public actual fun CharSequence.repeat(n: Int): String { - require (n >= 0) { "Count 'n' must be non-negative, but was $n." } + require(n >= 0) { "Count 'n' must be non-negative, but was $n." } return when (n) { 0 -> "" diff --git a/libraries/stdlib/jvm/src/kotlin/text/regex/Regex.kt b/libraries/stdlib/jvm/src/kotlin/text/regex/Regex.kt index df96e6ae96a..144b061ad3a 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/regex/Regex.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/regex/Regex.kt @@ -14,12 +14,14 @@ private interface FlagEnum { public val value: Int public val mask: Int } + private fun Iterable.toInt(): Int = - this.fold(0, { value, option -> value or option.value }) -private inline fun fromInt(value: Int): Set where T : FlagEnum, T: Enum = - Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply { - retainAll { value and it.mask == it.value } - }) + this.fold(0, { value, option -> value or option.value }) + +private inline fun fromInt(value: Int): Set where T : FlagEnum, T : Enum = + Collections.unmodifiableSet(EnumSet.allOf(T::class.java).apply { + retainAll { value and it.mask == it.value } + }) /** * Provides enumeration values to use to set regular expression options. @@ -87,13 +89,13 @@ internal constructor(private val nativePattern: Pattern) : Serializable { /** Creates a regular expression from the specified [pattern] string and the default options. */ - public actual constructor(pattern: String): this(Pattern.compile(pattern)) + public actual constructor(pattern: String) : this(Pattern.compile(pattern)) /** Creates a regular expression from the specified [pattern] string and the specified single [option]. */ - public actual constructor(pattern: String, option: RegexOption): this(Pattern.compile(pattern, ensureUnicodeCase(option.value))) + public actual constructor(pattern: String, option: RegexOption) : this(Pattern.compile(pattern, ensureUnicodeCase(option.value))) /** Creates a regular expression from the specified [pattern] string and the specified set of [options]. */ - public actual constructor(pattern: String, options: Set): this(Pattern.compile(pattern, ensureUnicodeCase(options.toInt()))) + public actual constructor(pattern: String, options: Set) : this(Pattern.compile(pattern, ensureUnicodeCase(options.toInt()))) /** The pattern string of this regular expression. */ @@ -117,13 +119,15 @@ internal constructor(private val nativePattern: Pattern) : Serializable { * @return An instance of [MatchResult] if match was found or `null` otherwise. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") - public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input) + public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = + nativePattern.matcher(input).findNext(startIndex, input) /** * Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") - public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence = generateSequence({ find(input, startIndex) }, MatchResult::next) + public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence = + generateSequence({ find(input, startIndex) }, MatchResult::next) /** * Attempts to match the entire [input] CharSequence against the pattern. @@ -170,7 +174,8 @@ internal constructor(private val nativePattern: Pattern) : Serializable { * * @param replacement A replacement expression that can include substitutions. See [Matcher.appendReplacement] for details. */ - public actual fun replaceFirst(input: CharSequence, replacement: String): String = nativePattern.matcher(input).replaceFirst(replacement) + public actual fun replaceFirst(input: CharSequence, replacement: String): String = + nativePattern.matcher(input).replaceFirst(replacement) /** @@ -181,7 +186,7 @@ internal constructor(private val nativePattern: Pattern) : Serializable { */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun split(input: CharSequence, limit: Int = 0): List { - require(limit >= 0, { "Limit must be non-negative, but was $limit." } ) + require(limit >= 0, { "Limit must be non-negative, but was $limit." }) return nativePattern.split(input, if (limit == 0) -1 else limit).asList() } @@ -208,8 +213,10 @@ internal constructor(private val nativePattern: Pattern) : Serializable { actual companion object { /** Returns a literal regex for the specified [literal] string. */ public actual fun fromLiteral(literal: String): Regex = literal.toRegex(RegexOption.LITERAL) + /** Returns a literal pattern for the specified [literal] string. */ public actual fun escape(literal: String): String = Pattern.quote(literal) + /** Returns a literal replacement expression for the specified [literal] string. */ public actual fun escapeReplacement(literal: String): String = Matcher.quoteReplacement(literal) @@ -247,6 +254,7 @@ private class MatcherMatchResult(private val matcher: Matcher, private val input else null } + override fun get(name: String): MatchGroup? { return IMPLEMENTATIONS.getMatchResultNamedGroup(matchResult, name) } diff --git a/libraries/stdlib/jvm/src/kotlin/util/AssertionsJVM.kt b/libraries/stdlib/jvm/src/kotlin/util/AssertionsJVM.kt index 3ff3b96f171..ac34139bde9 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/AssertionsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/AssertionsJVM.kt @@ -9,7 +9,8 @@ package kotlin @PublishedApi internal object _Assertions { - @JvmField @PublishedApi + @JvmField + @PublishedApi internal val ENABLED: Boolean = javaClass.desiredAssertionStatus() } diff --git a/libraries/stdlib/jvm/src/kotlin/util/BigIntegers.kt b/libraries/stdlib/jvm/src/kotlin/util/BigIntegers.kt index db42a8e3640..8346b19c1c7 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/BigIntegers.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/BigIntegers.kt @@ -125,5 +125,5 @@ public inline fun BigInteger.toBigDecimal(): BigDecimal = BigDecimal(this) @SinceKotlin("1.2") @kotlin.internal.InlineOnly public inline fun BigInteger.toBigDecimal(scale: Int = 0, mathContext: MathContext = MathContext.UNLIMITED): BigDecimal = - BigDecimal(this, scale, mathContext) + BigDecimal(this, scale, mathContext) diff --git a/libraries/stdlib/jvm/src/kotlin/util/LazyJVM.kt b/libraries/stdlib/jvm/src/kotlin/util/LazyJVM.kt index b082cb42c89..fd0f0d93440 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/LazyJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/LazyJVM.kt @@ -70,8 +70,7 @@ private class SynchronizedLazyImpl(initializer: () -> T, lock: Any? = nul val _v2 = _value if (_v2 !== UNINITIALIZED_VALUE) { @Suppress("UNCHECKED_CAST") (_v2 as T) - } - else { + } else { val typedValue = initializer!!() _value = typedValue initializer = null @@ -125,6 +124,7 @@ private class SafePublicationLazyImpl(initializer: () -> T) : Lazy, Se private val valueUpdater = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater( SafePublicationLazyImpl::class.java, Any::class.java, - "_value") + "_value" + ) } } \ No newline at end of file diff --git a/libraries/stdlib/jvm/src/kotlin/util/MathJVM.kt b/libraries/stdlib/jvm/src/kotlin/util/MathJVM.kt index bcb8c94ce91..59d7a3cd20b 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/MathJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/MathJVM.kt @@ -439,6 +439,7 @@ public actual inline fun sign(x: Double): Double = nativeMath.signum(x) @SinceKotlin("1.2") @InlineOnly public actual inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b) + /** * Returns the greater of two values. * @@ -524,6 +525,7 @@ public actual inline val Double.sign: Double get() = nativeMath.signum(this) @SinceKotlin("1.2") @InlineOnly public actual inline fun Double.withSign(sign: Double): Double = nativeMath.copySign(this, sign) + /** * Returns this value with the sign bit same as of the [sign] value. */ @@ -551,6 +553,7 @@ public actual inline val Double.ulp: Double get() = nativeMath.ulp(this) @SinceKotlin("1.2") @InlineOnly public actual inline fun Double.nextUp(): Double = nativeMath.nextUp(this) + /** * Returns the [Double] value nearest to this value in direction of negative infinity. */ @@ -599,8 +602,8 @@ public actual fun Double.roundToInt(): Int = when { * @throws IllegalArgumentException when this value is `NaN` */ @SinceKotlin("1.2") -public actual fun Double.roundToLong(): Long = if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this) - +public actual fun Double.roundToLong(): Long = + if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this) // ================ Float Math ======================================== @@ -963,6 +966,7 @@ public actual inline fun sign(x: Float): Float = nativeMath.signum(x) @SinceKotlin("1.2") @InlineOnly public actual inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b) + /** * Returns the greater of two values. * @@ -1048,6 +1052,7 @@ public actual inline val Float.sign: Float get() = nativeMath.signum(this) @SinceKotlin("1.2") @InlineOnly public actual inline fun Float.withSign(sign: Float): Float = nativeMath.copySign(this, sign) + /** * Returns this value with the sign bit same as of the [sign] value. */ @@ -1075,6 +1080,7 @@ public inline val Float.ulp: Float get() = nativeMath.ulp(this) @SinceKotlin("1.2") @InlineOnly public inline fun Float.nextUp(): Float = nativeMath.nextUp(this) + /** * Returns the [Float] value nearest to this value in direction of negative infinity. */ @@ -1105,7 +1111,8 @@ public inline fun Float.nextTowards(to: Float): Float = nativeMath.nextAfter(thi * @throws IllegalArgumentException when this value is `NaN` */ @SinceKotlin("1.2") -public actual fun Float.roundToInt(): Int = if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this) +public actual fun Float.roundToInt(): Int = + if (isNaN()) throw IllegalArgumentException("Cannot round NaN value.") else nativeMath.round(this) /** * Rounds this [Float] value to the nearest integer and converts the result to [Long].