Refactoring: extract KotlinStepOverInlineFilter class

(cherry picked from commit 27b0e7d)
This commit is contained in:
Nikolay Krasko
2016-10-12 17:11:20 +03:00
committed by Nikolay Krasko
parent 7510ff4864
commit 2511ef2c45
2 changed files with 52 additions and 29 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.debugger.stepping
import com.intellij.debugger.engine.DebugProcessImpl
import com.intellij.debugger.engine.SuspendContextImpl
import com.intellij.util.Range
import com.sun.jdi.LocalVariable
import com.sun.jdi.Location
class KotlinStepOverInlineFilter(val stepOverLines: Set<Int>, val fromLine: Int,
val inlineFunRangeVariables: List<LocalVariable>) : KotlinMethodFilter {
override fun locationMatches(context: SuspendContextImpl, location: Location): Boolean {
val frameProxy = context.frameProxy
if (frameProxy == null) return true
val currentLine = location.lineNumber()
if (!(stepOverLines.contains(location.lineNumber()))) {
return currentLine != fromLine
}
val visibleInlineVariables = getInlineRangeLocalVariables(frameProxy)
// Our ranges check missed exit from inline function. This is when breakpoint was in last statement of inline functions.
// This can be observed by inline local range-variables. Absence of any means step out was done.
return inlineFunRangeVariables.any { !visibleInlineVariables.contains(it) }
}
override fun locationMatches(process: DebugProcessImpl, location: Location): Boolean {
throw IllegalStateException() // Should not be called from Kotlin hint
}
override fun getCallingExpressionLines(): Range<Int>? {
throw IllegalStateException() // Should not be called from Kotlin hint
}
}
@@ -296,34 +296,6 @@ interface KotlinMethodFilter: MethodFilter {
fun locationMatches(context: SuspendContextImpl, location: Location): Boolean
}
class KotlinStepOverInlineFilter(val stepOverLines: Set<Int>, val fromLine: Int,
val inlineFunRangeVariables: List<LocalVariable>) : KotlinMethodFilter {
override fun locationMatches(context: SuspendContextImpl, location: Location): Boolean {
val frameProxy = context.frameProxy
if (frameProxy == null) return true
val currentLine = location.lineNumber()
if (!(stepOverLines.contains(location.lineNumber()))) {
return currentLine != fromLine
}
val visibleInlineVariables = getInlineRangeLocalVariables(frameProxy)
// Our ranges check missed exit from inline function. This is when breakpoint was in last statement of inline functions.
// This can be observed by inline local range-variables. Absence of any means step out was done.
return inlineFunRangeVariables.any { !visibleInlineVariables.contains(it) }
}
override fun locationMatches(process: DebugProcessImpl, location: Location): Boolean {
throw IllegalStateException() // Should not be called from Kotlin hint
}
override fun getCallingExpressionLines(): Range<Int>? {
throw IllegalStateException() // Should not be called from Kotlin hint
}
}
fun getStepOverAction(
location: Location,
kotlinSourcePosition: KotlinSteppingCommandProvider.KotlinSourcePosition,
@@ -496,7 +468,7 @@ private fun SuspendContextImpl.getNextPositionWithFilter(
return null
}
private fun getInlineRangeLocalVariables(stackFrame: StackFrameProxyImpl): List<LocalVariable> {
fun getInlineRangeLocalVariables(stackFrame: StackFrameProxyImpl): List<LocalVariable> {
return stackFrame.visibleVariables()
.filter {
val name = it.name()