[debugger] use DebuggerUtils.findMethod pt.2

GitOrigin-RevId: f83c4b1ffce05dc64dcef85eb4f293027113e7ab
This commit is contained in:
Egor Ushakov
2024-10-17 14:19:16 +00:00
committed by intellij-monorepo-bot
parent cfa1938d3d
commit b281b92e5b
5 changed files with 26 additions and 26 deletions
@@ -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<Method> 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);
}
@@ -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 }
}
}
fun ReferenceType.findMethod(name: String, methodSignature: String?): Method {
return DebuggerUtils.findMethod(this, name, methodSignature) ?: error("Method {$name} {$methodSignature} not found")
}
@@ -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")
}
@@ -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())
}
@@ -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())