From a61529944c1e0e0ffaaaa0dc9da73d8dbf239f5d Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 27 May 2016 19:05:44 +0300 Subject: [PATCH] do not look for Object type in instanceOf (it does linear search inside jdi) --- .../ui/tree/render/ToStringRenderer.java | 2 +- .../debugger/engine/DebuggerUtils.java | 51 +++++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java index 4fbcaaf616ff..dc1f9d5a6cba 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/tree/render/ToStringRenderer.java @@ -175,7 +175,7 @@ public class ToStringRenderer extends NodeRendererImpl { private boolean isFiltered(Type t) { if (t instanceof ReferenceType) { for (ClassFilter classFilter : myClassFilters) { - if (classFilter.isEnabled() && DebuggerUtils.getSuperType(t, classFilter.getPattern()) != null) { + if (classFilter.isEnabled() && DebuggerUtils.instanceOf(t, classFilter.getPattern())) { return true; } } diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java b/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java index ffd5ef82d81b..9f3b1229aac8 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java @@ -107,7 +107,7 @@ public abstract class DebuggerUtils { Method toStringMethod = debugProcess.getUserData(TO_STRING_METHOD_KEY); if (toStringMethod == null) { try { - ReferenceType refType = objRef.virtualMachine().classesByName(CommonClassNames.JAVA_LANG_OBJECT).get(0); + ReferenceType refType = getObjectClassType(objRef.virtualMachine()); toStringMethod = findMethod(refType, "toString", "()Ljava/lang/String;"); debugProcess.putUserData(TO_STRING_METHOD_KEY, toStringMethod); } @@ -153,13 +153,13 @@ public abstract class DebuggerUtils { public static Method findMethod(@NotNull ReferenceType refType, @NonNls String methodName, @Nullable @NonNls String methodSignature) { if (refType instanceof ArrayType) { // for array types methodByName() in JDI always returns empty list - Method method = findMethod(refType.virtualMachine().classesByName(CommonClassNames.JAVA_LANG_OBJECT).get(0), methodName, methodSignature); + Method method = findMethod(getObjectClassType(refType.virtualMachine()), methodName, methodSignature); if (method != null) { return method; } // for arrays, clone signature may return array of objects, there is no such method in Object class if ("clone".equals(methodName) && "()[Ljava/lang/Object;".equals(methodSignature)) { - method = findMethod(refType.virtualMachine().classesByName(CommonClassNames.JAVA_LANG_OBJECT).get(0), "clone", null); + method = findMethod(getObjectClassType(refType.virtualMachine()), "clone", null); if (method != null) { return method; } @@ -265,21 +265,35 @@ public abstract class DebuggerUtils { return false; } - @Nullable - public static Type getSuperType(@Nullable Type subType, @NotNull String superType) { - if (subType == null) return null; + public static boolean instanceOf(@Nullable Type subType, @NotNull String superType) { + if (subType == null || subType instanceof PrimitiveType || subType instanceof VoidType) { + return false; + } if (CommonClassNames.JAVA_LANG_OBJECT.equals(superType)) { - List list = subType.virtualMachine().classesByName(CommonClassNames.JAVA_LANG_OBJECT); - if(list.size() > 0) { - return (ReferenceType)list.get(0); - } + return true; + } + + return getSuperTypeInt(subType, superType) != null; + } + + @Nullable + public static Type getSuperType(@Nullable Type subType, @NotNull String superType) { + if (subType == null || subType instanceof PrimitiveType || subType instanceof VoidType) { return null; } + if (CommonClassNames.JAVA_LANG_OBJECT.equals(superType)) { + return getObjectClassType(subType.virtualMachine()); + } + return getSuperTypeInt(subType, superType); } + private static ReferenceType getObjectClassType(VirtualMachine virtualMachine) { + return ContainerUtil.getFirstItem(virtualMachine.classesByName(CommonClassNames.JAVA_LANG_OBJECT)); + } + private static boolean typeEquals(@NotNull Type type, @NotNull String typeName) { int genericPos = typeName.indexOf('<'); if (genericPos > -1) { @@ -339,27 +353,10 @@ public abstract class DebuggerUtils { } } } - else if (subType instanceof PrimitiveType) { - //noinspection HardCodedStringLiteral - if(superType.equals("java.lang.Primitive")) { - return subType; - } - } - //only for interfaces and arrays - if(CommonClassNames.JAVA_LANG_OBJECT.equals(superType)) { - List list = subType.virtualMachine().classesByName(CommonClassNames.JAVA_LANG_OBJECT); - if(list.size() > 0) { - return (ReferenceType)list.get(0); - } - } return null; } - public static boolean instanceOf(@Nullable Type subType, @NotNull String superType) { - return getSuperType(subType, superType) != null; - } - @Nullable public static PsiClass findClass(@NotNull final String className, @NotNull Project project, final GlobalSearchScope scope) { ApplicationManager.getApplication().assertReadAccessAllowed();