mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not look for Object type in instanceOf (it does linear search inside jdi)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user