Debugger: Smart Step Into inside lambda suggests methods from outer context

#KT-10148 Fixed
This commit is contained in:
Natalia Ukhorskaya
2016-03-31 16:49:03 +03:00
parent 8b6a447e68
commit 09faec9ed7
6 changed files with 42 additions and 15 deletions
@@ -44,15 +44,11 @@ class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
override fun isAvailable(position: SourcePosition?) = position?.file is KtFile
override fun findSmartStepTargets(position: SourcePosition): List<SmartStepTarget> {
if (position.line < 0) return emptyList()
val file = position.file
val lineStart = CodeInsightUtils.getStartLineOffset(file, position.line) ?: return emptyList()
val elementAtOffset = position.elementAt ?: return emptyList()
val elementAtOffset = file.findElementAt(lineStart) ?: return emptyList()
val element = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, lineStart)
val element = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, elementAtOffset.textRange.startOffset)
if (element !is KtElement) return emptyList()
val elementTextRange = element.textRange ?: return emptyList()
@@ -0,0 +1,8 @@
LineBreakpoint created at smartStepIntoInsideLambda.kt:6 lambdaOrdinal = 0
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! smartStepIntoInsideLambda.SmartStepIntoInsideLambdaKt
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
smartStepIntoInsideLambda.kt:6
smartStepIntoInsideLambda.kt:14
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -0,0 +1,16 @@
package smartStepIntoInsideLambda
fun main(args: Array<String>) {
// SMART_STEP_INTO_BY_INDEX: 1
//Breakpoint! (lambdaOrdinal = 0)
foo { bar() }
}
fun foo(f: () -> Unit) {
f()
}
fun bar() {
val a = 1
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.debugger
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSmartStepIntoHandler
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
@@ -33,7 +34,14 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase
val offset = fixture.caretOffset
val line = fixture.getDocument(fixture.file!!)!!.getLineNumber(offset)
val position = MockSourcePosition(_file = fixture.file, _line = line, _offset = offset, _editor = fixture.editor)
val lineStart = CodeInsightUtils.getStartLineOffset(file, line)!!
val elementAtOffset = file.findElementAt(lineStart)
val position = MockSourcePosition(_file = fixture.file,
_line = line,
_offset = offset,
_editor = fixture.editor,
_elementAt = elementAtOffset)
val actual = KotlinSmartStepIntoHandler().findSmartStepTargets(position).map { it.presentation }
@@ -45,7 +45,6 @@ import com.intellij.xdebugger.XDebuggerUtil
import com.intellij.xdebugger.breakpoints.*
import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpoint
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpointType
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinLineBreakpointType
@@ -205,16 +204,10 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
}
private fun createSmartStepIntoFilters(): List<MethodFilter> {
val contextElement = ContextUtil.getContextElement(evaluationContext)!!
val line = runReadAction { contextElement.getLineNumber() }
return runReadAction {
val containingFile = contextElement.containingFile
val position = MockSourcePosition(_file = containingFile, _line = line)
val position = debuggerContext.sourcePosition
val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position)
stepTargets.filterIsInstance<SmartStepTarget>().mapNotNull {
stepTarget ->
when (stepTarget) {
@@ -613,6 +613,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest {
doCustomTest(fileName);
}
@TestMetadata("smartStepIntoInsideLambda.kt")
public void testSmartStepIntoInsideLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInsideLambda.kt");
doCustomTest(fileName);
}
@TestMetadata("smartStepIntoInterfaceImpl.kt")
public void testSmartStepIntoInterfaceImpl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInterfaceImpl.kt");