From 3dd076efa8f1788d94cb2dcb1090a11cf27afe39 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 25 Sep 2015 14:04:29 +0300 Subject: [PATCH] Minor: extract function --- .../stepping/KotlinSteppingCommandProvider.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSteppingCommandProvider.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSteppingCommandProvider.kt index 6b1fc6cf15b..3e7209d21f9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSteppingCommandProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSteppingCommandProvider.kt @@ -99,7 +99,7 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { val result = arrayListOf() val ifParent = getParentOfType(false) if (ifParent != null) { - if (ifParent.then?.textRange?.contains(this.textRange) ?: false) { + if (ifParent.then.contains(this)) { ifParent.elseKeyword?.let { result.add(it) } ifParent.`else`?.let { result.add(it) } } @@ -114,7 +114,7 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { val whenEntry = getParentOfType(false) if (whenEntry != null) { - if (whenEntry.expression?.textRange?.contains(this.textRange) ?: false) { + if (whenEntry.expression.contains(this)) { val whenParent = whenEntry.getParentOfType(false) if (whenParent != null) { result.addAll(whenParent.entries.filter { it != whenEntry }) @@ -129,7 +129,7 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { val ifParent = getParentOfType(false) if (ifParent != null) { // if (inlineFunCall()) {...} - if (ifParent.condition?.textRange?.contains(this.textRange) ?: false) { + if (ifParent.condition.contains(this)) { return true } @@ -139,10 +139,10 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { */ val ifParentElementAt = elementAt.getParentOfType(false) if (ifParentElementAt == null) { - if (ifParent.then?.textRange?.contains(this.textRange) ?: false) { + if (ifParent.then.contains(this)) { return true } - if (ifParent.`else`?.textRange?.contains(this.textRange) ?: false) { + if (ifParent.`else`.contains(this)) { return true } } @@ -153,7 +153,7 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { /* try { inlineFunCall() } catch()... */ - if (tryParent.tryBlock.textRange?.contains(this.textRange) ?: false) { + if (tryParent.tryBlock.contains(this)) { return true } } @@ -161,21 +161,25 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() { val whenEntry = getParentOfType(false) if (whenEntry != null) { // inlineFunCall -> ... - if (whenEntry.conditions.any { it.textRange.contains(this.textRange) } ) { + if (whenEntry.conditions.any { it.contains(this) } ) { return true } // 1 == 2 -> inlineFunCall() - if (whenEntry.expression?.textRange?.contains(this.textRange) ?: false) { + if (whenEntry.expression.contains(this)) { val parentEntryElementAt = elementAt.getParentOfType(false) ?: return true return parentEntryElementAt == whenEntry && - whenEntry.conditions.any { it.textRange.contains(elementAt.textRange) } + whenEntry.conditions.any { it.contains(elementAt) } } } return false } + private fun PsiElement?.contains(element: PsiElement): Boolean { + return this?.textRange?.contains(element.textRange) ?: false + } + override fun getStepOutCommand(suspendContext: SuspendContextImpl?, stepSize: Int): DebugProcessImpl.ResumeCommand? { if (suspendContext == null || suspendContext.isResumed) return null