Search in sources :

Example 6 with EzyFunction

use of com.tvd12.ezyfox.asm.EzyFunction in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlerImplementer method makeHandleRequestMethodContent.

protected String makeHandleRequestMethodContent() {
    EzyMethod method = getHandleRequestMethod();
    EzyFunction function = new EzyFunction(method).throwsException();
    EzyBody body = function.body();
    int paramCount = prepareHandleMethodArguments(body);
    EzyInstruction instruction = new EzyInstruction("\t", "\n");
    StringBuilder answerExpression = new StringBuilder();
    if (handlerMethod.getReturnType() != void.class) {
        answerExpression.append(Object.class.getName()).append(" data = ");
    }
    answerExpression.append("this.controller.").append(handlerMethod.getName()).append("(");
    for (int i = 0; i < paramCount; ++i) {
        answerExpression.append(PARAMETER_PREFIX).append(i);
        if (i < paramCount - 1) {
            answerExpression.append(", ");
        }
    }
    answerExpression.append(")");
    instruction.append(answerExpression);
    body.append(instruction);
    if (handlerMethod.getReturnType() != void.class) {
        EzyInstruction responseInstruction = new EzyInstruction("\t", "\n").invoke("this", "responseToSession", "arg1", "data");
        body.append(responseInstruction);
    }
    return function.toString();
}
Also used : EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Aggregations

EzyFunction (com.tvd12.ezyfox.asm.EzyFunction)6 EzyBody (com.tvd12.ezyfox.asm.EzyFunction.EzyBody)6 EzyInstruction (com.tvd12.ezyfox.asm.EzyInstruction)6 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)6 EzyClass (com.tvd12.ezyfox.reflect.EzyClass)4 EzyClassTree (com.tvd12.ezyfox.reflect.EzyClassTree)4 CtClass (javassist.CtClass)4 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)1 PathVariable (com.tvd12.ezyhttp.server.core.annotation.PathVariable)1 RequestBody (com.tvd12.ezyhttp.server.core.annotation.RequestBody)1 RequestCookie (com.tvd12.ezyhttp.server.core.annotation.RequestCookie)1 RequestHeader (com.tvd12.ezyhttp.server.core.annotation.RequestHeader)1 RequestParam (com.tvd12.ezyhttp.server.core.annotation.RequestParam)1 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)1 Parameter (java.lang.reflect.Parameter)1