in core/src/main/java/org/apache/calcite/util/Util.java [388:494]
public static void print(
PrintWriter pw,
@Nullable Object o,
int indent) {
if (o == null) {
pw.print("null");
return;
}
Class clazz = o.getClass();
if (o instanceof String) {
printJavaString(pw, (String) o, true);
} else if (
(clazz == Integer.class)
|| (clazz == Boolean.class)
|| (clazz == Character.class)
|| (clazz == Byte.class)
|| (clazz == Short.class)
|| (clazz == Long.class)
|| (clazz == Float.class)
|| (clazz == Double.class)
|| (clazz == Void.class)) {
pw.print(o.toString());
} else if (clazz.isArray()) {
// o is an array, but we can't cast to Object[] because it may be
// an array of primitives.
Object[] a; // for debug
if (o instanceof Object[]) {
a = (Object[]) o;
discard(a);
}
int n = Array.getLength(o);
pw.print("{");
for (int i = 0; i < n; i++) {
if (i > 0) {
pw.println(",");
} else {
pw.println();
}
for (int j = 0; j < indent; j++) {
pw.print("\t");
}
print(
pw,
Array.get(o, i),
indent + 1);
}
pw.print("}");
} else if (o instanceof Iterator) {
pw.print(clazz.getName());
Iterator iter = (Iterator) o;
pw.print(" {");
int i = 0;
while (iter.hasNext()) {
if (i++ > 0) {
pw.println(",");
}
print(
pw,
iter.next(),
indent + 1);
}
pw.print("}");
} else if (o instanceof Enumeration) {
pw.print(clazz.getName());
Enumeration e = (Enumeration) o;
pw.print(" {");
int i = 0;
while (e.hasMoreElements()) {
if (i++ > 0) {
pw.println(",");
}
print(
pw,
e.nextElement(),
indent + 1);
}
pw.print("}");
} else {
pw.print(clazz.getName());
pw.print(" {");
Field[] fields = clazz.getFields();
int printed = 0;
for (Field field : fields) {
if (isStatic(field)) {
continue;
}
if (printed++ > 0) {
pw.println(",");
} else {
pw.println();
}
for (int j = 0; j < indent; j++) {
pw.print("\t");
}
pw.print(field.getName());
pw.print("=");
Object val;
try {
val = field.get(o);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
print(pw, val, indent + 1);
}
pw.print("}");
}
}