From b281b92e5b14b79ba87564284029a8dffa292b40 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Thu, 17 Oct 2024 12:16:43 +0200 Subject: [PATCH] [debugger] use DebuggerUtils.findMethod pt.2 GitOrigin-RevId: f83c4b1ffce05dc64dcef85eb4f293027113e7ab --- .../debugger/mockJDI/types/MockReferenceType.java | 12 +++++------- .../kotlin/idea/debugger/base/util/JdiTypeUtils.kt | 11 +++++++++-- .../debugger/base/util/evaluate/ExecutionContext.kt | 12 ++++-------- .../evaluate/variables/EvaluatorValueConverter.kt | 8 ++++---- .../debugger/evaluate/variables/VariableFinder.kt | 9 ++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/java/testFramework/src/com/intellij/debugger/mockJDI/types/MockReferenceType.java b/java/testFramework/src/com/intellij/debugger/mockJDI/types/MockReferenceType.java index b1ff916753cb..85d01695d28d 100644 --- a/java/testFramework/src/com/intellij/debugger/mockJDI/types/MockReferenceType.java +++ b/java/testFramework/src/com/intellij/debugger/mockJDI/types/MockReferenceType.java @@ -1,9 +1,7 @@ -/* - * Copyright (c) 2000-2004 by JetBrains s.r.o. All Rights Reserved. - * Use is subject to license terms. - */ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.debugger.mockJDI.types; +import com.intellij.debugger.engine.DebuggerUtils; import com.intellij.debugger.mockJDI.MockLocation; import com.intellij.debugger.mockJDI.MockVirtualMachine; import com.intellij.debugger.mockJDI.members.MockConstructor; @@ -291,11 +289,11 @@ public abstract class MockReferenceType extends MockType implements ReferenceTyp reader.accept(new ClassVisitor(Opcodes.API_VERSION) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - final List methods = MockReferenceType.this.methodsByName(name, desc); - if (methods.isEmpty()) { + Method method = DebuggerUtils.findMethod(MockReferenceType.this, name, desc); + if (method == null) { return super.visitMethod(access, name, desc, signature, exceptions); } - return new LineNumbersEvaluatingVisitor(stratum, methods.get(0)); + return new LineNumbersEvaluatingVisitor(stratum, method); } }, 0); } diff --git a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/JdiTypeUtils.kt b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/JdiTypeUtils.kt index 4291a447601c..7437519ac846 100644 --- a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/JdiTypeUtils.kt +++ b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/JdiTypeUtils.kt @@ -1,10 +1,13 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:JvmName("JdiTypeUtils") package org.jetbrains.kotlin.idea.debugger.base.util +import com.intellij.debugger.engine.DebuggerUtils import com.sun.jdi.ClassType +import com.sun.jdi.Method +import com.sun.jdi.ReferenceType import com.sun.jdi.Type import org.jetbrains.annotations.ApiStatus import org.jetbrains.org.objectweb.asm.Type as AsmType @@ -51,4 +54,8 @@ fun ClassType.hasSuperClass(jdiName: String): Boolean { fun ClassType.hasInterface(jdiName: String): Boolean { return allInterfaces().any { it.name() == jdiName } -} \ No newline at end of file +} + +fun ReferenceType.findMethod(name: String, methodSignature: String?): Method { + return DebuggerUtils.findMethod(this, name, methodSignature) ?: error("Method {$name} {$methodSignature} not found") +} diff --git a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/evaluate/ExecutionContext.kt b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/evaluate/ExecutionContext.kt index d08b0328a021..c99c0e0bc191 100644 --- a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/evaluate/ExecutionContext.kt +++ b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/evaluate/ExecutionContext.kt @@ -3,7 +3,6 @@ package org.jetbrains.kotlin.idea.debugger.base.util.evaluate import com.intellij.debugger.engine.DebugProcessImpl -import com.intellij.debugger.engine.DebuggerUtils import com.intellij.debugger.engine.SuspendContextImpl import com.intellij.debugger.engine.evaluation.EvaluateException import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil @@ -14,6 +13,7 @@ import com.intellij.debugger.jdi.VirtualMachineProxyImpl import com.intellij.openapi.project.Project import com.sun.jdi.* import com.sun.jdi.request.EventRequest +import org.jetbrains.kotlin.idea.debugger.base.util.findMethod import org.jetbrains.kotlin.idea.debugger.base.util.hopelessAware import org.jetbrains.org.objectweb.asm.Type @@ -180,21 +180,17 @@ sealed class BaseExecutionContext(val evaluationContext: EvaluationContextImpl) methodSignature: String, vararg params: Value ): Value? { - return invokeMethod(ref, findSingleMethod(type, name, methodSignature), params.asList()) + return invokeMethod(ref, type.findMethod(name, methodSignature), params.asList()) } /** * static method invocation */ private fun findAndInvoke(type: ClassType, name: String, methodSignature: String? = null, vararg params: Value): Value? { - return invokeMethod(type, findSingleMethod(type, name, methodSignature), params.asList()) + return invokeMethod(type, type.findMethod(name, methodSignature), params.asList()) } private fun findAndInvoke(instance: ObjectReference, name: String, methodSignature: String? = null, vararg params: Value): Value? { - return invokeMethod(instance, findSingleMethod(instance.referenceType(), name, methodSignature), params.asList()) + return invokeMethod(instance, instance.referenceType().findMethod(name, methodSignature), params.asList()) } } - -private fun findSingleMethod(type: ReferenceType, name: String, methodSignature: String?): Method { - return DebuggerUtils.findMethod(type, name, methodSignature) ?: error("Method {$name} {$methodSignature} not found") -} diff --git a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/EvaluatorValueConverter.kt b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/EvaluatorValueConverter.kt index e8aa23b21828..92ac0a04049f 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/EvaluatorValueConverter.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/EvaluatorValueConverter.kt @@ -5,9 +5,9 @@ package org.jetbrains.kotlin.idea.debugger.evaluate.variables import com.sun.jdi.* import org.jetbrains.kotlin.fileClasses.internalNameWithoutInnerClasses import org.jetbrains.kotlin.idea.debugger.base.util.evaluate.ExecutionContext -import org.jetbrains.kotlin.idea.debugger.evaluate.variables.VariableFinder.Result +import org.jetbrains.kotlin.idea.debugger.base.util.findMethod import org.jetbrains.kotlin.idea.debugger.base.util.isSubtype -import org.jetbrains.kotlin.resolve.jvm.AsmTypes +import org.jetbrains.kotlin.idea.debugger.evaluate.variables.VariableFinder.Result import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType import kotlin.jvm.internal.Ref import com.sun.jdi.Type as JdiType @@ -150,7 +150,7 @@ class EvaluatorValueConverter(val context: ExecutionContext) { ?: error("Class $boxedType is not loaded") val methodDesc = AsmType.getMethodDescriptor(boxedType, unboxedType) - val valueOfMethod = boxedTypeClass.methodsByName("valueOf", methodDesc).first() + val valueOfMethod = boxedTypeClass.findMethod("valueOf", methodDesc) return context.invokeMethod(boxedTypeClass, valueOfMethod, listOf(value)) } @@ -166,7 +166,7 @@ class EvaluatorValueConverter(val context: ExecutionContext) { val unboxingMethodName = UNBOXING_METHOD_NAMES.getValue(boxedType.internalName) val methodDesc = AsmType.getMethodDescriptor(unboxedType) - val valueMethod = boxedTypeClass.methodsByName(unboxingMethodName, methodDesc).first() + val valueMethod = boxedTypeClass.findMethod(unboxingMethodName, methodDesc) return context.invokeMethod(value, valueMethod, emptyList()) } diff --git a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt index b9758d87ed9e..8db738729557 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt @@ -1,7 +1,8 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.debugger.evaluate.variables +import com.intellij.debugger.engine.DebuggerUtils import com.intellij.debugger.engine.JavaValue import com.intellij.debugger.engine.evaluation.AdditionalContextProvider import com.intellij.debugger.engine.evaluation.EvaluationContextImpl @@ -487,8 +488,7 @@ class VariableFinder(val context: ExecutionContext) { ?.allInterfaces()?.firstOrNull { it.name() == Continuation::class.java.name } ?: return null - val getContextMethod = continuationType - .methodsByName("getContext", "()Lkotlin/coroutines/CoroutineContext;").firstOrNull() + val getContextMethod = DebuggerUtils.findMethod(continuationType, "getContext", "()Lkotlin/coroutines/CoroutineContext;") ?: return null return context.invokeMethod(continuation, getContextMethod, emptyList()) as? ObjectReference @@ -561,8 +561,7 @@ class VariableFinder(val context: ExecutionContext) { } val delegateValue = rawValue as? ObjectReference ?: return rawValue - val getValueMethod = delegateValue.referenceType() - .methodsByName("getValue", "()Ljava/lang/Object;").firstOrNull() + val getValueMethod = DebuggerUtils.findMethod(delegateValue.referenceType(), "getValue", "()Ljava/lang/Object;") ?: return rawValue return context.invokeMethod(delegateValue, getValueMethod, emptyList())