+ public static Object impose(Method _method, Object[] fields) {
+ try {
+ Class[] argTypes = _method.getParameterTypes();
+ Object[] args = new Object[argTypes.length];
+ int j = 0;
+ for(int i=0; i<args.length; i++) {
+ Object tgt = Reflection.lub(fields[i]);
+ 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));
+ args[i] = tgt;
+ }
+ //System.err.println("invoking " + _method + " with " + Reflection.show(args));
+ return _method.invoke(null, args);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Object impose(Constructor _ctor, Object[] fields) {
+ try {
+ Class[] argTypes = _ctor.getParameterTypes();
+ Object[] args = new Object[argTypes.length];
+ int j = 0;
+ for(int i=0; i<args.length; i++) {
+ Object tgt = Reflection.lub(fields[i]);
+ 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));
+ args[i] = tgt;
+ }
+ return _ctor.newInstance(args);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+