VariableUtils { public static boolean hasChildren(Value value, boolean includeStatic) { if (value == null || !(value instanceof ObjectReference)) { return false; } ReferenceType type = ((ObjectReference) value).referenceType(); if (type instanceof ArrayType) { return ((ArrayReference) value).length() > 0; } return type.allFields().stream().anyMatch(t -> includeStatic || !t.isStatic()); } private  VariableUtils(); static boolean hasChildren(Value value, boolean includeStatic); static List<Variable> listFieldVariables(ObjectReference obj, boolean includeStatic); static List<Variable> listFieldVariables(ObjectReference obj, int start, int count); static List<Variable> listLocalVariables(StackFrame stackFrame); static Variable getThisVariable(StackFrame stackFrame); static List<Variable> listStaticVariables(StackFrame stackFrame); static void applyFormatterOptions(Map<String, Object> defaultOptions, boolean hexInArgument); static String getEvaluateName(String name, String containerName, boolean isArrayElement);  }
@Test public void testHasChildren() throws Exception { ObjectReference foo = this.getObjectReference("Foo"); assertTrue("class Foo should have children", VariableUtils.hasChildren(foo, true)); assertTrue("class Foo should have children", VariableUtils.hasChildren(foo, false)); Value string = this.getLocalValue("str"); assertTrue("String object should have children", VariableUtils.hasChildren(string, true)); assertTrue("String object should have children", VariableUtils.hasChildren(string, false)); ArrayReference arrays = (ArrayReference) this.getLocalValue("arrays"); assertTrue("Array object with elements should have children", VariableUtils.hasChildren( arrays, true)); assertTrue("Array object with elements should have children", VariableUtils.hasChildren( arrays, false)); assertFalse("Array object with no elements should not have children", VariableUtils.hasChildren( ((ArrayType) arrays.type()).newInstance(0), true)); assertFalse("Array object with no elements should not have children", VariableUtils.hasChildren( ((ArrayType) arrays.type()).newInstance(0), false)); assertTrue("List object with elements should have children", VariableUtils.hasChildren( this.getLocalValue("strList"), false)); assertFalse("Object should not have children", VariableUtils.hasChildren(this.getLocalValue("obj"), true)); assertFalse("Object should not have children", VariableUtils.hasChildren(this.getLocalValue("obj"), false)); assertTrue("Class object should have children", VariableUtils.hasChildren(this.getLocalValue("b"), false)); assertTrue("Class object should have children", VariableUtils.hasChildren(this.getLocalValue("b"), false)); assertFalse("Null object should not have children", VariableUtils.hasChildren(null, true)); assertFalse("Null object should not have children", VariableUtils.hasChildren(null, false)); assertTrue("Boolean object should have children", VariableUtils.hasChildren(getLocalValue("boolVar"), false)); assertFalse("boolean object should not have children", VariableUtils.hasChildren(getVM().mirrorOf(true), false)); assertFalse("Class with no fields should not have children", VariableUtils.hasChildren(this.getLocalValue("a"), true)); assertFalse("Class with no fields should not have children", VariableUtils.hasChildren(this.getLocalValue("a"), false)); assertFalse("Primitive object should not have children", VariableUtils.hasChildren( getVM().mirrorOf(1), true)); assertFalse("Primitive object should not have children", VariableUtils.hasChildren( getVM().mirrorOf(true), true)); assertFalse("Primitive object should not have children", VariableUtils.hasChildren( getVM().mirrorOf('c'), true)); assertFalse("Primitive object should not have children", VariableUtils.hasChildren( getVM().mirrorOf(1000L), true)); }