From 9af31244e72b25e2b9ca2bf4bef39eba324cfab8 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 28 Jul 2014 15:44:30 +0200 Subject: [PATCH] avoid unnecessary and time-consuming type resolution for method parameters --- .../expression/MethodEvaluator.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java index 69cbb140be86..2569559d2d11 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java @@ -30,7 +30,10 @@ import com.intellij.debugger.engine.evaluation.EvaluateRuntimeException; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.openapi.diagnostic.Logger; -import com.sun.jdi.*; +import com.sun.jdi.ClassType; +import com.sun.jdi.Method; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; import java.util.ArrayList; import java.util.List; @@ -127,14 +130,16 @@ public class MethodEvaluator implements Evaluator { _refType = ((ClassType)referenceType).superclass(); } Method jdiMethod = DebuggerUtils.findMethod(_refType, myMethodName, signature); - if (jdiMethod == null || jdiMethod.argumentTypes().size() != args.size()) { + if (signature == null) { + // we know nothing about expected method's signature, so trying to match my method name and parameter count // dummy matching, may be improved with types matching later - List methods = _refType.methodsByName(myMethodName); - for (Method method : methods) { - List types = method.argumentTypes(); - if (types.size() == args.size()) { - jdiMethod = method; - break; + // IMPORTANT! using argumentTypeNames() instead of argumentTypes() to avoid type resolution inside JDI, which may be time-consuming + if (jdiMethod == null || jdiMethod.argumentTypeNames().size() != args.size()) { + for (Method method : _refType.methodsByName(myMethodName)) { + if (method.argumentTypeNames().size() == args.size()) { + jdiMethod = method; + break; + } } } }