: cons.getParameterTypes();
BCMethod m = bc.declareMethod("copy", Object.class,
new Class[] {Object.class});
m.makePublic();
Code code = m.getCode(true);
code.anew().setType(type);
code.dup();
if (params.length == 1) {
code.aload().setParam(0);
code.checkcast().setType(params[0]);
}
code.invokespecial().setMethod(type, "<init>", void.class, params);
if (params.length == 0) {
code.dup();
code.aload().setParam(0);
code.checkcast().setType(Calendar.class);
code.invokevirtual().setMethod(Calendar.class, "getTimeInMillis",
long.class, null);
code.invokevirtual().setMethod(type, "setTimeInMillis", void.class,
new Class[] { long.class });
code.dup();
code.aload().setParam(0);
code.checkcast().setType(Calendar.class);
code.invokevirtual().setMethod(Calendar.class, "isLenient",
boolean.class, null);
code.invokevirtual().setMethod(type, "setLenient", void.class,
new Class[] { boolean.class });
code.dup();
code.aload().setParam(0);
code.checkcast().setType(Calendar.class);
code.invokevirtual().setMethod(Calendar.class, "getFirstDayOfWeek",
int.class, null);
code.invokevirtual().setMethod(type, "setFirstDayOfWeek",
void.class, new Class[] { int.class });
code.dup();
code.aload().setParam(0);
code.checkcast().setType(Calendar.class);
code.invokevirtual().setMethod(Calendar.class,
"getMinimalDaysInFirstWeek", int.class, null);
code.invokevirtual().setMethod(type, "setMinimalDaysInFirstWeek",
void.class, new Class[] { int.class });
code.dup();
code.aload().setParam(0);
code.checkcast().setType(Calendar.class);
code.invokevirtual().setMethod(Calendar.class, "getTimeZone",
TimeZone.class, null);
code.invokevirtual().setMethod(type, "setTimeZone", void.class,
new Class[] { TimeZone.class });
}
code.areturn();
code.calculateMaxStack();
code.calculateMaxLocals();
// new instance factory
m = bc.declareMethod("newInstance", ProxyCalendar.class, null);
m.makePublic();
code = m.getCode(true);
code.anew().setType(bc);
code.dup();
code.invokespecial().setMethod("<init>", void.class, null);
code.areturn();
code.calculateMaxStack();
code.calculateMaxLocals();
// proxy the protected computeFields method b/c it is called on
// mutate, and some setters are final and therefore not proxyable
m = bc.declareMethod("computeFields", void.class, null);
m.makeProtected();
code = m.getCode(true);
code.aload().setThis();
code.constant().setValue(true);
code.invokestatic().setMethod(Proxies.class, "dirty", void.class,
new Class[] { Proxy.class, boolean.class });
code.aload().setThis();
code.invokespecial().setMethod(type, "computeFields", void.class, null);
code.vreturn();
code.calculateMaxStack();
code.calculateMaxLocals();
}