|
2 | 2 | * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
|
3 | 3 | */
|
4 | 4 |
|
| 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. */ |
5 | 8 | package _COROUTINE
|
6 | 9 |
|
7 | 10 | /**
|
8 | 11 | * 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. |
9 | 19 | */
|
10 | 20 | internal class ArtificialStackFrames {
|
11 | 21 | /**
|
@@ -35,10 +45,20 @@ internal class ArtificialStackFrames {
|
35 | 45 | fun coroutineBoundary(): StackTraceElement = Exception().artificialFrame(_BOUNDARY::class.java.simpleName)
|
36 | 46 | }
|
37 | 47 |
|
| 48 | +// These are needed for the IDE navigation to detect that this file does contain the definition. |
38 | 49 | private class _CREATION
|
39 | 50 | private class _BOUNDARY
|
40 | 51 |
|
41 | 52 | internal val ARTIFICIAL_FRAME_PACKAGE_NAME = "_COROUTINE"
|
42 | 53 |
|
| 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 | + */ |
43 | 63 | private fun Throwable.artificialFrame(name: String): StackTraceElement =
|
44 | 64 | with(stackTrace[0]) { StackTraceElement(ARTIFICIAL_FRAME_PACKAGE_NAME + "." + name, "_", fileName, lineNumber) }
|
0 commit comments