Fix smart step into in libraries

This commit is contained in:
Natalia Ukhorskaya
2015-07-21 16:06:18 +03:00
parent b76b251489
commit 6c9da53414
4 changed files with 30 additions and 18 deletions
@@ -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
}
}
+5
View File
@@ -0,0 +1,5 @@
fun foo() {
arrayListOf(1, 2).count()<caret>
}
// EXISTS: arrayListOf(vararg Int), count()
@@ -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
}
@@ -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");