From e5b0d2e34f5bd711f802a7290120dc73aafc6019 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 14 Dec 2018 21:27:26 +0900 Subject: [PATCH] Refactoring: Extract list field search --- .../kotlin/idea/debugger/KotlinStackFrame.kt | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/KotlinStackFrame.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/KotlinStackFrame.kt index 577ce274e7b..5aebe6cca58 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/KotlinStackFrame.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/KotlinStackFrame.kt @@ -99,18 +99,26 @@ class KotlinStackFrame(frame: StackFrameProxyImpl) : JavaStackFrame(StackFrameDe } fun remove() { + val (names, values) = getLists() ?: return + names.removeAt(index) + values.removeAt(index) + } + + private fun getLists(): Lists? { if (children.size() != size) { throw IllegalStateException("Children list was modified") } - var namesList: MutableList<*>? = null - var valuesList: MutableList<*>? = null + var namesList: MutableList? = null + var valuesList: MutableList? = null for (field in XValueChildrenList::class.java.declaredFields) { val mods = field.modifiers if (Modifier.isPrivate(mods) && Modifier.isFinal(mods) && !Modifier.isStatic(mods) && field.type == List::class.java) { - val list = (field.getSafe(children) as? MutableList<*>)?.takeIf { it.size == size } ?: continue - if (list[index] == name) { + @Suppress("UNCHECKED_CAST") + val list = (field.getSafe(children) as? MutableList)?.takeIf { it.size == size } ?: continue + + if (list[index] == THIS_NAME) { namesList = list } else if (list[index] === value) { valuesList = list @@ -118,21 +126,19 @@ class KotlinStackFrame(frame: StackFrameProxyImpl) : JavaStackFrame(StackFrameDe } if (namesList != null && valuesList != null) { - break + return Lists(namesList, valuesList) } } - if (namesList == null || valuesList == null) { - org.jetbrains.kotlin.idea.debugger.evaluate.LOG.error( - "Can't find name/value lists, existing fields: " - + Arrays.toString(XValueChildrenList::class.java.declaredFields) - ) - return - } + DebuggerLog.error( + "Can't find name/value lists, existing fields: " + + Arrays.toString(XValueChildrenList::class.java.declaredFields) + ) - namesList.removeAt(index) - valuesList.removeAt(index) + return null } + + private data class Lists(val names: MutableList, val values: MutableList) } override fun getVisibleVariables(): List {