From 705c9089f07d44119035d273b3e185e60f491dbd Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 3 Jun 2015 19:41:03 +0300 Subject: [PATCH] Provide replacement for methods deprecated in favor of SAM-constructors. Provide replacement for isNotEmpty on nullable receiver. JS: Provide SAM-like constructor for Runnable. --- js/js.libraries/src/core/javalang.kt | 4 ++++ libraries/stdlib/src/kotlin/deprecated/Deprecated.kt | 10 ++-------- .../stdlib/src/kotlin/deprecated/DeprecatedJVM.kt | 8 ++------ libraries/stdlib/src/kotlin/text/Strings.kt | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/js/js.libraries/src/core/javalang.kt b/js/js.libraries/src/core/javalang.kt index b7db2beaeec..2770a1c32ec 100644 --- a/js/js.libraries/src/core/javalang.kt +++ b/js/js.libraries/src/core/javalang.kt @@ -29,6 +29,10 @@ public trait Runnable { public open fun run() : Unit; } +public fun Runnable(action: () -> Unit): Runnable = object : Runnable { + override fun run() = action() +} + library public trait Appendable { public open fun append(csq: CharSequence?): Appendable diff --git a/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt b/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt index 2bfaf07990e..d6d8ffe42db 100644 --- a/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt +++ b/libraries/stdlib/src/kotlin/deprecated/Deprecated.kt @@ -52,14 +52,8 @@ public inline fun String.findNot(predicate: (Char) -> Boolean): Char? { /** * A helper method for creating a [[Runnable]] from a function */ -deprecated("Use SAM constructor: Runnable(...)") -public /*inline*/ fun runnable(action: () -> Unit): Runnable { - return object: Runnable { - public override fun run() { - action() - } - } -} +deprecated("Use SAM constructor: Runnable(...)", ReplaceWith("Runnable(action)")) +public /*inline*/ fun runnable(action: () -> Unit): Runnable = Runnable(action) deprecated("Use forEachIndexed instead.", ReplaceWith("forEachIndexed(operation)")) public inline fun List.forEachWithIndex(operation: (Int, T) -> Unit): Unit = forEachIndexed(operation) diff --git a/libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt b/libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt index 0b804a2f061..f02f4bcee3f 100644 --- a/libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt +++ b/libraries/stdlib/src/kotlin/deprecated/DeprecatedJVM.kt @@ -31,12 +31,8 @@ public fun sortedMap(vararg values: Pair): SortedMap = sorted /** * A helper method for creating a [[Callable]] from a function */ -deprecated("Use SAM constructor: Callable(...)") -public /*inline*/ fun callable(action: () -> T): Callable { - return object: Callable { - public override fun call() = action() - } -} +deprecated("Use SAM constructor: Callable(...)", ReplaceWith("Callable(action)", "java.util.concurrent.Callable")) +public /*inline*/ fun callable(action: () -> T): Callable = Callable(action) deprecated("Use length() instead", ReplaceWith("length()")) public val String.size: Int diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index da432ddd0a9..d143cab1224 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -149,7 +149,7 @@ public fun String.padEnd(length: Int, padChar: Char = ' '): String { } /** Returns `true` if the string is not `null` and not empty */ -deprecated("Use !isNullOrEmpty() or isNullOrEmpty().not() for nullable strings.") +deprecated("Use !isNullOrEmpty() or isNullOrEmpty().not() for nullable strings.", ReplaceWith("this != null && this.isNotEmpty()")) platformName("isNotEmptyNullable") public fun String?.isNotEmpty(): Boolean = this != null && this.length() > 0