From 757fc421f793b91b91507b2fb5dd14ea76921e44 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 14 Dec 2018 19:25:53 +0900 Subject: [PATCH] Refactoring: Extract wrapping 'try' expressions --- .../kotlin/idea/debugger/safeUtil.kt | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/safeUtil.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/safeUtil.kt index 1f9e26d2ebd..4cf8ddd4cfb 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/safeUtil.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/safeUtil.kt @@ -12,14 +12,7 @@ import com.intellij.debugger.jdi.StackFrameProxyImpl import com.sun.jdi.* fun StackFrameProxyImpl.safeVisibleVariables(): List { - return try { - visibleVariables() - } catch (e: AbsentInformationEvaluateException) { - // Current implementation of visibleVariables() wraps an AbsentInformationException into EvaluateException - emptyList() - } catch (e: AbsentInformationException) { - emptyList() - } + return wrapAbsentInformationException { visibleVariables() } ?: emptyList() } fun Method.safeAllLineLocations(): List { @@ -31,35 +24,19 @@ fun ReferenceType.safeAllLineLocations(): List { } fun ReferenceType.safeSourceName(): String? { - return try { - sourceName() - } catch (e: AbsentInformationException) { - null - } + return wrapAbsentInformationException { sourceName() } } fun Method.safeLocationsOfLine(line: Int): List { - return try { - locationsOfLine(line) - } catch (e: AbsentInformationException) { - emptyList() - } + return wrapAbsentInformationException { locationsOfLine(line) } ?: emptyList() } fun Method.safeVariables(): List? { - return try { - variables() - } catch (e: AbsentInformationException) { - null - } + return wrapAbsentInformationException { variables() } } fun Method.safeArguments(): List? { - return try { - arguments() - } catch (e: AbsentInformationException) { - null - } + return wrapAbsentInformationException { arguments() } } fun Location.safeSourceName(): String? { @@ -85,16 +62,26 @@ fun Location.safeMethod(): Method? { } fun LocalVariableProxyImpl.safeType(): Type? { + return wrapClassNotLoadedException { type } +} + +fun Field.safeType(): Type? { + return wrapClassNotLoadedException { type() } +} + +private inline fun wrapAbsentInformationException(block: () -> T): T? { return try { - type - } catch (e: ClassNotLoadedException) { + block() + } catch (e: AbsentInformationException) { + null + } catch (e: AbsentInformationEvaluateException) { null } } -fun Field.safeType(): Type? { +private inline fun wrapClassNotLoadedException(block: () -> T): T? { return try { - type() + block() } catch (e: ClassNotLoadedException) { null }