X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FReflection.java;fp=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FReflection.java;h=da16336265460f02540e50e264483187e6927fe9;hb=eec21f64634c3a76436a263254fc890b56b5b34d;hp=247652a1dd333eaa375ac8a410b6c710a2c28f1d;hpb=d324d5d52c6602d69d333a6d786fc37177e4252c;p=sbp.git diff --git a/src/edu/berkeley/sbp/util/Reflection.java b/src/edu/berkeley/sbp/util/Reflection.java index 247652a..da16336 100644 --- a/src/edu/berkeley/sbp/util/Reflection.java +++ b/src/edu/berkeley/sbp/util/Reflection.java @@ -53,19 +53,7 @@ public final class Reflection { public static String show(Object o) { if (o==null) return "null"; - if (o instanceof Show) { - StringBuffer ret = new StringBuffer(); - for(Field f : o.getClass().getFields()) { - ret.append("\n" + f.getName() + " = "); - try { - ret.append(show(f.get(o))); - } catch (Exception e) { - ret.append("**"+e+"**"); - throw new RuntimeException(e); - } - } - return o.getClass().getName() + " {" + StringUtil.indent(ret.toString(), 4) + "\n}"; - } + if (o instanceof Show) return ((Show)o).toString(); if (! (o instanceof Object[])) return o.toString() + " : " + o.getClass().getName(); Object[] arr = (Object[])o; StringBuffer ret = new StringBuffer(); @@ -76,6 +64,20 @@ public final class Reflection { return ret.toString(); } + public static String show(Show o) { + StringBuffer ret = new StringBuffer(); + for(Field f : o.getClass().getFields()) { + ret.append("\n" + f.getName() + " = "); + try { + ret.append(show(f.get(o))); + } catch (Exception e) { + ret.append("**"+e+"**"); + throw new RuntimeException(e); + } + } + return o.getClass().getName() + " {" + StringUtil.indent(ret.toString(), 4) + "\n}"; + } + public static Object lub(Object argo) { if (argo instanceof Object[]) return lub((Object[])argo); return argo; @@ -197,5 +199,6 @@ public final class Reflection { return null; } - public static interface Show { } + public static interface Show { + } }