X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FReflection.java;h=2cc7b0a5933517372e3c028c81e3d714a0e4785e;hp=05de7dc44fbd588dee65af80acfa587599188e1e;hb=fa49c4e86eaabb1fad07bcfdfb004aa1fc0dea8a;hpb=1976ed1b8cf49284016a99114e717d46a3be3617 diff --git a/src/edu/berkeley/sbp/util/Reflection.java b/src/edu/berkeley/sbp/util/Reflection.java index 05de7dc..2cc7b0a 100644 --- a/src/edu/berkeley/sbp/util/Reflection.java +++ b/src/edu/berkeley/sbp/util/Reflection.java @@ -54,7 +54,7 @@ public final class Reflection { public static String show(Object o) { if (o==null) return "null"; - if (o instanceof Show) return ((Show)o).toString(); + if (o instanceof Show) return show((Show)o); if (! (o instanceof Object[])) return o.toString() + " : " + o.getClass().getName(); Object[] arr = (Object[])o; StringBuffer ret = new StringBuffer(); @@ -219,7 +219,7 @@ public final class Reflection { if (f[i].getType() == String.class) tgt = stringify(tgt); // FUGLY tgt = coerce(tgt, f[i].getType()); - System.err.println("setting a " + f[i].getType().getName() + " to " + Reflection.show(tgt)); + //System.err.println("setting a " + f[i].getType().getName() + " to " + Reflection.show(tgt)); f[i].set(ret, tgt); } return ret; @@ -239,10 +239,10 @@ public final class Reflection { if (argTypes[i] == String.class) tgt = Reflection.stringify(tgt); // FUGLY tgt = Reflection.coerce(tgt, argTypes[i]); - System.err.println("setting a " + argTypes[i].getName() + " to " + Reflection.show(tgt)); + //System.err.println("setting a " + argTypes[i].getName() + " to " + Reflection.show(tgt)); args[i] = tgt; } - System.err.println("invoking " + _method + " with " + Reflection.show(args)); + //System.err.println("invoking " + _method + " with " + Reflection.show(args)); return _method.invoke(null, args); } catch (Exception e) { throw new RuntimeException(e); @@ -259,7 +259,7 @@ public final class Reflection { if (argTypes[i] == String.class) tgt = Reflection.stringify(tgt); // FUGLY tgt = Reflection.coerce(tgt, argTypes[i]); - System.err.println("setting a " + argTypes[i].getName() + " to " + Reflection.show(tgt)); + //System.err.println("setting a " + argTypes[i].getName() + " to " + Reflection.show(tgt)); args[i] = tgt; } return _ctor.newInstance(args); @@ -284,6 +284,10 @@ public final class Reflection { if (c == char.class) { return o.toString().charAt(0); } + if (c==int.class || c==Integer.class) { + String s = (String)coerce(o, String.class); + return new Integer(Integer.parseInt(s)); + } if (o.getClass().isArray() && o.getClass().getComponentType().isArray() && @@ -311,12 +315,12 @@ public final class Reflection { for(int i=0; i<((Object[])o).length; i++) { Object ob = (((Object[])o)[i]); if (ob != null) { - System.err.println("no hit with " + c.getComponentType().getName() + " on " + Reflection.show(((Object[])o)[i])); + //System.err.println("no hit with " + c.getComponentType().getName() + " on " + Reflection.show(((Object[])o)[i])); ok = false; } } if (ok) { - System.err.println("hit with " + c.getComponentType().getName()); + //System.err.println("hit with " + c.getComponentType().getName()); return Array.newInstance(c.getComponentType(), ((Object[])o).length); } }