public static ReferenceType getSuperClass( final String baseQualifiedName, ReferenceType checkedType) { if (baseQualifiedName.equals(checkedType.name())) { return checkedType; } if (checkedType instanceof ClassType) { ClassType classType = (ClassType) checkedType; ClassType superClassType = classType.superclass(); if (superClassType != null) { ReferenceType superClass = getSuperClass(baseQualifiedName, superClassType); if (superClass != null) { return superClass; } } List<InterfaceType> interfaces = classType.allInterfaces(); for (InterfaceType iface : interfaces) { ReferenceType superClass = getSuperClass(baseQualifiedName, iface); if (superClass != null) { return superClass; } } } if (checkedType instanceof InterfaceType) { List<InterfaceType> list = ((InterfaceType) checkedType).superinterfaces(); for (InterfaceType superInterface : list) { ReferenceType superClass = getSuperClass(baseQualifiedName, superInterface); if (superClass != null) { return superClass; } } } return null; }
private static ClassLoaderReference getClassLoader( EvaluationContext context, DebugProcess process) throws EvaluateException, InvocationException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException { // TODO: cache ClassType loaderClass = (ClassType) process.findClass(context, "java.net.URLClassLoader", context.getClassLoader()); Method ctorMethod = loaderClass.concreteMethodByName("<init>", "([Ljava/net/URL;Ljava/lang/ClassLoader;)V"); ClassLoaderReference reference = (ClassLoaderReference) process.newInstance( context, loaderClass, ctorMethod, Arrays.asList(createURLArray(context), context.getClassLoader())); keep(reference, context); return reference; }
private static ArrayReference createURLArray(EvaluationContext context) throws EvaluateException, InvocationException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException { DebugProcess process = context.getDebugProcess(); ArrayType arrayType = (ArrayType) process.findClass(context, "java.net.URL[]", context.getClassLoader()); ArrayReference arrayRef = arrayType.newInstance(1); keep(arrayRef, context); ClassType classType = (ClassType) process.findClass(context, "java.net.URL", context.getClassLoader()); VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl) process.getVirtualMachineProxy(); StringReference url = proxy.mirrorOf("file:a"); keep(url, context); ObjectReference reference = process.newInstance( context, classType, classType.concreteMethodByName("<init>", "(Ljava/lang/String;)V"), Collections.singletonList(url)); keep(reference, context); arrayRef.setValues(Collections.singletonList(reference)); return arrayRef; }