PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(serviceInterface.getName(),
"delegate", null, null);
// If not concerned with efficiency, this might be done with method advice instead.
delegateMethod.changeImplementation(new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
builder.loadThis().getField(plasticClass.getClassName(), creatorField.getName(),
ObjectCreator.class);
builder.invoke(ObjectCreator.class, Object.class, "createObject").checkcast(serviceInterface)
.returnResult();
}
});
for (Method m : serviceInterface.getMethods())
{
plasticClass.introduceMethod(m).delegateTo(delegateMethod);
}
plasticClass.introduceMethod(WRITE_REPLACE).changeImplementation(new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
builder.loadThis()
.getField(plasticClass.getClassName(), tokenField.getName(), ServiceProxyToken.class)