Refactoring: Extract list field search

This commit is contained in:
Yan Zhulanow
2018-12-14 21:27:26 +09:00
parent c5061e7997
commit e5b0d2e34f
@@ -99,18 +99,26 @@ class KotlinStackFrame(frame: StackFrameProxyImpl) : JavaStackFrame(StackFrameDe
} }
fun remove() { fun remove() {
val (names, values) = getLists() ?: return
names.removeAt(index)
values.removeAt(index)
}
private fun getLists(): Lists? {
if (children.size() != size) { if (children.size() != size) {
throw IllegalStateException("Children list was modified") throw IllegalStateException("Children list was modified")
} }
var namesList: MutableList<*>? = null var namesList: MutableList<Any?>? = null
var valuesList: MutableList<*>? = null var valuesList: MutableList<Any?>? = null
for (field in XValueChildrenList::class.java.declaredFields) { for (field in XValueChildrenList::class.java.declaredFields) {
val mods = field.modifiers val mods = field.modifiers
if (Modifier.isPrivate(mods) && Modifier.isFinal(mods) && !Modifier.isStatic(mods) && field.type == List::class.java) { 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 @Suppress("UNCHECKED_CAST")
if (list[index] == name) { val list = (field.getSafe(children) as? MutableList<Any?>)?.takeIf { it.size == size } ?: continue
if (list[index] == THIS_NAME) {
namesList = list namesList = list
} else if (list[index] === value) { } else if (list[index] === value) {
valuesList = list valuesList = list
@@ -118,21 +126,19 @@ class KotlinStackFrame(frame: StackFrameProxyImpl) : JavaStackFrame(StackFrameDe
} }
if (namesList != null && valuesList != null) { if (namesList != null && valuesList != null) {
break return Lists(namesList, valuesList)
} }
} }
if (namesList == null || valuesList == null) { DebuggerLog.error(
org.jetbrains.kotlin.idea.debugger.evaluate.LOG.error( "Can't find name/value lists, existing fields: "
"Can't find name/value lists, existing fields: " + Arrays.toString(XValueChildrenList::class.java.declaredFields)
+ Arrays.toString(XValueChildrenList::class.java.declaredFields) )
)
return
}
namesList.removeAt(index) return null
valuesList.removeAt(index)
} }
private data class Lists(val names: MutableList<Any?>, val values: MutableList<Any?>)
} }
override fun getVisibleVariables(): List<LocalVariableProxyImpl> { override fun getVisibleVariables(): List<LocalVariableProxyImpl> {