From 6c9da53414c21610119a86fb1f17a473606393e3 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Tue, 21 Jul 2015 16:06:18 +0300 Subject: [PATCH] Fix smart step into in libraries --- .../stepping/KotlinSmartStepIntoHandler.kt | 34 +++++++++---------- .../debugger/smartStepInto/libraryFun.kt | 5 +++ .../debugger/AbstractSmartStepIntoTest.kt | 3 +- .../debugger/SmartStepIntoTestGenerated.java | 6 ++++ 4 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 idea/testData/debugger/smartStepInto/libraryFun.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt index 79ce86b0cde..1a4ed04da62 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt @@ -26,10 +26,13 @@ import com.intellij.psi.PsiMethod import com.intellij.util.Range import com.intellij.util.containers.OrderedSet import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethod +import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult +import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.psi.* @@ -138,11 +141,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { if (delegatedResolvedCall == null) { val getter = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), getterDescriptor) if (getter is JetPropertyAccessor && (getter.getBodyExpression() != null || getter.getEqualsToken() != null)) { - val psiMethod = LightClassUtil.getLightClassAccessorMethod(getter) - if (psiMethod != null) { - val label = KotlinMethodSmartStepTarget.calcLabel(getterDescriptor) - result.add(KotlinMethodSmartStepTarget(getter, label, expression, lines)) - } + val label = KotlinMethodSmartStepTarget.calcLabel(getterDescriptor) + result.add(KotlinMethodSmartStepTarget(getter, label, expression, lines)) } } else { @@ -150,11 +150,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) { val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), delegatedPropertyGetterDescriptor) if (function is JetNamedFunction || function is JetSecondaryConstructor) { - val psiMethod = LightClassUtil.getLightClassMethod(function as JetFunction) - if (psiMethod != null) { - val label = "${propertyDescriptor.getName()}." + KotlinMethodSmartStepTarget.calcLabel(delegatedPropertyGetterDescriptor) - result.add(KotlinMethodSmartStepTarget(function, label, expression, lines)) - } + val label = "${propertyDescriptor.getName()}." + KotlinMethodSmartStepTarget.calcLabel(delegatedPropertyGetterDescriptor) + result.add(KotlinMethodSmartStepTarget(function as JetFunction, label, expression, lines)) } } } @@ -168,15 +165,11 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { val resolvedCall = expression.getResolvedCall(bindingContext) ?: return val descriptor = resolvedCall.getResultingDescriptor() - if (descriptor is CallableMemberDescriptor) { - // TODO doesn't work for libraries + if (descriptor is CallableMemberDescriptor && !isIntrinsic(descriptor)) { val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), descriptor) if (function is JetNamedFunction || function is JetSecondaryConstructor) { - val psiMethod = LightClassUtil.getLightClassMethod(function as JetFunction) - if (psiMethod != null) { - val label = KotlinMethodSmartStepTarget.calcLabel(descriptor) - result.add(KotlinMethodSmartStepTarget(function, label, expression, lines)) - } + val label = KotlinMethodSmartStepTarget.calcLabel(descriptor) + result.add(KotlinMethodSmartStepTarget(function as JetFunction, label, expression, lines)) } else if (function is PsiMethod) { result.add(MethodSmartStepTarget(function, null, expression, false, lines)) @@ -195,4 +188,11 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { else -> super.createMethodFilter(stepTarget) } } + + + private val methods = IntrinsicMethods() + + private fun isIntrinsic(descriptor: CallableMemberDescriptor): Boolean { + return methods.getIntrinsic(descriptor) != null + } } diff --git a/idea/testData/debugger/smartStepInto/libraryFun.kt b/idea/testData/debugger/smartStepInto/libraryFun.kt new file mode 100644 index 00000000000..501c40cb15a --- /dev/null +++ b/idea/testData/debugger/smartStepInto/libraryFun.kt @@ -0,0 +1,5 @@ +fun foo() { + arrayListOf(1, 2).count() +} + +// EXISTS: arrayListOf(vararg Int), count() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt index 289935811fc..fa3e5377e49 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt @@ -26,6 +26,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.debugger.stepping.KotlinLambdaSmartStepTarget import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSmartStepIntoHandler import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils @@ -80,5 +81,5 @@ public abstract class AbstractSmartStepIntoTest : JetLightCodeInsightFixtureTest return PluginTestCaseBase.getTestDataPathBase() + "/debugger/smartStepInto" } - override fun getProjectDescriptor() = LightCodeInsightFixtureTestCase.JAVA_LATEST + override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/SmartStepIntoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/SmartStepIntoTestGenerated.java index 55a51c3dd33..74e1943ab19 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/SmartStepIntoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/SmartStepIntoTestGenerated.java @@ -125,6 +125,12 @@ public class SmartStepIntoTestGenerated extends AbstractSmartStepIntoTest { doTest(fileName); } + @TestMetadata("libraryFun.kt") + public void testLibraryFun() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/libraryFun.kt"); + doTest(fileName); + } + @TestMetadata("multiline.kt") public void testMultiline() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/smartStepInto/multiline.kt");