From d6cface66fb38690ac972a3a2286701b9c73f769 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 12 Dec 2017 18:47:59 +0300 Subject: [PATCH] Make isFromJava check work for SAM adapter extension descriptors (KT-21538) Consider all callable descriptor in JavaClassDescriptor to be from Java. This is used to check if smart step into should be intercepted by Kotlin handler or delegated to Java. #KT-21538 Fixed --- .../kotlin/load/java/specialBuiltinMembers.kt | 6 +++--- .../debugger/tinyApp/src/forTests/MyJavaClass.java | 5 +++++ .../stepIntoAndSmartStepInto/javaSamFunction.kt | 9 +++++++++ .../stepIntoAndSmartStepInto/javaSamFunction.out | 9 +++++++++ .../idea/debugger/KotlinSteppingTestGenerated.java | 12 ++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt create mode 100644 idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.out diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt index 62947b4e840..d72a525c372 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt @@ -343,10 +343,10 @@ fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf( return false } -// Util methods val CallableMemberDescriptor.isFromJava: Boolean - get() = propertyIfAccessor.let { descriptor -> - (descriptor as? JavaCallableMemberDescriptor)?.containingDeclaration is JavaClassDescriptor + get() { + val descriptor = propertyIfAccessor + return descriptor.containingDeclaration is JavaClassDescriptor } fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || KotlinBuiltIns.isBuiltIn(this) diff --git a/idea/testData/debugger/tinyApp/src/forTests/MyJavaClass.java b/idea/testData/debugger/tinyApp/src/forTests/MyJavaClass.java index f69b382c757..a411a20df4e 100644 --- a/idea/testData/debugger/tinyApp/src/forTests/MyJavaClass.java +++ b/idea/testData/debugger/tinyApp/src/forTests/MyJavaClass.java @@ -49,4 +49,9 @@ public class MyJavaClass { public static class RawADerived extends RawA { } + + // Method with sam conversion for step into test + public void other(Runnable runnable) { + runnable.run(); + } } diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt b/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt new file mode 100644 index 00000000000..8d41903964b --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt @@ -0,0 +1,9 @@ +package javaSamFunction + +import forTests.MyJavaClass + +fun main(args: Array) { + val klass = MyJavaClass() + //Breakpoint! + klass.other { /* do nothing*/ } +} \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.out b/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.out new file mode 100644 index 00000000000..14841bb9f2e --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.out @@ -0,0 +1,9 @@ +LineBreakpoint created at javaSamFunction.kt:8 +Run Java +Connected to the target VM +javaSamFunction.kt:8 +MyJavaClass.java:55 +resuming javaSamFunction.kt:8 +Disconnected from the target VM + +Process finished with exit code 0 diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index 5d9e164a8e2..a94e89bc49f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -62,6 +62,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepIntoTest(fileName); } + @TestMetadata("javaSamFunction.kt") + public void testJavaSamFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt"); + doStepIntoTest(fileName); + } + @TestMetadata("memberFunFromClass.kt") public void testMemberFunFromClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/memberFunFromClass.kt"); @@ -149,6 +155,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doSmartStepIntoTest(fileName); } + @TestMetadata("javaSamFunction.kt") + public void testJavaSamFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/javaSamFunction.kt"); + doSmartStepIntoTest(fileName); + } + @TestMetadata("memberFunFromClass.kt") public void testMemberFunFromClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepIntoAndSmartStepInto/memberFunFromClass.kt");