Search in sources :

Example 6 with EzyBody

use of com.tvd12.ezyfox.asm.EzyFunction.EzyBody 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)

Example 7 with EzyBody

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

the class EzyAbstractHandlerImplementer method prepareHandleMethodArguments.

protected int prepareHandleMethodArguments(EzyBody body) {
    int paramCount = 0;
    Class<?> requestDataType = handlerMethod.getRequestDataType();
    Parameter[] parameters = handlerMethod.getParameters();
    for (Parameter parameter : parameters) {
        Class<?> parameterType = parameter.getType();
        EzyInstruction instruction = new EzyInstruction("\t", "\n").clazz(parameterType).append(" ").append(PARAMETER_PREFIX).append(paramCount).equal();
        if (parameterType == requestDataType) {
            instruction.cast(requestDataType, "arg2");
        } else if (EzyContext.class.isAssignableFrom(parameterType)) {
            instruction.append("arg0");
        } else if (parameterType == EzyUserSessionEvent.class) {
            instruction.append("arg1");
        } else if (parameterType == EzyUser.class) {
            instruction.append("arg1.getUser()");
        } else if (parameterType == EzySession.class) {
            instruction.append("arg1.getSession()");
        } else if (parameterType == boolean.class) {
            instruction.append("false");
        } else if (parameterType.isPrimitive()) {
            instruction.append("0");
        } else {
            instruction.append("null");
        }
        body.append(instruction);
        ++paramCount;
    }
    return paramCount;
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) Parameter(java.lang.reflect.Parameter) EzyContext(com.tvd12.ezyfoxserver.context.EzyContext)

Aggregations

EzyInstruction (com.tvd12.ezyfox.asm.EzyInstruction)7 EzyFunction (com.tvd12.ezyfox.asm.EzyFunction)6 EzyBody (com.tvd12.ezyfox.asm.EzyFunction.EzyBody)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 Parameter (java.lang.reflect.Parameter)2 EzyContext (com.tvd12.ezyfoxserver.context.EzyContext)1 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)1 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