diff --git a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt b/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt index cc12dc2bf3e..03eb9a87a30 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt @@ -5,14 +5,16 @@ package kotlin.test import kotlin.reflect.* /** Asserts that a [block] fails with a specific exception being thrown. */ -@Deprecated("Use assertFailsWith with kotlin class.", ReplaceWith("assertFailsWith(exceptionClass.kotlin, block)")) +@Deprecated("Use assertFailsWith with kotlin class.", ReplaceWith("assertFailsWith(exceptionClass.kotlin, block)"), level = DeprecationLevel.ERROR) fun assertFailsWith(exceptionClass: Class, block: () -> Unit): T { - return assertFailsWith(exceptionClass, null, block) + return assertFailsWithImpl(exceptionClass, null, block) } +@Deprecated("Use assertFailsWith with kotlin class.", ReplaceWith("assertFailsWith(exceptionClass.kotlin, message, block)"), level = DeprecationLevel.ERROR) +fun assertFailsWith(exceptionClass: Class, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass, message, block) + /** Asserts that a [block] fails with a specific exception being thrown. */ -@Deprecated("Use assertFailsWith with kotlin class.", ReplaceWith("assertFailsWith(exceptionClass.kotlin, message, block)")) -fun assertFailsWith(exceptionClass: Class, message: String?, block: () -> Unit): T { +private fun assertFailsWithImpl(exceptionClass: Class, message: String?, block: () -> Unit): T { try { block() } catch (e: Throwable) { @@ -30,12 +32,12 @@ fun assertFailsWith(exceptionClass: Class, message: String?, fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block) /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ -fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = assertFailsWith(exceptionClass.java, message, block) +fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass.java, message, block) /** Asserts that a [block] fails with a specific exception of type [T] being thrown. * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ -inline fun assertFailsWith(message: String, noinline block: () -> Unit): T = assertFailsWith(T::class.java, message, block) +inline fun assertFailsWith(message: String, noinline block: () -> Unit): T = assertFailsWith(T::class, message, block) /** diff --git a/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt b/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt index 6b5f633cf35..e9f83fc5695 100644 --- a/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt +++ b/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt @@ -27,9 +27,9 @@ class BasicAssertionsJVMTest { @Test fun testFailsWithClassMessage() { @Suppress("UNCHECKED_CAST") - assertFailsWith(Class.forName("java.lang.IllegalArgumentException") as Class) { + (assertFailsWith((Class.forName("java.lang.IllegalArgumentException") as Class).kotlin) { throw IllegalArgumentException() - } + }) } @Test diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 632a61f90b9..c5bddd02002 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -6019,7 +6019,7 @@ public inline fun > ShortArray.associateTo(dest /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun Array.toArrayList(): ArrayList { return ArrayList(this.asCollection()) } @@ -6027,7 +6027,7 @@ public fun Array.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun BooleanArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6037,7 +6037,7 @@ public fun BooleanArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun ByteArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6047,7 +6047,7 @@ public fun ByteArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun CharArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6057,7 +6057,7 @@ public fun CharArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun DoubleArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6067,7 +6067,7 @@ public fun DoubleArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun FloatArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6077,7 +6077,7 @@ public fun FloatArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun IntArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6087,7 +6087,7 @@ public fun IntArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun LongArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6097,7 +6097,7 @@ public fun LongArray.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun ShortArray.toArrayList(): ArrayList { val list = ArrayList(size) for (item in this) list.add(item) @@ -6324,7 +6324,7 @@ public fun ShortArray.toList(): List { * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Array.toMap(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } @@ -6333,7 +6333,7 @@ public inline fun Array.toMap(selector: (T) -> K, transform: (T * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun BooleanArray.toMap(selector: (Boolean) -> K, transform: (Boolean) -> V): Map { return associateBy(selector, transform) } @@ -6342,7 +6342,7 @@ public inline fun BooleanArray.toMap(selector: (Boolean) -> K, transform: * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun ByteArray.toMap(selector: (Byte) -> K, transform: (Byte) -> V): Map { return associateBy(selector, transform) } @@ -6351,7 +6351,7 @@ public inline fun ByteArray.toMap(selector: (Byte) -> K, transform: (Byte * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun CharArray.toMap(selector: (Char) -> K, transform: (Char) -> V): Map { return associateBy(selector, transform) } @@ -6360,7 +6360,7 @@ public inline fun CharArray.toMap(selector: (Char) -> K, transform: (Char * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun DoubleArray.toMap(selector: (Double) -> K, transform: (Double) -> V): Map { return associateBy(selector, transform) } @@ -6369,7 +6369,7 @@ public inline fun DoubleArray.toMap(selector: (Double) -> K, transform: ( * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun FloatArray.toMap(selector: (Float) -> K, transform: (Float) -> V): Map { return associateBy(selector, transform) } @@ -6378,7 +6378,7 @@ public inline fun FloatArray.toMap(selector: (Float) -> K, transform: (Fl * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun IntArray.toMap(selector: (Int) -> K, transform: (Int) -> V): Map { return associateBy(selector, transform) } @@ -6387,7 +6387,7 @@ public inline fun IntArray.toMap(selector: (Int) -> K, transform: (Int) - * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun LongArray.toMap(selector: (Long) -> K, transform: (Long) -> V): Map { return associateBy(selector, transform) } @@ -6396,151 +6396,151 @@ public inline fun LongArray.toMap(selector: (Long) -> K, transform: (Long * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun ShortArray.toMap(selector: (Short) -> K, transform: (Short) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun Array.toMap(transform: (T) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun BooleanArray.toMap(transform: (Boolean) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun ByteArray.toMap(transform: (Byte) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun CharArray.toMap(transform: (Char) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun DoubleArray.toMap(transform: (Double) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun FloatArray.toMap(transform: (Float) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun IntArray.toMap(transform: (Int) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun LongArray.toMap(transform: (Long) -> Pair): Map { return associate(transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun ShortArray.toMap(transform: (Short) -> Pair): Map { return associate(transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun Array.toMapBy(selector: (T) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun BooleanArray.toMapBy(selector: (Boolean) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun ByteArray.toMapBy(selector: (Byte) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun CharArray.toMapBy(selector: (Char) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun DoubleArray.toMapBy(selector: (Double) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun FloatArray.toMapBy(selector: (Float) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun IntArray.toMapBy(selector: (Int) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun LongArray.toMapBy(selector: (Long) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun ShortArray.toMapBy(selector: (Short) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Array.toMapBy(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun BooleanArray.toMapBy(selector: (Boolean) -> K, transform: (Boolean) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun ByteArray.toMapBy(selector: (Byte) -> K, transform: (Byte) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun CharArray.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun DoubleArray.toMapBy(selector: (Double) -> K, transform: (Double) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun FloatArray.toMapBy(selector: (Float) -> K, transform: (Float) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun IntArray.toMapBy(selector: (Int) -> K, transform: (Int) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun LongArray.toMapBy(selector: (Long) -> K, transform: (Long) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun ShortArray.toMapBy(selector: (Short) -> K, transform: (Short) -> V): Map { return associateBy(selector, transform) } diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 6e07ab54c34..88c6989aa03 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -983,7 +983,7 @@ public inline fun > Iterable.associateTo( /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun Collection.toArrayList(): ArrayList { return ArrayList(this) } @@ -991,10 +991,10 @@ public fun Collection.toArrayList(): ArrayList { /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun Iterable.toArrayList(): ArrayList { if (this is Collection) - return this.toArrayList() + return ArrayList(this) return toCollection(ArrayList()) } @@ -1026,23 +1026,23 @@ public fun Iterable.toList(): List { * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given collection. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Iterable.toMap(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun Iterable.toMap(transform: (T) -> Pair): Map { return associate(transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun Iterable.toMapBy(selector: (T) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Iterable.toMapBy(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index c690caabc8b..19aeb0bf76e 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -489,7 +489,7 @@ public inline fun > Sequence.associateTo( /** * Returns an [ArrayList] of all elements. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun Sequence.toArrayList(): ArrayList { return toCollection(ArrayList()) } @@ -522,23 +522,23 @@ public fun Sequence.toList(): List { * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given sequence. * If any two elements would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Sequence.toMap(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun Sequence.toMap(transform: (T) -> Pair): Map { return associate(transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun Sequence.toMapBy(selector: (T) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun Sequence.toMapBy(selector: (T) -> K, transform: (T) -> V): Map { return associateBy(selector, transform) } diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 2ea27e8f455..2fc9d3eb5b6 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -561,7 +561,7 @@ public inline fun > CharSequence.associateTo(de /** * Returns an [ArrayList] of all characters. */ -@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())")) +@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) public fun CharSequence.toArrayList(): ArrayList { return toCollection(ArrayList(length)) } @@ -594,23 +594,23 @@ public fun CharSequence.toList(): List { * Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given char sequence. * If any two characters would have the same key returned by [selector] the last one gets added to the map. */ -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun CharSequence.toMap(selector: (Char) -> K, transform: (Char) -> V): Map { return associateBy(selector, transform) } -@Deprecated("Use associate instead.", ReplaceWith("associate(transform)")) +@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR) @kotlin.jvm.JvmName("toMapOfPairs") public inline fun CharSequence.toMap(transform: (Char) -> Pair): Map { return associate(transform) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR) public inline fun CharSequence.toMapBy(selector: (Char) -> K): Map { return associateBy(selector) } -@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)")) +@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR) public inline fun CharSequence.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map { return associateBy(selector, transform) } diff --git a/libraries/stdlib/src/kotlin/collections/JUtil.kt b/libraries/stdlib/src/kotlin/collections/JUtil.kt index afec61f5fd2..355e8ddfe1a 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtil.kt +++ b/libraries/stdlib/src/kotlin/collections/JUtil.kt @@ -75,11 +75,11 @@ public fun listOf(element: T): List = Collections.singletonList(element) /** Returns a new [LinkedList] with the given elements. */ @JvmVersion -@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList(listOf(*elements))", "java.util.LinkedList")) +@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList(listOf(*elements))", "java.util.LinkedList"), level = DeprecationLevel.ERROR) public fun linkedListOf(vararg elements: T): LinkedList = if (elements.size == 0) LinkedList() else LinkedList(ArrayAsCollection(elements)) -@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList()", "java.util.LinkedList")) +@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList()", "java.util.LinkedList"), level = DeprecationLevel.ERROR) public fun linkedListOf() = LinkedList() diff --git a/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt b/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt index 4eba8825b25..30195a66264 100644 --- a/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt +++ b/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt @@ -12,17 +12,8 @@ import java.util.* * * @throws NoSuchElementException when the map doesn't contain value for the specified key and no implicit default was provided for that map. */ -@Deprecated("This function is used to support property delegation to map with defaults and will become internal soon.") -public fun Map.getOrImplicitDefault(key: K): V { - if (this is MapWithDefault) - return this.getOrImplicitDefault(key) - - return getOrElseNullable(key, { throw NoSuchElementException("Key $key is missing in the map.") }) -} - @kotlin.jvm.JvmName("getOrImplicitDefaultNullable") -@Deprecated("This function is used to support property delegation to map with defaults and will become internal soon.") -public fun Map.getOrImplicitDefault(key: K): V { +internal fun Map.getOrImplicitDefault(key: K): V { if (this is MapWithDefault) return this.getOrImplicitDefault(key) @@ -31,7 +22,7 @@ public fun Map.getOrImplicitDefault(key: K): V { /** * Returns a wrapper of this read-only map, having the implicit default value provided with the specified function [defaultValue]. - * This implicit default value is used when [getOrImplicitDefault] is called on the returned map, + * This implicit default value is used when properties are delegated to the returned map, * and that map doesn't contain value for the key specified. * * When this map already have an implicit default value provided with a former call to [withDefault], it is being replaced by this call. @@ -44,7 +35,7 @@ public fun Map.withDefault(defaultValue: (key: K) -> V): Map /** * Returns a wrapper of this mutable map, having the implicit default value provided with the specified function [defaultValue]. - * This implicit default value is used when [getOrImplicitDefault] is called on the returned map, + * This implicit default value is used when properties are delegated to the returned map, * and that map doesn't contain value for the key specified. * * When this map already have an implicit default value provided with a former call to [withDefault], it is being replaced by this call. diff --git a/libraries/stdlib/src/kotlin/collections/Maps.kt b/libraries/stdlib/src/kotlin/collections/Maps.kt index a724a46c01d..af12b1f7448 100644 --- a/libraries/stdlib/src/kotlin/collections/Maps.kt +++ b/libraries/stdlib/src/kotlin/collections/Maps.kt @@ -392,7 +392,7 @@ public fun > Sequence>.toMap(destina /** * Converts this [Map] to a [LinkedHashMap], maintaining the insertion order of elements added to that map afterwards. */ -@Deprecated("It may be too late to convert map this map to linked map, if you care about the order use the ordered map from the beginning.", ReplaceWith("LinkedHashMap(this)", "java.util.LinkedHashMap")) +@Deprecated("It may be too late to convert map this map to linked map, if you care about the order use the ordered map from the beginning.", ReplaceWith("LinkedHashMap(this)", "java.util.LinkedHashMap"), level = DeprecationLevel.ERROR) public fun Map.toLinkedMap(): MutableMap = LinkedHashMap(this) /** @@ -464,35 +464,35 @@ public operator fun MutableMap.plusAssign(map: Map) { /** * Creates a new read-only map by removing a [key] from this map. */ -@Deprecated("This operation will be removed soon.") +@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= key.", level = DeprecationLevel.ERROR) public operator fun Map.minus(key: K): Map - = this.toLinkedMap().apply { minusAssign(key) } + = LinkedHashMap(this).apply { keys.remove(key) } /** * Creates a new read-only map by removing a collection of [keys] from this map. */ -@Deprecated("This operation will be removed soon.") +@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR) public operator fun Map.minus(keys: Iterable): Map - = this.toLinkedMap().apply { minusAssign(keys) } + = LinkedHashMap(this).apply { for (key in keys) remove(key) } /** * Creates a new read-only map by removing a array of [keys] from this map. */ -@Deprecated("This operation will be removed soon.") +@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR) public operator fun Map.minus(keys: Array): Map - = this.toLinkedMap().apply { minusAssign(keys) } + = LinkedHashMap(this).apply { for (key in keys) remove(key) } /** * Creates a new read-only map by removing a sequence of [keys] from this map. */ -@Deprecated("This operation will be removed soon.") +@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR) public operator fun Map.minus(keys: Sequence): Map - = this.toLinkedMap().apply { minusAssign(keys) } + = LinkedHashMap(this).apply { for (key in keys) remove(key) } /** * Removes the given [key] from this mutable map. */ -@Deprecated("This operation will be removed soon, use remove(key) instead.", ReplaceWith("this.keys -= key")) +@Deprecated("This operation will be removed soon, use remove(key) instead.", ReplaceWith("this.keys -= key"), level = DeprecationLevel.ERROR) public operator fun MutableMap.minusAssign(key: K) { remove(key) } @@ -500,7 +500,7 @@ public operator fun MutableMap.minusAssign(key: K) { /** * Removes all the given [keys] from this mutable map. */ -@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys")) +@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR) public operator fun MutableMap.minusAssign(keys: Iterable) { for (key in keys) remove(key) } @@ -508,7 +508,7 @@ public operator fun MutableMap.minusAssign(keys: Iterable) { /** * Removes all the given [keys] from this mutable map. */ -@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys")) +@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR) public operator fun MutableMap.minusAssign(keys: Array) { for (key in keys) remove(key) } @@ -516,7 +516,7 @@ public operator fun MutableMap.minusAssign(keys: Array) { /** * Removes all the given [keys] from this mutable map. */ -@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys")) +@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR) public operator fun MutableMap.minusAssign(keys: Sequence) { for (key in keys) remove(key) } diff --git a/libraries/stdlib/src/kotlin/collections/Sequences.kt b/libraries/stdlib/src/kotlin/collections/Sequences.kt index 7698dd509d0..6bb5e120259 100644 --- a/libraries/stdlib/src/kotlin/collections/Sequences.kt +++ b/libraries/stdlib/src/kotlin/collections/Sequences.kt @@ -488,7 +488,7 @@ public fun generateSequence(nextFunction: () -> T?): Sequence { return GeneratorSequence(nextFunction, { nextFunction() }).constrainOnce() } -@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(nextFunction)")) +@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(nextFunction)"), level = DeprecationLevel.ERROR) public fun sequence(nextFunction: () -> T?): Sequence = generateSequence(nextFunction) /** @@ -504,7 +504,7 @@ public fun generateSequence(seed: T?, nextFunction: (T) -> T?): Sequen else GeneratorSequence({ seed }, nextFunction) -@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValue, nextFunction)")) +@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValue, nextFunction)"), level = DeprecationLevel.ERROR) @kotlin.internal.LowPriorityInOverloadResolution public fun sequence(initialValue: T?, nextFunction: (T) -> T?): Sequence = generateSequence(initialValue, nextFunction) @@ -517,5 +517,5 @@ public fun generateSequence(seedFunction: () -> T?, nextFunction: (T) - GeneratorSequence(seedFunction, nextFunction) -@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValueFunction, nextFunction)")) +@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValueFunction, nextFunction)"), level = DeprecationLevel.ERROR) public fun sequence(initialValueFunction: () -> T?, nextFunction: (T) -> T?): Sequence = generateSequence(initialValueFunction, nextFunction) diff --git a/libraries/stdlib/src/kotlin/io/files/FileTreeWalk.kt b/libraries/stdlib/src/kotlin/io/files/FileTreeWalk.kt index 1b933871c16..2dbddf3a1ee 100644 --- a/libraries/stdlib/src/kotlin/io/files/FileTreeWalk.kt +++ b/libraries/stdlib/src/kotlin/io/files/FileTreeWalk.kt @@ -60,7 +60,6 @@ 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) { init { - @Suppress("DEPRECATION") if (ASSERTIONS_ENABLED) assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." } } @@ -208,7 +207,6 @@ public class FileTreeWalk private constructor( private var visited: Boolean = false init { - @Suppress("DEPRECATION") if (ASSERTIONS_ENABLED) assert(rootFile.isFile) { "rootFile must be verified to be file beforehand." } } diff --git a/libraries/stdlib/src/kotlin/io/files/Utils.kt b/libraries/stdlib/src/kotlin/io/files/Utils.kt index 4a9cb93fa44..1b34b7dc559 100644 --- a/libraries/stdlib/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/src/kotlin/io/files/Utils.kt @@ -87,7 +87,7 @@ public fun File.toRelativeString(base: File): String */ public fun File.relativeTo(base: File): File = File(this.toRelativeString(base)) -@Deprecated("Use relativeTo instead.", ReplaceWith("this.relativeTo(base)"), level = DeprecationLevel.WARNING) +@Deprecated("Use relativeTo instead.", ReplaceWith("this.relativeTo(base)"), level = DeprecationLevel.ERROR) public fun File.relativeToFile(base: File): File = File(this.toRelativeString(base)) diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index bbd1c07c365..f4ebc3d7418 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -445,7 +445,7 @@ public fun CharSequence.repeat(n: Int): String { * Appends the contents of this char sequence, excluding the first characters that satisfy the given [predicate], * to the given Appendable. */ -@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.dropWhile(predicate))")) +@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.dropWhile(predicate))"), level = DeprecationLevel.ERROR) public inline fun CharSequence.dropWhileTo(result: T, predicate: (Char) -> Boolean): T { var start = true for (element in this) { @@ -462,7 +462,7 @@ public inline fun CharSequence.dropWhileTo(result: T, predicate /** * Appends the first characters from this char sequence that satisfy the given [predicate] to the given Appendable. */ -@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.takeWhile(predicate))")) +@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.takeWhile(predicate))"), level = DeprecationLevel.ERROR) public inline fun CharSequence.takeWhileTo(result: T, predicate: (Char) -> Boolean): T { for (c in this) if (predicate(c)) result.append(c) else break return result diff --git a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt index 3592c756c0c..e6f7e27360b 100644 --- a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt +++ b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt @@ -5,8 +5,7 @@ package kotlin private object _Assertions -@Deprecated("Not supposed to be used directly, exposed to make assert() inlinable.") -public val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus() +internal val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus() /** * Throws an [AssertionError] if the [value] is false @@ -21,7 +20,7 @@ public fun assert(value: Boolean) { * and runtime assertions have been enabled on the JVM using the *-ea* JVM option. */ public inline fun assert(value: Boolean, lazyMessage: () -> Any) { - @Suppress("DEPRECATION") + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") if (ASSERTIONS_ENABLED) { if (!value) { val message = lazyMessage() diff --git a/libraries/stdlib/src/kotlin/util/OrderingDeprecated.kt b/libraries/stdlib/src/kotlin/util/OrderingDeprecated.kt index d57ad39cbf3..94b802d2e0b 100644 --- a/libraries/stdlib/src/kotlin/util/OrderingDeprecated.kt +++ b/libraries/stdlib/src/kotlin/util/OrderingDeprecated.kt @@ -14,6 +14,7 @@ * limitations under the License. */ @file:kotlin.jvm.JvmName("ComparisonsKt") +@file:Suppress("DEPRECATION_ERROR") package kotlin @@ -25,7 +26,7 @@ import java.util.Comparator * objects. As soon as the [Comparable] instances returned by a function for [a] and [b] values do not * compare as equal, the result of that comparison is returned. */ -@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, *selectors)", "kotlin.comparisons.compareValuesBy")) +@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, *selectors)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR) public fun compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int { require(selectors.size > 0) for (fn in selectors) { @@ -42,7 +43,7 @@ public fun compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<* * The function is applied to the given values [a] and [b] and return [Comparable] objects. * The result of comparison of these [Comparable] instances is returned. */ -@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, selector)", "kotlin.comparisons.compareValuesBy")) +@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, selector)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR) public inline fun compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*>?): Int { return compareValues(selector(a), selector(b)) } @@ -52,7 +53,7 @@ public inline fun compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*> * The function is applied to the given values [a] and [b] and return objects of type K which are then being * compared with the given [comparator]. */ -@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, comparator, selector)", "kotlin.comparisons.compareValuesBy")) +@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, comparator, selector)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR) public inline fun compareValuesBy(a: T, b: T, comparator: Comparator, selector: (T) -> K): Int { return comparator.compare(selector(a), selector(b)) } @@ -70,7 +71,7 @@ public inline fun compareValuesBy(a: T, b: T, comparator: Comparator> compareValues(a: T?, b: T?): Int { if (a === b) return 0 if (a == null) return -1 @@ -85,7 +86,7 @@ public fun > compareValues(a: T?, b: T?): Int { * objects. As soon as the [Comparable] instances returned by a function for `a` and `b` values do not * compare as equal, the result of that comparison is returned from the [Comparator]. */ -@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(*selectors)", "kotlin.comparisons.compareBy")) +@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(*selectors)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR) public fun compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, *selectors) @@ -97,7 +98,7 @@ public fun compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator /** * Creates a comparator using the function to transform value to a [Comparable] instance for comparison. */ -@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(selector)", "kotlin.comparisons.compareBy")) +@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(selector)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR) inline public fun compareBy(crossinline selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, selector) @@ -108,7 +109,7 @@ inline public fun compareBy(crossinline selector: (T) -> Comparable<*>?): Co * Creates a comparator using the [selector] function to transform values being compared and then applying * the specified [comparator] to compare transformed values. */ -@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(comparator, selector)", "kotlin.comparisons.compareBy")) +@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(comparator, selector)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR) inline public fun compareBy(comparator: Comparator, crossinline selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, comparator, selector) @@ -118,7 +119,7 @@ inline public fun compareBy(comparator: Comparator, crossinline sel /** * Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison. */ -@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(selector)", "kotlin.comparisons.compareByDescending")) +@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(selector)", "kotlin.comparisons.compareByDescending"), level = DeprecationLevel.ERROR) inline public fun compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, selector) @@ -131,7 +132,7 @@ inline public fun compareByDescending(crossinline selector: (T) -> Comparabl * * Note that an order of [comparator] is reversed by this wrapper. */ -@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(comparator, selector)", "kotlin.comparisons.compareByDescending")) +@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(comparator, selector)", "kotlin.comparisons.compareByDescending"), level = DeprecationLevel.ERROR) inline public fun compareByDescending(comparator: Comparator, crossinline selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, comparator, selector) @@ -142,7 +143,7 @@ inline public fun compareByDescending(comparator: Comparator, cross * Creates a comparator comparing values after the primary comparator defined them equal. It uses * the function to transform value to a [Comparable] instance for comparison. */ -@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(selector)", "kotlin.comparisons.thenBy")) +@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(selector)", "kotlin.comparisons.thenBy"), level = DeprecationLevel.ERROR) inline public fun Comparator.thenBy(crossinline selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -156,7 +157,7 @@ inline public fun Comparator.thenBy(crossinline selector: (T) -> Comparab * Creates a comparator comparing values after the primary comparator defined them equal. It uses * the [selector] function to transform values and then compares them with the given [comparator]. */ -@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(comparator, selector)", "kotlin.comparisons.thenBy")) +@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(comparator, selector)", "kotlin.comparisons.thenBy"), level = DeprecationLevel.ERROR) inline public fun Comparator.thenBy(comparator: Comparator, crossinline selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -170,7 +171,7 @@ inline public fun Comparator.thenBy(comparator: Comparator, cros * Creates a descending comparator using the primary comparator and * the function to transform value to a [Comparable] instance for comparison. */ -@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(selector)", "kotlin.comparisons.thenByDescending")) +@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(selector)", "kotlin.comparisons.thenByDescending"), level = DeprecationLevel.ERROR) inline public fun Comparator.thenByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -184,7 +185,7 @@ inline public fun Comparator.thenByDescending(crossinline selector: (T) - * Creates a descending comparator comparing values after the primary comparator defined them equal. It uses * the [selector] function to transform values and then compares them with the given [comparator]. */ -@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(comparator, selector)", "kotlin.comparisons.thenByDescending")) +@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(comparator, selector)", "kotlin.comparisons.thenByDescending"), level = DeprecationLevel.ERROR) inline public fun Comparator.thenByDescending(comparator: Comparator, crossinline selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -197,13 +198,13 @@ inline public fun Comparator.thenByDescending(comparator: Comparator comparator(crossinline comparison: (T, T) -> Int) = Comparator { a, b -> comparison(a, b) } /** * Creates a comparator using the primary comparator and function to calculate a result of comparison. */ -@Deprecated("Use thenComparator from kotlin.comparisons package.", ReplaceWith("this.thenComparator(comparison)", "kotlin.comparisons.thenComparator")) +@Deprecated("Use thenComparator from kotlin.comparisons package.", ReplaceWith("this.thenComparator(comparison)", "kotlin.comparisons.thenComparator"), level = DeprecationLevel.ERROR) inline public fun Comparator.thenComparator(crossinline comparison: (T, T) -> Int): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -217,7 +218,7 @@ inline public fun Comparator.thenComparator(crossinline comparison: (T, T * Combines this comparator and the given [comparator] such that the latter is applied only * when the former considered values equal. */ -@Deprecated("Use then from kotlin.comparisons package.", ReplaceWith("this.then(comparator)", "kotlin.comparisons.then")) +@Deprecated("Use then from kotlin.comparisons package.", ReplaceWith("this.then(comparator)", "kotlin.comparisons.then"), level = DeprecationLevel.ERROR) public infix fun Comparator.then(comparator: Comparator): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -231,7 +232,7 @@ public infix fun Comparator.then(comparator: Comparator): Comparato * Combines this comparator and the given [comparator] such that the latter is applied only * when the former considered values equal. */ -@Deprecated("Use thenDescending from kotlin.comparisons package.", ReplaceWith("this.thenDescending(comparator)", "kotlin.comparisons.thenDescending")) +@Deprecated("Use thenDescending from kotlin.comparisons package.", ReplaceWith("this.thenDescending(comparator)", "kotlin.comparisons.thenDescending"), level = DeprecationLevel.ERROR) public infix fun Comparator.thenDescending(comparator: Comparator): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { @@ -246,7 +247,7 @@ public infix fun Comparator.thenDescending(comparator: Comparator): * Extends the given [comparator] of non-nullable values to a comparator of nullable values * considering `null` value less than any other value. */ -@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst(comparator)", "kotlin.comparisons.nullsFirst")) +@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst(comparator)", "kotlin.comparisons.nullsFirst"), level = DeprecationLevel.ERROR) public fun nullsFirst(comparator: Comparator): Comparator { return object: Comparator { override fun compare(a: T?, b: T?): Int { @@ -262,14 +263,14 @@ public fun nullsFirst(comparator: Comparator): Comparator { * Provides a comparator of nullable [Comparable] values * considering `null` value less than any other value. */ -@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst()", "kotlin.comparisons.nullsFirst")) +@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst()", "kotlin.comparisons.nullsFirst"), level = DeprecationLevel.ERROR) public fun > nullsFirst(): Comparator = nullsFirst(naturalOrder()) /** * Extends the given [comparator] of non-nullable values to a comparator of nullable values * considering `null` value greater than any other value. */ -@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast(comparator)", "kotlin.comparisons.nullsLast")) +@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast(comparator)", "kotlin.comparisons.nullsLast"), level = DeprecationLevel.ERROR) public fun nullsLast(comparator: Comparator): Comparator { return object: Comparator { override fun compare(a: T?, b: T?): Int { @@ -285,23 +286,23 @@ public fun nullsLast(comparator: Comparator): Comparator { * Provides a comparator of nullable [Comparable] values * considering `null` value greater than any other value. */ -@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast()", "kotlin.comparisons.nullsLast")) +@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast()", "kotlin.comparisons.nullsLast"), level = DeprecationLevel.ERROR) public fun > nullsLast(): Comparator = nullsLast(naturalOrder()) /** * Returns a comparator that compares [Comparable] objects in natural order. */ -@Deprecated("Use naturalOrder from kotlin.comparisons package.", ReplaceWith("naturalOrder()", "kotlin.comparisons.naturalOrder")) +@Deprecated("Use naturalOrder from kotlin.comparisons package.", ReplaceWith("naturalOrder()", "kotlin.comparisons.naturalOrder"), level = DeprecationLevel.ERROR) public fun > naturalOrder(): Comparator = NaturalOrderComparator as Comparator /** * Returns a comparator that compares [Comparable] objects in reversed natural order. */ -@Deprecated("Use reverseOrder from kotlin.comparisons package.", ReplaceWith("reverseOrder()", "kotlin.comparisons.reverseOrder")) +@Deprecated("Use reverseOrder from kotlin.comparisons package.", ReplaceWith("reverseOrder()", "kotlin.comparisons.reverseOrder"), level = DeprecationLevel.ERROR) public fun > reverseOrder(): Comparator = ReverseOrderComparator as Comparator /** Returns a comparator that imposes the reverse ordering of this comparator. */ -@Deprecated("Use reversed from kotlin.comparisons package.", ReplaceWith("this.reversed()", "kotlin.comparisons.reversed")) +@Deprecated("Use reversed from kotlin.comparisons package.", ReplaceWith("this.reversed()", "kotlin.comparisons.reversed"), level = DeprecationLevel.ERROR) public fun Comparator.reversed(): Comparator = when (this) { is ReversedComparator -> this.comparator NaturalOrderComparator -> ReverseOrderComparator as Comparator diff --git a/libraries/stdlib/test/collections/MapTest.kt b/libraries/stdlib/test/collections/MapTest.kt index 26d87955711..9c04ec32b0e 100644 --- a/libraries/stdlib/test/collections/MapTest.kt +++ b/libraries/stdlib/test/collections/MapTest.kt @@ -26,6 +26,7 @@ class MapTest { assertEquals("x", d) } + @Suppress("INVISIBLE_MEMBER") @test fun getOrImplicitDefault() { val data: MutableMap = hashMapOf("bar" to 1) assertTrue(assertFails { data.getOrImplicitDefault("foo") } is NoSuchElementException) @@ -337,43 +338,6 @@ class MapTest { @test fun plusMap() = testPlus { it + mapOf("C" to 3, "B" to 4) } - fun testMinus(doMinus: (Map) -> Map) { - val original = mapOf("A" to 1, "B" to 2) - val shortened = doMinus(original) - assertEquals("A" to 1, shortened.entries.single().toPair()) - } - - @test fun minus() = testMinus { it - "B" - "C" } - - @test fun minusList() = testMinus { it - listOf("B", "C") } - - @test fun minusArray() = testMinus { it - arrayOf("B", "C") } - - @test fun minusSequence() = testMinus { it - sequenceOf("B", "C") } - - @test fun minusSet() = testMinus { it - setOf("B", "C") } - - - - fun testMinusAssign(doMinusAssign: (MutableMap) -> Unit) { - val original = hashMapOf("A" to 1, "B" to 2) - doMinusAssign(original) - assertEquals("A" to 1, original.entries.single().toPair()) - } - -/* - @test fun minusAssign() = testMinusAssign { - it.keys -= "B" - it.keys -= "C" - } - - @test fun minusAssignList() = testMinusAssign { it.keys -= listOf("B", "C") } - - @test fun minusAssignArray() = testMinusAssign { it.keys -= arrayOf("B", "C") } - - @test fun minusAssignSequence() = testMinusAssign { it.keys -= sequenceOf("B", "C") } -*/ - fun testIdempotent(operation: (Map) -> Map) { val original = mapOf("A" to 1, "B" to 2) @@ -389,16 +353,12 @@ class MapTest { @test fun plusEmptyList() = testIdempotent { it + listOf() } -// @test fun minusEmptyList() = testIdempotent { it - listOf() } @test fun plusEmptySet() = testIdempotent { it + setOf() } -// @test fun minusEmptySet() = testIdempotent { it - setOf() } @test fun plusAssignEmptyList() = testIdempotentAssign { it += listOf() } -// @test fun minusAssignEmptyList() = testIdempotentAssign { it -= listOf() } @test fun plusAssignEmptySet() = testIdempotentAssign { it += setOf() } -// @test fun minusAssignEmptySet() = testIdempotentAssign { it -= setOf() } } diff --git a/libraries/stdlib/test/collections/SequenceJVMTest.kt b/libraries/stdlib/test/collections/SequenceJVMTest.kt index 1ccc8eb315b..1a5fc2b2705 100644 --- a/libraries/stdlib/test/collections/SequenceJVMTest.kt +++ b/libraries/stdlib/test/collections/SequenceJVMTest.kt @@ -9,18 +9,18 @@ class SequenceJVMTest { val src: Sequence = listOf(1, 2, 3.toDouble(), "abc", "cde").asSequence() val intValues: Sequence = src.filterIsInstance() - assertEquals(listOf(1, 2), intValues.toArrayList()) + assertEquals(listOf(1, 2), intValues.toList()) val doubleValues: Sequence = src.filterIsInstance() - assertEquals(listOf(3.0), doubleValues.toArrayList()) + assertEquals(listOf(3.0), doubleValues.toList()) val stringValues: Sequence = src.filterIsInstance() - assertEquals(listOf("abc", "cde"), stringValues.toArrayList()) + assertEquals(listOf("abc", "cde"), stringValues.toList()) val anyValues: Sequence = src.filterIsInstance() - assertEquals(src.toList(), anyValues.toArrayList()) + assertEquals(src.toList(), anyValues.toList()) val charValues: Sequence = src.filterIsInstance() - assertEquals(0, charValues.toArrayList().size) + assertEquals(0, charValues.toList().size) } } diff --git a/libraries/stdlib/test/io/ReadWrite.kt b/libraries/stdlib/test/io/ReadWrite.kt index 4351ce2ec66..9a556dfad1b 100644 --- a/libraries/stdlib/test/io/ReadWrite.kt +++ b/libraries/stdlib/test/io/ReadWrite.kt @@ -155,17 +155,17 @@ class LineIteratorTest { @test fun useLines() { // TODO we should maybe zap the useLines approach as it encourages // use of iterators which don't close the underlying stream - val list1 = sample().useLines { it.toArrayList() } - val list2 = sample().useLines>{ it.toArrayList() } + val list1 = sample().useLines { it.toList() } + val list2 = sample().useLines>{ it.toCollection(arrayListOf()) } - assertEquals(arrayListOf("Hello", "World"), list1) - assertEquals(arrayListOf("Hello", "World"), list2) + assertEquals(listOf("Hello", "World"), list1) + assertEquals(listOf("Hello", "World"), list2) } @test fun manualClose() { val reader = sample().buffered() try { - val list = reader.lineSequence().toArrayList() + val list = reader.lineSequence().toList() assertEquals(arrayListOf("Hello", "World"), list) } finally { reader.close() @@ -174,19 +174,19 @@ class LineIteratorTest { @test fun boundaryConditions() { var reader = StringReader("").buffered() - assertEquals(ArrayList(), reader.lineSequence().toArrayList()) + assertEquals(emptyList(), reader.lineSequence().toList()) reader.close() reader = StringReader(" ").buffered() - assertEquals(arrayListOf(" "), reader.lineSequence().toArrayList()) + assertEquals(listOf(" "), reader.lineSequence().toList()) reader.close() reader = StringReader(" \n").buffered() - assertEquals(arrayListOf(" "), reader.lineSequence().toArrayList()) + assertEquals(listOf(" "), reader.lineSequence().toList()) reader.close() reader = StringReader(" \n ").buffered() - assertEquals(arrayListOf(" ", " "), reader.lineSequence().toArrayList()) + assertEquals(listOf(" ", " "), reader.lineSequence().toList()) reader.close() } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt index 295f211aaa9..5a4592b79ed 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt @@ -67,7 +67,7 @@ fun snapshots(): List { body(Iterables) { """ if (this is Collection) - return this.toArrayList() + return ArrayList(this) return toCollection(ArrayList()) """ } @@ -81,7 +81,7 @@ fun snapshots(): List { return list """ } - deprecate(Deprecation("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", "toCollection(arrayListOf())")) + deprecate(Deprecation("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", "toCollection(arrayListOf())", level = DeprecationLevel.ERROR)) } templates add f("toMutableList()") { @@ -135,7 +135,7 @@ fun snapshots(): List { typeParam("V") returns("Map") annotations("""@kotlin.jvm.JvmName("toMapOfPairs")""") - deprecate(Deprecation("Use associate instead.", replaceWith = "associate(transform)")) + deprecate(Deprecation("Use associate instead.", replaceWith = "associate(transform)", level = DeprecationLevel.ERROR)) } templates add f("associate(transform: (T) -> Pair)") { @@ -205,7 +205,7 @@ fun snapshots(): List { typeParam("K") returns("Map") include(CharSequences) - deprecate(Deprecation("Use associateBy instead.", replaceWith = "associateBy(selector)")) + deprecate(Deprecation("Use associateBy instead.", replaceWith = "associateBy(selector)", level = DeprecationLevel.ERROR)) } templates add f("associateBy(keySelector: (T) -> K)") { @@ -287,7 +287,7 @@ fun snapshots(): List { """ } returns("Map") - deprecate(Deprecation("Use associateBy instead.", "associateBy(selector, transform)")) + deprecate(Deprecation("Use associateBy instead.", "associateBy(selector, transform)", level = DeprecationLevel.ERROR)) } templates add f("toMapBy(selector: (T) -> K, transform: (T) -> V)") { @@ -296,7 +296,7 @@ fun snapshots(): List { typeParam("V") include(CharSequences) returns("Map") - deprecate(Deprecation("Use associateBy instead.", replaceWith = "associateBy(selector, transform)")) + deprecate(Deprecation("Use associateBy instead.", replaceWith = "associateBy(selector, transform)", level = DeprecationLevel.ERROR)) } templates add f("associateBy(keySelector: (T) -> K, valueTransform: (T) -> V)") {