From 1cfed000c47dc828ab600ce188c7d5b08ca167ff Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 22 May 2015 17:18:34 +0300 Subject: [PATCH] Fix exception during step into inline function in library --- .../kotlin/idea/util/DebuggerUtils.java | 18 +++++++++++++++--- .../functionInLibrary/1/functionInLibrary.kt | 5 +++++ .../functionInLibrary/functionInLibrary.kt | 9 +++++++++ .../tinyApp/outs/allFilesPresentInCustom.out | 0 .../outs/stepIntoStdlibInlineFun2step.out | 9 +++++++++ .../custom/stepIntoStdlibInlineFun2step.kt | 8 ++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/1/functionInLibrary.kt create mode 100644 idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/functionInLibrary.kt create mode 100644 idea/testData/debugger/tinyApp/outs/allFilesPresentInCustom.out create mode 100644 idea/testData/debugger/tinyApp/outs/stepIntoStdlibInlineFun2step.out create mode 100644 idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/util/DebuggerUtils.java b/idea/src/org/jetbrains/kotlin/idea/util/DebuggerUtils.java index 58add37c3ab..2b2c3be3fed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/DebuggerUtils.java +++ b/idea/src/org/jetbrains/kotlin/idea/util/DebuggerUtils.java @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde; import org.jetbrains.kotlin.idea.debugger.DebuggerPackage; import org.jetbrains.kotlin.load.kotlin.PackageClassUtils; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; +import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.CompositeBindingContext; @@ -78,7 +79,15 @@ public class DebuggerUtils { } if (!isPackagePartClassName(className)) { - return filesWithExactName.iterator().next(); + for (JetFile file : filesWithExactName) { + boolean hasTopLevelMembers = KotlinPackage.any(file.getDeclarations(), new Function1() { + @Override + public Boolean invoke(JetDeclaration declaration) { + return !(declaration instanceof JetClassOrObject); + } + }); + if (hasTopLevelMembers) return file; + } } JetFile file = getFileForPackagePartPrefixedName(filesWithExactName, className.getInternalName()); @@ -110,8 +119,11 @@ public class DebuggerUtils { } private static boolean isPackagePartClassName(JvmClassName className) { - String packageName = className.getPackageFqName().asString().replaceAll("\\.", "/"); - return className.getInternalName().startsWith(packageName + "/" + PackageClassUtils.getPackageClassName(className.getPackageFqName())); + FqName packageFqName = PackageClassUtils.getPackageClassFqName(className.getPackageFqName()); + String packageName = packageFqName.asString().replaceAll("\\.", "/"); + + String internalName = className.getInternalName(); + return !internalName.equals(packageName) && internalName.startsWith(packageName); } @Nullable diff --git a/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/1/functionInLibrary.kt b/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/1/functionInLibrary.kt new file mode 100644 index 00000000000..1754d952e98 --- /dev/null +++ b/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/1/functionInLibrary.kt @@ -0,0 +1,5 @@ +package customLib.functionInLibrary + +public inline fun simpleFun2() { + val a = 1 +} \ No newline at end of file diff --git a/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/functionInLibrary.kt b/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/functionInLibrary.kt new file mode 100644 index 00000000000..be222382c15 --- /dev/null +++ b/idea/testData/debugger/customLibraryForTinyApp/functionInLibrary/functionInLibrary.kt @@ -0,0 +1,9 @@ +package customLib.functionInLibrary + +public inline fun simpleFun() { + nextFun() +} + +public inline fun nextFun() { + val a = 1 +} diff --git a/idea/testData/debugger/tinyApp/outs/allFilesPresentInCustom.out b/idea/testData/debugger/tinyApp/outs/allFilesPresentInCustom.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/debugger/tinyApp/outs/stepIntoStdlibInlineFun2step.out b/idea/testData/debugger/tinyApp/outs/stepIntoStdlibInlineFun2step.out new file mode 100644 index 00000000000..3eb92543d76 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/stepIntoStdlibInlineFun2step.out @@ -0,0 +1,9 @@ +LineBreakpoint created at functionInLibrary.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! stepIntoStdlibInlineFun2step.StepIntoStdlibInlineFun2stepPackage +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +stepIntoStdlibInlineFun2step.kt:4 +functionInLibrary.kt:4 +functionInLibrary.kt:8 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt new file mode 100644 index 00000000000..1dee35e576e --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt @@ -0,0 +1,8 @@ +package stepIntoStdlibInlineFun2step + +fun main(args: Array) { + customLib.functionInLibrary.simpleFun() +} + +// ADDITIONAL_BREAKPOINT: functionInLibrary.kt:public inline fun simpleFun() +// STEP_INTO: 2 \ No newline at end of file