From 240a423bed991487a2f2248028118f07320e4dba Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Tue, 30 Jan 2024 16:01:04 +0200 Subject: [PATCH] Introduce Common protected function AbstractMutableList.removeRange #KT-57151 --- .../common/src/kotlin/collections/AbstractMutableList.kt | 7 +++++++ .../js/src/kotlin/collections/AbstractMutableList.kt | 2 +- .../jvm/src/kotlin/collections/AbstractMutableList.kt | 2 ++ .../src/kotlin/collections/AbstractMutableList.kt | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt index 4df15c7271f..494b0b21ece 100644 --- a/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt +++ b/libraries/stdlib/common/src/kotlin/collections/AbstractMutableList.kt @@ -13,6 +13,13 @@ package kotlin.collections public expect abstract class AbstractMutableList : MutableList { protected constructor() + /** + * Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex]. + */ + // TODO: Should be @SinceKotlin("2.0"), see KT-64904 + @SinceKotlin("1.9") + protected open fun removeRange(fromIndex: Int, toIndex: Int): Unit + // From List override fun isEmpty(): Boolean diff --git a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt index bb8c65944d9..df2cf8a31c2 100644 --- a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt +++ b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt @@ -81,7 +81,7 @@ public actual abstract class AbstractMutableList protected actual constructor /** * Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex]. */ - protected open fun removeRange(fromIndex: Int, toIndex: Int) { + protected actual open fun removeRange(fromIndex: Int, toIndex: Int) { val iterator = listIterator(fromIndex) repeat(toIndex - fromIndex) { iterator.next() diff --git a/libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableList.kt index 1290ad7b0b2..3522845336a 100644 --- a/libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableList.kt +++ b/libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableList.kt @@ -13,6 +13,8 @@ import java.util.AbstractList * @param E the type of elements contained in the list. The list is invariant in its element type. */ @SinceKotlin("1.1") +// removeRange: Kotlin `protected` visibility is different from Java +@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS") public actual abstract class AbstractMutableList protected actual constructor() : MutableList, AbstractList() { /** * Replaces the element at the specified position in this list with the specified element. diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt index 61eb0d9889c..d0b1e12020e 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableList.kt @@ -81,7 +81,7 @@ public actual abstract class AbstractMutableList protected actual constructor /** * Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex]. */ - protected open fun removeRange(fromIndex: Int, toIndex: Int) { + protected actual open fun removeRange(fromIndex: Int, toIndex: Int) { val iterator = listIterator(fromIndex) repeat(toIndex - fromIndex) { iterator.next()