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();
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;
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);
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);
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() &&
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);
}
}
return o;
}
- public static abstract class Bindable {
- public abstract String getSimpleName();
- public abstract String toString();
- public abstract <A extends Annotation> A getAnnotation(Class<A> c);
- public boolean isAnnotationPresent(Class<? extends Annotation> c) { return getAnnotation(c) != null; }
- public static Bindable create(Object o) {
- if (o instanceof Class) return new BindableClass((Class)o);
- if (o instanceof Method) return new BindableMethod((Method)o);
- if (o instanceof Constructor) return new BindableConstructor((Constructor)o);
- return null;
- }
- }
-
- private static class BindableMethod extends Bindable {
- private final Method _method;
- public String toString() { return "BindableMethod["+_method+"]"; }
- public BindableMethod(Method _method) { this._method = _method; }
- public String getSimpleName() { return _method.getName(); }
- public <A extends Annotation> A getAnnotation(Class<A> c) { return _method.getAnnotation(c); }
- }
- private static class BindableConstructor extends Bindable {
- private final Constructor _constructor;
- public String toString() { return "BindableConstructor["+_constructor+"]"; }
- public BindableConstructor(Constructor _constructor) { this._constructor = _constructor; }
- public String getSimpleName() { return _constructor.getName(); }
- public <A extends Annotation> A getAnnotation(Class<A> c) { return _constructor.getAnnotation(c); }
- }
- private static class BindableClass extends Bindable {
- private final Class _class;
- public String toString() { return "BindableClass["+_class+"]"; }
- public BindableClass(Class _class) { this._class = _class; }
- public String getSimpleName() { return _class.getSimpleName(); }
- public <A extends Annotation> A getAnnotation(Class<A> c) { return (A)_class.getAnnotation(c); }
- }
-
}