Refactoring: Extract wrapping 'try' expressions
This commit is contained in:
@@ -12,14 +12,7 @@ import com.intellij.debugger.jdi.StackFrameProxyImpl
|
|||||||
import com.sun.jdi.*
|
import com.sun.jdi.*
|
||||||
|
|
||||||
fun StackFrameProxyImpl.safeVisibleVariables(): List<LocalVariableProxyImpl> {
|
fun StackFrameProxyImpl.safeVisibleVariables(): List<LocalVariableProxyImpl> {
|
||||||
return try {
|
return wrapAbsentInformationException { visibleVariables() } ?: emptyList()
|
||||||
visibleVariables()
|
|
||||||
} catch (e: AbsentInformationEvaluateException) {
|
|
||||||
// Current implementation of visibleVariables() wraps an AbsentInformationException into EvaluateException
|
|
||||||
emptyList()
|
|
||||||
} catch (e: AbsentInformationException) {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Method.safeAllLineLocations(): List<Location> {
|
fun Method.safeAllLineLocations(): List<Location> {
|
||||||
@@ -31,35 +24,19 @@ fun ReferenceType.safeAllLineLocations(): List<Location> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ReferenceType.safeSourceName(): String? {
|
fun ReferenceType.safeSourceName(): String? {
|
||||||
return try {
|
return wrapAbsentInformationException { sourceName() }
|
||||||
sourceName()
|
|
||||||
} catch (e: AbsentInformationException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Method.safeLocationsOfLine(line: Int): List<Location> {
|
fun Method.safeLocationsOfLine(line: Int): List<Location> {
|
||||||
return try {
|
return wrapAbsentInformationException { locationsOfLine(line) } ?: emptyList()
|
||||||
locationsOfLine(line)
|
|
||||||
} catch (e: AbsentInformationException) {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Method.safeVariables(): List<LocalVariable>? {
|
fun Method.safeVariables(): List<LocalVariable>? {
|
||||||
return try {
|
return wrapAbsentInformationException { variables() }
|
||||||
variables()
|
|
||||||
} catch (e: AbsentInformationException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Method.safeArguments(): List<LocalVariable>? {
|
fun Method.safeArguments(): List<LocalVariable>? {
|
||||||
return try {
|
return wrapAbsentInformationException { arguments() }
|
||||||
arguments()
|
|
||||||
} catch (e: AbsentInformationException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Location.safeSourceName(): String? {
|
fun Location.safeSourceName(): String? {
|
||||||
@@ -85,16 +62,26 @@ fun Location.safeMethod(): Method? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun LocalVariableProxyImpl.safeType(): Type? {
|
fun LocalVariableProxyImpl.safeType(): Type? {
|
||||||
|
return wrapClassNotLoadedException { type }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Field.safeType(): Type? {
|
||||||
|
return wrapClassNotLoadedException { type() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <T> wrapAbsentInformationException(block: () -> T): T? {
|
||||||
return try {
|
return try {
|
||||||
type
|
block()
|
||||||
} catch (e: ClassNotLoadedException) {
|
} catch (e: AbsentInformationException) {
|
||||||
|
null
|
||||||
|
} catch (e: AbsentInformationEvaluateException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Field.safeType(): Type? {
|
private inline fun <T> wrapClassNotLoadedException(block: () -> T): T? {
|
||||||
return try {
|
return try {
|
||||||
type()
|
block()
|
||||||
} catch (e: ClassNotLoadedException) {
|
} catch (e: ClassNotLoadedException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user