diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DebuggerDfaRunnerUtils.kt b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DebuggerDfaRunnerUtils.kt index b6b8a734b53e..8b15d5376817 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DebuggerDfaRunnerUtils.kt +++ b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DebuggerDfaRunnerUtils.kt @@ -45,7 +45,7 @@ private suspend fun hatch(proxy: StackFrameProxyEx, pointer: SmartPsiElementPoin } ?: return null try { - val match = syncReadAction { provider.locationMatches(e, proxy.location()) } + val match = provider.locationMatches(e, proxy.location()) if (!match) return null } catch (iea: IllegalArgumentException) { diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DfaAssistProvider.kt b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DfaAssistProvider.kt index 07f4eb819910..eaa504024359 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DfaAssistProvider.kt +++ b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/DfaAssistProvider.kt @@ -8,10 +8,12 @@ import com.intellij.debugger.jdi.StackFrameProxyEx import com.intellij.lang.LanguageExtension import com.intellij.psi.PsiElement import com.sun.jdi.* +import org.jetbrains.annotations.ApiStatus /** * Language specific helpers to implement DFAAssist (for JVM languages only) */ +@ApiStatus.Internal interface DfaAssistProvider { /** * Represents a 'virtual' boxed value which in fact does not exist in the VM memory. @@ -38,7 +40,7 @@ interface DfaAssistProvider { * @return true if debugger location likely matches to the editor location; * false if definitely doesn't match (in this case, DFA Assist will be turned off) */ - fun locationMatches(element: PsiElement, location: Location): Boolean + suspend fun locationMatches(element: PsiElement, location: Location): Boolean /** * @param element psi element the debugger state points at diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/java/JavaDfaAssistProvider.kt b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/java/JavaDfaAssistProvider.kt index 8f89c40bc133..6f0173b4c3df 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/java/JavaDfaAssistProvider.kt +++ b/java/debugger/impl/src/com/intellij/debugger/engine/dfaassist/java/JavaDfaAssistProvider.kt @@ -15,26 +15,30 @@ import com.intellij.debugger.engine.evaluation.EvaluateException import com.intellij.debugger.engine.evaluation.expression.CaptureTraverser import com.intellij.debugger.impl.DebuggerUtilsEx import com.intellij.debugger.jdi.StackFrameProxyEx +import com.intellij.openapi.application.readAction import com.intellij.psi.* import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.containers.ContainerUtil import com.sun.jdi.* -class JavaDfaAssistProvider : DfaAssistProvider { - override fun locationMatches(element: PsiElement, location: Location): Boolean { +private class JavaDfaAssistProvider : DfaAssistProvider { + override suspend fun locationMatches(element: PsiElement, location: Location): Boolean { val method = location.method() - val context = DebuggerUtilsEx.getContainingMethod(element) + val methodName = method.name() + val methodArgumentsSize = method.argumentTypeNames().size + val context = readAction { DebuggerUtilsEx.getContainingMethod(element) } if (context is PsiMethod) { - val name = if (context.isConstructor()) "" else context.getName() - return name == method.name() && context.getParameterList().getParametersCount() == method.argumentTypeNames().size + return readAction { + val name = if (context.isConstructor()) "" else context.getName() + name == methodName && context.getParameterList().getParametersCount() == methodArgumentsSize + } } if (context is PsiLambdaExpression) { - return DebuggerUtilsEx.isLambda(method) && - method.argumentTypeNames().size >= context.getParameterList().getParametersCount() + return DebuggerUtilsEx.isLambda(method) && readAction { methodArgumentsSize >= context.getParameterList().getParametersCount() } } if (context is PsiClassInitializer) { - val expectedMethod = if (context.hasModifierProperty(PsiModifier.STATIC)) "" else "" - return method.name() == expectedMethod + val expectedMethod = readAction { if (context.hasModifierProperty(PsiModifier.STATIC)) "" else "" } + return methodName == expectedMethod } return false } diff --git a/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiLambda.java b/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiLambda.java index 65e9c2ed8155..7881c58a1ffe 100644 --- a/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiLambda.java +++ b/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiLambda.java @@ -5,6 +5,7 @@ import com.intellij.debugger.mockJDI.MockLocalVariable; import com.intellij.debugger.mockJDI.MockMirror; import com.intellij.debugger.mockJDI.MockVirtualMachine; import com.intellij.debugger.mockJDI.types.MockType; +import com.intellij.openapi.application.ReadAction; import com.intellij.psi.LambdaUtil; import com.intellij.psi.PsiLambdaExpression; import com.intellij.psi.PsiMethod; @@ -41,15 +42,16 @@ public class MockPsiLambda extends MockMirror implements Method { @Override public @Unmodifiable List argumentTypeNames() { // Captured values are not yet supported in mock - return ContainerUtil.map(myPsiLambdaExpression.getParameterList().getParameters(), parameter -> parameter.getType().getCanonicalText()); + return ReadAction.compute(() -> ContainerUtil.map(myPsiLambdaExpression.getParameterList().getParameters(), + parameter -> parameter.getType().getCanonicalText())); } @Override public @Unmodifiable List argumentTypes() { - return ContainerUtil.map( + return ReadAction.compute(() -> ContainerUtil.map( myPsiLambdaExpression.getParameterList().getParameters(), parameter -> MockType.createType(myVirtualMachine, parameter.getType()) - ); + )); } @Override @@ -144,7 +146,7 @@ public class MockPsiLambda extends MockMirror implements Method { @Override public String name() { - return "lambda$" + myDeclaringMethod.getName() + "$mock"; + return "lambda$" + ReadAction.compute(() -> myDeclaringMethod.getName()) + "$mock"; } @Override diff --git a/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiMethod.java b/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiMethod.java index 861d40f72eed..748e0b82f490 100644 --- a/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiMethod.java +++ b/java/testFramework/src/com/intellij/debugger/mockJDI/members/MockPsiMethod.java @@ -36,15 +36,16 @@ public class MockPsiMethod extends MockMirror implements Method { @Override public @Unmodifiable List argumentTypeNames() { - return ContainerUtil.map(myPsiMethod.getParameterList().getParameters(), parameter -> parameter.getType().getCanonicalText()); + return ReadAction.compute(() -> ContainerUtil.map(myPsiMethod.getParameterList().getParameters(), + parameter -> parameter.getType().getCanonicalText())); } @Override public @Unmodifiable List argumentTypes() { - return ContainerUtil.map( + return ReadAction.compute(() -> ContainerUtil.map( myPsiMethod.getParameterList().getParameters(), parameter -> MockType.createType(myVirtualMachine, parameter.getType()) - ); + )); } @Override @@ -139,7 +140,7 @@ public class MockPsiMethod extends MockMirror implements Method { @Override public String name() { - return myPsiMethod.getName(); + return ReadAction.compute(() -> myPsiMethod.getName()); } @Override diff --git a/plugins/kotlin/jvm-debugger/evaluation/k1/src/org/jetbrains/kotlin/idea/debugger/dfaassist/KotlinDfaAssistProvider.kt b/plugins/kotlin/jvm-debugger/evaluation/k1/src/org/jetbrains/kotlin/idea/debugger/dfaassist/KotlinDfaAssistProvider.kt index b7a8b1da8499..e24d4c0be669 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/k1/src/org/jetbrains/kotlin/idea/debugger/dfaassist/KotlinDfaAssistProvider.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/k1/src/org/jetbrains/kotlin/idea/debugger/dfaassist/KotlinDfaAssistProvider.kt @@ -13,6 +13,7 @@ import com.intellij.debugger.engine.DebuggerUtils import com.intellij.debugger.engine.dfaassist.DebuggerDfaListener import com.intellij.debugger.engine.dfaassist.DfaAssistProvider import com.intellij.debugger.jdi.StackFrameProxyEx +import com.intellij.openapi.application.readAction import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace @@ -36,13 +37,15 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.org.objectweb.asm.Type as AsmType -class KotlinDfaAssistProvider : DfaAssistProvider { - override fun locationMatches(element: PsiElement, location: Location): Boolean { +private class KotlinDfaAssistProvider : DfaAssistProvider { + override suspend fun locationMatches(element: PsiElement, location: Location): Boolean { val jdiClassName = location.method().declaringType().name() - val file = element.containingFile - if (file !is KtFile) return false - val classNames = ClassNameCalculator.getClassNames(file) - return element.parentsWithSelf.any { e -> classNames[e] == jdiClassName } + return readAction { + val file = element.containingFile + if (file !is KtFile) return@readAction false + val classNames = ClassNameCalculator.getClassNames(file) + element.parentsWithSelf.any { e -> classNames[e] == jdiClassName } + } } override fun getAnchor(element: PsiElement): KtExpression? { diff --git a/plugins/kotlin/jvm-debugger/evaluation/k2/src/org/jetbrains/kotlin/idea/k2/debugger/dfaassist/K2DfaAssistProvider.kt b/plugins/kotlin/jvm-debugger/evaluation/k2/src/org/jetbrains/kotlin/idea/k2/debugger/dfaassist/K2DfaAssistProvider.kt index 81a15eef8694..4aa9fa611f95 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/k2/src/org/jetbrains/kotlin/idea/k2/debugger/dfaassist/K2DfaAssistProvider.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/k2/src/org/jetbrains/kotlin/idea/k2/debugger/dfaassist/K2DfaAssistProvider.kt @@ -18,6 +18,7 @@ import com.intellij.debugger.engine.dfaassist.DfaAssistProvider import com.intellij.debugger.jdi.StackFrameProxyEx import com.intellij.debugger.jdi.StackFrameProxyImpl import com.intellij.lang.jvm.types.JvmPrimitiveTypeKind +import com.intellij.openapi.application.readAction import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace @@ -51,12 +52,14 @@ import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.org.objectweb.asm.Type as AsmType private class K2DfaAssistProvider : DfaAssistProvider { - override fun locationMatches(element: PsiElement, location: Location): Boolean { + override suspend fun locationMatches(element: PsiElement, location: Location): Boolean { val jdiClassName = location.method().declaringType().name() - val file = element.containingFile - if (file !is KtFile) return false - val classNames = ClassNameCalculator.getClassNames(file) - return element.parentsWithSelf.any { e -> classNames[e] == jdiClassName } + return readAction { + val file = element.containingFile + if (file !is KtFile) return@readAction false + val classNames = ClassNameCalculator.getClassNames(file) + element.parentsWithSelf.any { e -> classNames[e] == jdiClassName } + } } override fun getAnchor(element: PsiElement): PsiElement? {