Rename extension toStringWithTrace to stackTraceToString
#KT-37603
This commit is contained in:
@@ -128,7 +128,8 @@ internal class KotlinNothingValueException : RuntimeException {
|
||||
* - the detailed description of each throwable in the [Throwable.cause] chain.
|
||||
*/
|
||||
@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
|
||||
* suppressed in order to deliver this exception.
|
||||
|
||||
@@ -15,7 +15,7 @@ package kotlin
|
||||
* - the detailed description of each throwable in the [Throwable.cause] chain.
|
||||
*/
|
||||
@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
|
||||
|
||||
@@ -14,21 +14,21 @@ import java.io.StringWriter
|
||||
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
|
||||
@kotlin.internal.InlineOnly
|
||||
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
|
||||
@kotlin.internal.InlineOnly
|
||||
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
|
||||
@kotlin.internal.InlineOnly
|
||||
@@ -52,7 +52,7 @@ public val Throwable.stackTrace: Array<StackTraceElement>
|
||||
* - the detailed description of each throwable in the [Throwable.cause] chain.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public actual fun Throwable.toStringWithTrace(): String {
|
||||
public actual fun Throwable.stackTraceToString(): String {
|
||||
val sw = StringWriter()
|
||||
val pw = PrintWriter(sw)
|
||||
printStackTrace(pw)
|
||||
|
||||
@@ -53,7 +53,7 @@ class ExceptionJVMTest {
|
||||
}
|
||||
|
||||
fun assertToStringWithTrace(t: Throwable) {
|
||||
val content = t.toStringWithTrace()
|
||||
val content = t.stackTraceToString()
|
||||
comparePrintedThrowableResult(t, content)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class ExceptionJVMTest {
|
||||
assertSame(e1, e2.cause)
|
||||
assertSame(e2, e1.cause)
|
||||
testOnJvm7AndAbove {
|
||||
val trace = e2.toStringWithTrace()
|
||||
val trace = e2.stackTraceToString()
|
||||
assertTrue("CIRCULAR REFERENCE" in trace, trace)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class ExceptionTest {
|
||||
e.apply { addSuppressed(suppressedError(2)) }
|
||||
}
|
||||
|
||||
val topLevelTrace = e.toStringWithTrace()
|
||||
val topLevelTrace = e.stackTraceToString()
|
||||
fun assertInTrace(value: Any) {
|
||||
if (value.toString() !in topLevelTrace) {
|
||||
fail("Expected top level trace: $topLevelTrace\n\nto contain: $value")
|
||||
@@ -153,7 +153,7 @@ class ExceptionTest {
|
||||
e3.addSuppressed(e1)
|
||||
e2.addSuppressed(e1)
|
||||
|
||||
val topLevelTrace = e1.toStringWithTrace()
|
||||
val topLevelTrace = e1.stackTraceToString()
|
||||
fun assertAppearsInTrace(value: Any, count: Int) {
|
||||
if (Regex.fromLiteral(value.toString()).findAll(topLevelTrace).count() != count) {
|
||||
fail("Expected to find $value $count times in $topLevelTrace")
|
||||
|
||||
+1
-1
@@ -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 getStackTrace (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user