Fix breakpoints in inline functions in libraries

This commit is contained in:
Natalia Ukhorskaya
2015-05-21 14:03:47 +03:00
parent 6516c74a1a
commit 52fe6310a0
7 changed files with 39 additions and 11 deletions
@@ -48,6 +48,8 @@ import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.decompiler.JetClsFile
import org.jetbrains.kotlin.idea.findUsages.toSearchTarget
import org.jetbrains.kotlin.idea.search.usagesSearch.DefaultSearchHelper
import org.jetbrains.kotlin.idea.search.usagesSearch.FunctionUsagesSearchHelper
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearch
import org.jetbrains.kotlin.idea.search.usagesSearch.search
import org.jetbrains.kotlin.idea.util.DebuggerUtils
import org.jetbrains.kotlin.idea.util.application.runReadAction
@@ -353,7 +355,10 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Mult
}
if (isInLibrary) {
val elementAtForLibraryFile = getElementToCreateTypeMapperForLibraryFile(notPositionedElement)
val elementAtForLibraryFile =
if (element is JetDeclaration) element
else PsiTreeUtil.getParentOfType(element, javaClass<JetDeclaration>())
assert(elementAtForLibraryFile != null) {
"Couldn't find element at breakpoint for library file " + file.getName() +
(if (notPositionedElement == null) "" else ", notPositionedElement = " + notPositionedElement.getElementTextWithContext())
@@ -430,9 +435,11 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Mult
InlineUtil.isInline(typeMapper.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, psiElement))
) {
val project = myDebugProcess.getProject()
val usagesSearchTarget = FindUsagesOptions(project).toSearchTarget(psiElement, true)
val options = FindUsagesOptions(project)
options.isSearchForTextOccurrences = false
val usagesSearchTarget = options.toSearchTarget(psiElement, true)
val usagesSearchRequest = DefaultSearchHelper<JetNamedFunction>(true).newRequest(usagesSearchTarget)
val usagesSearchRequest = FunctionUsagesSearchHelper(skipImports = true).newRequest(usagesSearchTarget)
usagesSearchRequest.search().forEach {
val psiElement = it.getElement()
if (psiElement is JetElement) {
@@ -51,13 +51,7 @@ private val LOG = Logger.getInstance("org.jetbrains.kotlin.idea.debugger")
* 2. find all descriptors with same signature, if there is one - return it
* 3. else -> return null, because it means that there is more than one function with same signature in project
*/
fun findPackagePartInternalNameForLibraryFile(elementAt: JetElement): String? {
val topLevelDeclaration = PsiTreeUtil.getTopmostParentOfType(elementAt, javaClass<JetDeclaration>())
if (topLevelDeclaration == null) {
reportError(elementAt, null)
return null
}
fun findPackagePartInternalNameForLibraryFile(topLevelDeclaration: JetDeclaration): String? {
val packagePartFile = findPackagePartFileNamesForElement(topLevelDeclaration).singleOrNull()
if (packagePartFile != null) return packagePartFile
@@ -99,7 +99,7 @@ public class DebuggerUtils {
public Boolean invoke(JetFile file) {
Integer startLineOffset = CodeInsightUtils.getStartLineOffset(file, lineNumber);
assert startLineOffset != null : "Cannot find start line offset for file " + file.getName() + ", line " + lineNumber;
JetElement elementAt = PsiTreeUtil.getParentOfType(file.findElementAt(startLineOffset), JetElement.class);
JetDeclaration elementAt = PsiTreeUtil.getParentOfType(file.findElementAt(startLineOffset), JetDeclaration.class);
return elementAt != null &&
className.getInternalName().equals(DebuggerPackage.findPackagePartInternalNameForLibraryFile(elementAt));
}
@@ -0,0 +1,5 @@
package customLib.inlineFunInLibrary
public inline fun inlineFun(f: () -> Unit) {
1 + 1
}
@@ -0,0 +1,7 @@
LineBreakpoint created at inlineFunInLibrary.kt:3
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !APP_PATH!\classes;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! breakpointInInlineFun.BreakpointInInlineFunPackage
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
inlineFunInLibrary.kt:4
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -0,0 +1,9 @@
package breakpointInInlineFun
import customLib.inlineFunInLibrary.*
fun main(args: Array<String>) {
inlineFun { }
}
// ADDITIONAL_BREAKPOINT: inlineFunInLibrary.kt:public inline fun inlineFun
@@ -61,6 +61,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
doSingleBreakpointTest(fileName);
}
@TestMetadata("breakpointInInlineFun.kt")
public void testBreakpointInInlineFun() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/breakpointInInlineFun.kt");
doSingleBreakpointTest(fileName);
}
@TestMetadata("callableBug.kt")
public void testCallableBug() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/callableBug.kt");