Rename extension toStringWithTrace to stackTraceToString

#KT-37603
This commit is contained in:
Ilya Gorbunov
2020-04-04 02:04:30 +03:00
parent 4cc9909a70
commit 408b441a71
6 changed files with 12 additions and 11 deletions
@@ -128,7 +128,8 @@ internal class KotlinNothingValueException : RuntimeException {
* - the detailed description of each throwable in the [Throwable.cause] chain. * - the detailed description of each throwable in the [Throwable.cause] chain.
*/ */
@SinceKotlin("1.4") @SinceKotlin("1.4")
public expect fun Throwable.toStringWithTrace(): String public expect fun Throwable.stackTraceToString(): String
/** /**
* When supported by the platform, adds the specified exception to the list of exceptions that were * When supported by the platform, adds the specified exception to the list of exceptions that were
* suppressed in order to deliver this exception. * suppressed in order to deliver this exception.
@@ -15,7 +15,7 @@ package kotlin
* - the detailed description of each throwable in the [Throwable.cause] chain. * - the detailed description of each throwable in the [Throwable.cause] chain.
*/ */
@SinceKotlin("1.4") @SinceKotlin("1.4")
public actual fun Throwable.toStringWithTrace(): String = ExceptionTraceBuilder().buildFor(this) public actual fun Throwable.stackTraceToString(): String = ExceptionTraceBuilder().buildFor(this)
/** /**
* Adds the specified exception to the list of exceptions that were * Adds the specified exception to the list of exceptions that were
@@ -14,21 +14,21 @@ import java.io.StringWriter
import kotlin.internal.* import kotlin.internal.*
/** /**
* Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the standard error output. * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the standard error output.
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun Throwable.printStackTrace(): Unit = (this as java.lang.Throwable).printStackTrace() public inline fun Throwable.printStackTrace(): Unit = (this as java.lang.Throwable).printStackTrace()
/** /**
* Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the specified [writer]. * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the specified [writer].
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun Throwable.printStackTrace(writer: PrintWriter): Unit = (this as java.lang.Throwable).printStackTrace(writer) public inline fun Throwable.printStackTrace(writer: PrintWriter): Unit = (this as java.lang.Throwable).printStackTrace(writer)
/** /**
* Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the specified [stream]. * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the specified [stream].
*/ */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
@@ -52,7 +52,7 @@ public val Throwable.stackTrace: Array<StackTraceElement>
* - the detailed description of each throwable in the [Throwable.cause] chain. * - the detailed description of each throwable in the [Throwable.cause] chain.
*/ */
@SinceKotlin("1.4") @SinceKotlin("1.4")
public actual fun Throwable.toStringWithTrace(): String { public actual fun Throwable.stackTraceToString(): String {
val sw = StringWriter() val sw = StringWriter()
val pw = PrintWriter(sw) val pw = PrintWriter(sw)
printStackTrace(pw) printStackTrace(pw)
@@ -53,7 +53,7 @@ class ExceptionJVMTest {
} }
fun assertToStringWithTrace(t: Throwable) { fun assertToStringWithTrace(t: Throwable) {
val content = t.toStringWithTrace() val content = t.stackTraceToString()
comparePrintedThrowableResult(t, content) comparePrintedThrowableResult(t, content)
} }
@@ -88,7 +88,7 @@ class ExceptionJVMTest {
assertSame(e1, e2.cause) assertSame(e1, e2.cause)
assertSame(e2, e1.cause) assertSame(e2, e1.cause)
testOnJvm7AndAbove { testOnJvm7AndAbove {
val trace = e2.toStringWithTrace() val trace = e2.stackTraceToString()
assertTrue("CIRCULAR REFERENCE" in trace, trace) assertTrue("CIRCULAR REFERENCE" in trace, trace)
} }
} }
+2 -2
View File
@@ -109,7 +109,7 @@ class ExceptionTest {
e.apply { addSuppressed(suppressedError(2)) } e.apply { addSuppressed(suppressedError(2)) }
} }
val topLevelTrace = e.toStringWithTrace() val topLevelTrace = e.stackTraceToString()
fun assertInTrace(value: Any) { fun assertInTrace(value: Any) {
if (value.toString() !in topLevelTrace) { if (value.toString() !in topLevelTrace) {
fail("Expected top level trace: $topLevelTrace\n\nto contain: $value") fail("Expected top level trace: $topLevelTrace\n\nto contain: $value")
@@ -153,7 +153,7 @@ class ExceptionTest {
e3.addSuppressed(e1) e3.addSuppressed(e1)
e2.addSuppressed(e1) e2.addSuppressed(e1)
val topLevelTrace = e1.toStringWithTrace() val topLevelTrace = e1.stackTraceToString()
fun assertAppearsInTrace(value: Any, count: Int) { fun assertAppearsInTrace(value: Any, count: Int) {
if (Regex.fromLiteral(value.toString()).findAll(topLevelTrace).count() != count) { if (Regex.fromLiteral(value.toString()).findAll(topLevelTrace).count() != count) {
fail("Expected to find $value $count times in $topLevelTrace") fail("Expected to find $value $count times in $topLevelTrace")
@@ -22,7 +22,7 @@ public final class kotlin/ExceptionsKt {
public static final fun addSuppressed (Ljava/lang/Throwable;Ljava/lang/Throwable;)V public static final fun addSuppressed (Ljava/lang/Throwable;Ljava/lang/Throwable;)V
public static final fun getStackTrace (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement; public static final fun getStackTrace (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
public static final fun getSuppressedExceptions (Ljava/lang/Throwable;)Ljava/util/List; public static final fun getSuppressedExceptions (Ljava/lang/Throwable;)Ljava/util/List;
public static final fun toStringWithTrace (Ljava/lang/Throwable;)Ljava/lang/String; public static final fun stackTraceToString (Ljava/lang/Throwable;)Ljava/lang/String;
} }
public abstract interface annotation class kotlin/Experimental : java/lang/annotation/Annotation { public abstract interface annotation class kotlin/Experimental : java/lang/annotation/Annotation {