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();
}
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;
}
Aggregations