private static Statement generateInterceptorStackProceedMethod(
final GeneratorContext context,
final Class<? extends RemoteCallContext> callContextType,
final Statement proceed, final List<Class<?>> interceptors) {
final BlockStatement proceedLogic = new BlockStatement();
proceedLogic.addStatement(Stmt.loadVariable("status").invoke("proceed"));
final BlockBuilder<ElseBlockBuilder> interceptorStack =
If.isNotNull(Stmt.loadVariable("status").invoke("getNextInterceptor"));
for (final Class<?> interceptor : interceptors) {
interceptorStack.append(If.cond(Bool.equals(
Stmt.loadVariable("status").invoke("getNextInterceptor"), interceptor))
.append(Stmt.loadVariable("status").invoke("setProceeding", false))
.append(Stmt.declareFinalVariable("ctx", callContextType, Stmt.loadVariable("this")))
.append(
Stmt.declareVariable(CreationalCallback.class).asFinal().named("icc")
.initializeWith(
Stmt.newObject(CreationalCallback.class).extend()
.publicOverridesMethod("callback", Parameter.of(Object.class, "beanInstance", true))
.append(
Stmt.castTo(interceptor, Stmt.loadVariable("beanInstance")).invoke("aroundInvoke",
Variable.get("ctx")))
.append(
If.not(Stmt.loadVariable("status").invoke("isProceeding"))
.append(
Stmt.loadVariable("remoteCallback").invoke("callback",
Stmt.loadVariable("ctx").invoke("getResult")))
.finish())
.finish() // finish the method override body
.finish() // finish the anonymous CreationalCallback class body
))
.append(generateAsyncInterceptorCreation(context, interceptor))
.finish()
);
}
proceedLogic.addStatement(interceptorStack.finish().else_().append(proceed).finish());
return proceedLogic;
}