Skip to content

Commit fa30140

Browse files
authored
Cleanup core module after update to Kotlin 1.4 (#2440)
* Remove explicit API mode suppressions * Use list build in ReceiveChannel.toList to prevent casting to mutable list * Migrate to maxByOrNull * Remove redundant nullabilities
1 parent 1176267 commit fa30140

File tree

14 files changed

+23
-24
lines changed

14 files changed

+23
-24
lines changed

kotlinx-coroutines-core/common/src/CoroutineStart.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
4-
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
54
package kotlinx.coroutines
65

76
import kotlinx.coroutines.CoroutineStart.*

kotlinx-coroutines-core/common/src/channels/Channels.common.kt

+13-9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ public suspend inline fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Uni
8888

8989
// -------- Operations on ReceiveChannel --------
9090

91+
/**
92+
* Returns a [List] containing all elements.
93+
*
94+
* The operation is _terminal_.
95+
* This function [consumes][ReceiveChannel.consume] all elements of the original [ReceiveChannel].
96+
*/
97+
@OptIn(ExperimentalStdlibApi::class)
98+
public suspend fun <E> ReceiveChannel<E>.toList(): List<E> = buildList {
99+
consumeEach {
100+
add(it)
101+
}
102+
}
103+
91104
/**
92105
* Returns a [CompletionHandler] that invokes [cancel][ReceiveChannel.cancel] on the [ReceiveChannel]
93106
* with the corresponding cause. See also [ReceiveChannel.consume].
@@ -1189,15 +1202,6 @@ public suspend fun <E, C : MutableCollection<in E>> ReceiveChannel<E>.toCollecti
11891202
return destination
11901203
}
11911204

1192-
/**
1193-
* Returns a [List] containing all elements.
1194-
*
1195-
* The operation is _terminal_.
1196-
* This function [consumes][ReceiveChannel.consume] all elements of the original [ReceiveChannel].
1197-
*/
1198-
public suspend fun <E> ReceiveChannel<E>.toList(): List<E> =
1199-
this.toMutableList()
1200-
12011205
/**
12021206
* Returns a [Map] filled with all elements of this channel.
12031207
*

kotlinx-coroutines-core/jvm/src/CommonPool.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal object CommonPool : ExecutorCoroutineDispatcher() {
2828
* Note that until Java 10, if an application is run within a container,
2929
* `Runtime.getRuntime().availableProcessors()` is not aware of container constraints and will return the real number of cores.
3030
*/
31-
public const val DEFAULT_PARALLELISM_PROPERTY_NAME = "kotlinx.coroutines.default.parallelism"
31+
private const val DEFAULT_PARALLELISM_PROPERTY_NAME = "kotlinx.coroutines.default.parallelism"
3232

3333
override val executor: Executor
3434
get() = pool ?: getOrCreatePoolSync()
@@ -62,7 +62,7 @@ internal object CommonPool : ExecutorCoroutineDispatcher() {
6262
?: return createPlainPool() // Fallback to plain thread pool
6363
// Try to use commonPool unless parallelism was explicitly specified or in debug privatePool mode
6464
if (!usePrivatePool && requestedParallelism < 0) {
65-
Try { fjpClass.getMethod("commonPool")?.invoke(null) as? ExecutorService }
65+
Try { fjpClass.getMethod("commonPool").invoke(null) as? ExecutorService }
6666
?.takeIf { isGoodCommonPool(fjpClass, it) }
6767
?.let { return it }
6868
}

kotlinx-coroutines-core/jvm/src/CoroutineContext.kt

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package kotlinx.coroutines
66

77
import kotlinx.coroutines.internal.*
88
import kotlinx.coroutines.scheduling.*
9-
import java.util.concurrent.atomic.*
109
import kotlin.coroutines.*
1110

1211
internal const val COROUTINES_SCHEDULER_PROPERTY_NAME = "kotlinx.coroutines.scheduler"

kotlinx-coroutines-core/jvm/src/Dispatchers.kt

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package kotlinx.coroutines
88

99
import kotlinx.coroutines.internal.*
1010
import kotlinx.coroutines.scheduling.*
11-
import java.util.*
1211
import kotlin.coroutines.*
1312

1413
/**

kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt

-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
package kotlinx.coroutines
66

7-
import kotlinx.coroutines.internal.*
87
import java.util.concurrent.*
98
import java.util.concurrent.atomic.AtomicInteger
10-
import kotlin.coroutines.*
119

1210
/**
1311
* Creates a coroutine execution context using a single thread with built-in [yield] support.

kotlinx-coroutines-core/jvm/src/debug/internal/DebugCoroutineInfoImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal class DebugCoroutineInfoImpl(
7272
private fun creationStackTrace(): List<StackTraceElement> {
7373
val bottom = creationStackBottom ?: return emptyList()
7474
// Skip "Coroutine creation stacktrace" frame
75-
return sequence<StackTraceElement> { yieldFrames(bottom.callerFrame) }.toList()
75+
return sequence { yieldFrames(bottom.callerFrame) }.toList()
7676
}
7777

7878
private tailrec suspend fun SequenceScope<StackTraceElement>.yieldFrames(frame: CoroutineStackFrame?) {

kotlinx-coroutines-core/jvm/src/flow/internal/SafeCollector.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal actual class SafeCollector<T> actual constructor(
3636
override val context: CoroutineContext
3737
get() = completion?.context ?: EmptyCoroutineContext
3838

39-
override fun invokeSuspend(result: Result<Any?>): Any? {
39+
override fun invokeSuspend(result: Result<Any?>): Any {
4040
result.onFailure { lastEmissionContext = DownstreamExceptionElement(it) }
4141
completion?.resumeWith(result as Result<Unit>)
4242
return COROUTINE_SUSPENDED

kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.*
99
import java.util.concurrent.*
1010
import kotlin.concurrent.withLock as withLockJvm
1111

12-
internal actual fun <E> subscriberList(): SubscribersList<E> = CopyOnWriteArrayList<E>()
12+
internal actual fun <E> subscriberList(): SubscribersList<E> = CopyOnWriteArrayList()
1313

1414
@Suppress("ACTUAL_WITHOUT_EXPECT")
1515
internal actual typealias ReentrantLock = java.util.concurrent.locks.ReentrantLock

kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public actual open class LockFreeLinkedListNode {
322322

323323
private val _affectedNode = atomic<Node?>(null)
324324
final override val affectedNode: Node? get() = _affectedNode.value
325-
final override val originalNext: Node? get() = queue
325+
final override val originalNext: Node get() = queue
326326

327327
override fun retry(affected: Node, next: Any): Boolean = next !== queue
328328

kotlinx-coroutines-core/jvm/src/internal/MainDispatchers.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal object MainDispatcherLoader {
3535
).iterator().asSequence().toList()
3636
}
3737
@Suppress("ConstantConditionIf")
38-
factories.maxBy { it.loadPriority }?.tryCreateDispatcher(factories)
38+
factories.maxByOrNull { it.loadPriority }?.tryCreateDispatcher(factories)
3939
?: createMissingDispatcher()
4040
} catch (e: Throwable) {
4141
// Service loader can throw an exception as well

kotlinx-coroutines-core/jvm/src/internal/StackTraceRecovery.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
@file:Suppress("UNCHECKED_CAST", "NO_EXPLICIT_VISIBILITY_IN_API_MODE")
5+
@file:Suppress("UNCHECKED_CAST")
66

77
package kotlinx.coroutines.internal
88

kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal class CoroutineScheduler(
169169
* It does nothing is this worker is already physically linked to the stack.
170170
* This method is invoked only from the worker thread itself.
171171
* This invocation always precedes [LockSupport.parkNanos].
172-
* See [Worker.doPark].
172+
* See [Worker.tryPark].
173173
*
174174
* Returns `true` if worker was added to the stack by this invocation, `false` if it was already
175175
* registered in the stack.

kotlinx-coroutines-debug/src/CoroutineInfo.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
4-
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNUSED")
4+
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNUSED")
55
package kotlinx.coroutines.debug
66

77
import kotlinx.coroutines.*

0 commit comments

Comments
 (0)