From 54fa9eff61911b2a2bf66a29d02c5bae249d595a Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Thu, 28 Jan 2016 09:35:58 +0300 Subject: [PATCH] Debugger: do not compute classnames for inline functions during stepping --- .../kotlin/idea/ExtraSteppingFilter.kt | 2 +- .../idea/debugger/KotlinPositionManager.kt | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/ExtraSteppingFilter.kt b/idea/src/org/jetbrains/kotlin/idea/ExtraSteppingFilter.kt index aa00855b08f..a5ea51a5859 100644 --- a/idea/src/org/jetbrains/kotlin/idea/ExtraSteppingFilter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/ExtraSteppingFilter.kt @@ -56,7 +56,7 @@ class ExtraSteppingFilter : com.intellij.debugger.engine.ExtraSteppingFilter { if (sourcePosition == null) return false - val classNames = positionManager.classNamesForPosition(sourcePosition).map { it.replace('/', '.') } + val classNames = positionManager.classNamesForPosition(sourcePosition, false).map { it.replace('/', '.') } classNames.forEach { className -> val settings = DebuggerSettings.getInstance() diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt index 6d8f841f86b..1b7964fbcaa 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinPositionManager.kt @@ -71,7 +71,6 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.inline.InlineUtil import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.source.getPsi -import org.jetbrains.kotlin.utils.addToStdlib.check import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.toReadOnlyList import java.util.* @@ -260,7 +259,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq private fun classNamesForPositionAndInlinedOnes(sourcePosition: SourcePosition): List { val result = hashSetOf() - val names = classNamesForPosition(sourcePosition) + val names = classNamesForPosition(sourcePosition, true) result.addAll(names) val lambdas = findLambdas(sourcePosition) @@ -281,12 +280,12 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq } } - fun classNamesForPosition(sourcePosition: SourcePosition): Collection { + fun classNamesForPosition(sourcePosition: SourcePosition, withInlines: Boolean): Collection { val psiElement = runReadAction { sourcePosition.elementAt } ?: return emptyList() - return classNamesForPosition(psiElement) + return classNamesForPosition(psiElement, withInlines) } - private fun classNamesForPosition(element: PsiElement): Collection { + private fun classNamesForPosition(element: PsiElement, withInlines: Boolean): Collection { return runReadAction { if (DumbService.getInstance(element.project).isDumb) { emptySet() @@ -295,7 +294,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq val file = element.containingFile as KtFile val isInLibrary = LibraryUtil.findLibraryEntry(file.virtualFile, file.project) != null val typeMapper = if (!isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(element, file) - getInternalClassNameForElement(element, typeMapper, file, isInLibrary) + getInternalClassNameForElement(element, typeMapper, file, isInLibrary, withInlines) } } } @@ -357,7 +356,13 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq myTypeMappers.put(key, value) } - private fun getInternalClassNameForElement(notPositionedElement: PsiElement?, typeMapper: JetTypeMapper, file: KtFile, isInLibrary: Boolean): Collection { + private fun getInternalClassNameForElement( + notPositionedElement: PsiElement?, + typeMapper: JetTypeMapper, + file: KtFile, + isInLibrary: Boolean, + withInlines: Boolean = true + ): Collection { val element = getElementToCalculateClassName(notPositionedElement) when (element) { @@ -365,7 +370,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq is KtFunction -> { val descriptor = InlineUtil.getInlineArgumentDescriptor(element, typeMapper.bindingContext) if (descriptor != null) { - val classNamesForParent = getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary) + val classNamesForParent = getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines) if (descriptor.isCrossinline) { return findCrossInlineArguments(element, descriptor, typeMapper.bindingContext) + classNamesForParent } @@ -388,9 +393,9 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq val parent = getElementToCalculateClassName(element.parent) // Class-object initializer if (parent is KtObjectDeclaration && parent.isCompanion()) { - return getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary) + return getInternalClassNameForElement(parent.parent, typeMapper, file, isInLibrary, withInlines) } - return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary) + return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines) } element is KtProperty && (!element.isTopLevel || !isInLibrary) -> { if (isInPropertyAccessor(notPositionedElement)) { @@ -402,7 +407,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq val descriptor = typeMapper.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element) if (descriptor !is PropertyDescriptor) { - return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary) + return getInternalClassNameForElement(element.parent, typeMapper, file, isInLibrary, withInlines) } return getJvmInternalNameForPropertyOwner(typeMapper, descriptor).toSet() @@ -420,6 +425,8 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq NoResolveFileClassesProvider.getFileClassInternalName(file) } + if (!withInlines) return parentInternalName.toSet() + val inlinedCalls = findInlinedCalls(element, typeMapper.bindingContext) return inlinedCalls + parentInternalName.toSet() } @@ -490,7 +497,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq val usage = it.element if (usage is KtElement) { //TODO recursive search - val names = classNamesForPosition(usage) + val names = classNamesForPosition(usage, false) result.addAll(names) } }