예제 #1
0
 public void dump(Object o) {
   Set<Object> cache = CollectionFactory.newHashSet();
   w.write("(");
   dumpObject(o, cache);
   w.write(")");
   w.newline(0);
   try {
     w.flush();
   } catch (IOException e) {
   }
 }
예제 #2
0
  protected void dumpObject(Object obj, Set<Object> cache) {
    if (obj == null) {
      w.write("null");
      return;
    }

    w.write(StringUtil.getShortNameComponent(obj.getClass().getName()));

    //        w.allowBreak(0, " ");
    //        w.write(obj.toString());

    if (cache.contains(obj)) {
      return;
    }
    cache.add(obj);

    w.allowBreak(1, " ");
    w.begin(0);

    try {
      Field[] fields = obj.getClass().getDeclaredFields();
      java.lang.reflect.AccessibleObject.setAccessible(fields, true);
      for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if ((field.getModifiers() & modifiersMask) != 0) continue;
        w.write("(");
        w.write(field.getName());
        w.allowBreak(1, " ");
        try {
          Object o = field.get(obj);
          dumpObject(o, cache);
        } catch (IllegalAccessException exn) {
          w.write("##[" + exn.getMessage() + "]");
        }
        w.write(")");
        w.newline(0);
      }
    } catch (SecurityException exn) {
    }

    w.end();
  }