Skip to content

Commit 119e84a

Browse files
committed
Improve docs
1 parent 3bd0554 commit 119e84a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

kotlinx-coroutines-core/jvm/src/debug/CoroutineDebugging.kt

+20
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
/* This package name is like this so that
6+
1) the artificial stack frames look pretty, and
7+
2) the IDE reliably navigates to this file. */
58
package _COROUTINE
69

710
/**
811
* A collection of artificial stack trace elements to be included in stack traces by the coroutines machinery.
12+
*
13+
* There are typically two ways in which one can encounter an artificial stack frame:
14+
* 1. By using the debug mode, via the stacktrace recovery mechanism; see
15+
* https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/topics/debugging.md#stacktrace-recovery. The usual way
16+
* to enable the debug mode is with the [kotlinx.coroutines.DEBUG_PROPERTY_NAME] system property.
17+
* 2. By looking at the output of DebugProbes; see
18+
* https://github.com/Kotlin/kotlinx.coroutines/tree/master/kotlinx-coroutines-debug.
919
*/
1020
internal class ArtificialStackFrames {
1121
/**
@@ -35,10 +45,20 @@ internal class ArtificialStackFrames {
3545
fun coroutineBoundary(): StackTraceElement = Exception().artificialFrame(_BOUNDARY::class.java.simpleName)
3646
}
3747

48+
// These are needed for the IDE navigation to detect that this file does contain the definition.
3849
private class _CREATION
3950
private class _BOUNDARY
4051

4152
internal val ARTIFICIAL_FRAME_PACKAGE_NAME = "_COROUTINE"
4253

54+
/**
55+
* Forms an artificial stack frame with the given class name.
56+
*
57+
* It consists of the following parts:
58+
* 1. The package name, it seems, is needed for the IDE to detect stack trace elements reliably. It is `_COROUTINE` since
59+
* this is a valid identifier.
60+
* 2. Class names represents what type of artificial frame this is.
61+
* 3. The method name is `_`. The methods not being present in class definitions does not seem to affect navigation.
62+
*/
4363
private fun Throwable.artificialFrame(name: String): StackTraceElement =
4464
with(stackTrace[0]) { StackTraceElement(ARTIFICIAL_FRAME_PACKAGE_NAME + "." + name, "_", fileName, lineNumber) }

0 commit comments

Comments
 (0)