Minor: extract wrapEvaluateException()

This commit is contained in:
Yan Zhulanow
2020-01-16 21:10:20 +09:00
parent 3027fab238
commit f6b62f2299
3 changed files with 13 additions and 15 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.debugger.safeLineNumber
import org.jetbrains.kotlin.idea.debugger.safeLocation import org.jetbrains.kotlin.idea.debugger.safeLocation
import org.jetbrains.kotlin.idea.debugger.safeMethod import org.jetbrains.kotlin.idea.debugger.safeMethod
class CoroutineBuilder(val suspendContext: XSuspendContext) { class CoroutineBuilder(val suspendContext: XSuspendContext) {
private val coroutineStackFrameProvider = CoroutineAsyncStackTraceProvider() private val coroutineStackFrameProvider = CoroutineAsyncStackTraceProvider()
val debugProcess = (suspendContext as SuspendContextImpl).debugProcess val debugProcess = (suspendContext as SuspendContextImpl).debugProcess
@@ -13,12 +13,9 @@ import com.intellij.xdebugger.frame.XNamedValue
import com.intellij.xdebugger.frame.XStackFrame import com.intellij.xdebugger.frame.XStackFrame
import com.sun.jdi.Location import com.sun.jdi.Location
import com.sun.jdi.ObjectReference import com.sun.jdi.ObjectReference
import org.jetbrains.kotlin.idea.debugger.*
import org.jetbrains.kotlin.idea.debugger.coroutine.util.EmptyStackFrameDescriptor import org.jetbrains.kotlin.idea.debugger.coroutine.util.EmptyStackFrameDescriptor
import org.jetbrains.kotlin.idea.debugger.coroutine.util.logger import org.jetbrains.kotlin.idea.debugger.coroutine.util.logger
import org.jetbrains.kotlin.idea.debugger.safeLineNumber
import org.jetbrains.kotlin.idea.debugger.safeMethod
import org.jetbrains.kotlin.idea.debugger.safeSourceLineNumber
import org.jetbrains.kotlin.idea.debugger.safeSourceName
class CreationCoroutineStackFrameItem( class CreationCoroutineStackFrameItem(
val frame: StackFrameProxyImpl, val frame: StackFrameProxyImpl,
@@ -64,6 +61,6 @@ sealed class CoroutineStackFrameItem(val location: Location, val spilledVariable
fun uniqueId(): String { fun uniqueId(): String {
return location.safeSourceName() + ":" + location.safeMethod().toString() + ":" + return location.safeSourceName() + ":" + location.safeMethod().toString() + ":" +
location.safeLineNumber() + ":" + location.safeSourceLineNumber() location.safeLineNumber() + ":" + location.safeKotlinPreferredLineNumber()
} }
} }
@@ -60,19 +60,11 @@ fun Method.safeArguments(): List<LocalVariable>? {
} }
fun StackFrameProxy.safeLocation(): Location? { fun StackFrameProxy.safeLocation(): Location? {
return try { return wrapEvaluateException { this.location() }
this.location()
} catch (e: EvaluateException) {
null
}
} }
fun StackFrameProxy.safeStackFrame(): StackFrame? { fun StackFrameProxy.safeStackFrame(): StackFrame? {
return try { return wrapEvaluateException { this.stackFrame }
this.stackFrame
} catch (e: EvaluateException) {
null
}
} }
fun Location.safeSourceName(): String? { fun Location.safeSourceName(): String? {
@@ -118,6 +110,14 @@ fun Field.safeType(): Type? {
return wrapClassNotLoadedException { type() } return wrapClassNotLoadedException { type() }
} }
private inline fun <T> wrapEvaluateException(block: () -> T): T? {
return try {
block()
} catch (e: EvaluateException) {
null
}
}
private inline fun <T> wrapAbsentInformationException(block: () -> T): T? { private inline fun <T> wrapAbsentInformationException(block: () -> T): T? {
return try { return try {
block() block()