for (int i = 0; i < parameters.length; i++) {
methodParms.add(Parameter.of(parameters[i].getType().getErased(), "a" + i));
}
final DefParameters defParameters = DefParameters.fromParameters(methodParms);
final BlockBuilder methBody = builder.publicMethod(method.getReturnType(), method.getName())
.annotatedWith(OVERRIDE_ANNOTATION)
.parameters(defParameters)
.throws_(method.getCheckedExceptions());
// Put method body into conditional, executed only after initialization
BlockBuilder<ElseBlockBuilder> ifBody = Stmt.create().if_(
BooleanExpressionBuilder.create(Stmt.loadVariable(stateVar)));
ifBody.appendAll(getAroundInvokeStatements(method));
ifBody.appendAll(getBeforeStatements(method));
final List<Parameter> parms = defParameters.getParameters();
final Statement[] statementVars = new Statement[parms.size()];
for (int i = 0; i < parms.size(); i++) {
statementVars[i] = loadVariable(parms.get(i).getName());
}
if (!method.isPublic()) {
PrivateAccessUtil.addPrivateAccessStubs(privateAccessorType, builder, method, new Modifier[0]);
final Statement[] privateAccessStmts = new Statement[statementVars.length + 1];
privateAccessStmts[0] = Refs.get(proxyVar);
System.arraycopy(statementVars, 0, privateAccessStmts, 1, statementVars.length);
if (method.getReturnType().isVoid()) {
ifBody._(loadVariable("this").invoke(PrivateAccessUtil.getPrivateMethodName(method), privateAccessStmts));
}
else {
ifBody._(loadVariable("this").invoke(PrivateAccessUtil.getPrivateMethodName(method), privateAccessStmts).returnValue());
}
}
else {
if (method.getReturnType().isVoid()) {
ifBody._(loadVariable(proxyVar).invoke(method, statementVars));
}
else {
ifBody._(loadVariable(proxyVar).invoke(method, statementVars).returnValue());
}
}
ifBody.appendAll(getAfterStatements(method));
ifBody.appendAll(getAroundInvokeStatements(method));
BlockBuilder<StatementEnd> elseBody = ifBody.finish().else_();
// Must return in else body if method is not void
if (!method.getReturnType().isVoid()) {
elseBody.append(ProxyUtil.generateProxyMethodReturnStatement(method));
}
methBody.append(elseBody.finish());
methBody.finish();
}
if (renderEqualsAndHash) {
// implement hashCode()
builder.publicMethod(int.class, "hashCode")