use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod in project ezyfox-server by youngmonkeys.
the class EzyExceptionHandlerProxy method fetchExceptionHandlerMethods.
public List<EzyExceptionHandlerMethod> fetchExceptionHandlerMethods() {
List<EzyExceptionHandlerMethod> list = new ArrayList<>();
List<EzyMethod> methods = clazz.getPublicMethods(m -> m.isAnnotated(EzyTryCatch.class));
for (EzyMethod method : methods) {
EzyExceptionHandlerMethod m = new EzyExceptionHandlerMethod(method);
list.add(m);
}
return list;
}
use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod in project ezyfox-server by youngmonkeys.
the class EzyRequestControllerProxy method fetchExceptionHandlerMethods.
public List<EzyExceptionHandlerMethod> fetchExceptionHandlerMethods() {
List<EzyExceptionHandlerMethod> list = new ArrayList<>();
List<EzyMethod> methods = clazz.getMethods(m -> m.isAnnotated(EzyTryCatch.class));
for (EzyMethod method : methods) {
EzyExceptionHandlerMethod m = new EzyExceptionHandlerMethod(method);
list.add(m);
}
return list;
}
use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod in project ezyfox-server by youngmonkeys.
the class EzyExceptionHandlersImplementer method implement.
public Map<Class<?>, EzyUncaughtExceptionHandler> implement(Object exceptionHandler) {
Map<Class<?>, EzyUncaughtExceptionHandler> handlers = new HashMap<>();
EzyExceptionHandlerProxy proxy = new EzyExceptionHandlerProxy(exceptionHandler);
for (EzyExceptionHandlerMethod method : proxy.getExceptionHandlerMethods()) {
EzyExceptionHandlerImplementer implementer = newImplementer(proxy, method);
EzyUncaughtExceptionHandler handler = implementer.implement();
for (Class<?> exceptionClass : method.getExceptionClasses()) {
handlers.put(exceptionClass, handler);
}
}
return handlers;
}
use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod in project ezyfox-server by youngmonkeys.
the class EzyRequestHandlerImplementer method makeHandleExceptionMethodContent.
protected String makeHandleExceptionMethodContent() {
EzyMethod method = getHandleExceptionMethod();
EzyFunction function = new EzyFunction(method).throwsException();
EzyBody body = function.body();
Map<Class<?>, EzyExceptionHandlerMethod> exceptionHandlerMethodMap = controller.getExceptionHandlerMethodMap();
Set<Class<?>> exceptionClasses = exceptionHandlerMethodMap.keySet();
EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
for (Class<?> exceptionClass : exceptionTree.toList()) {
EzyExceptionHandlerMethod m = exceptionHandlerMethodMap.get(exceptionClass);
EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if(arg3 instanceof ").append(exceptionClass.getName()).append(") {");
body.append(instructionIf);
EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
instructionHandle.append("this.controller.").append(m.getName()).bracketopen();
appendHandleExceptionMethodArguments(m, instructionHandle, exceptionClass);
instructionHandle.bracketclose();
body.append(instructionHandle);
body.append(new EzyInstruction("\t", "\n", false).append("}"));
}
if (exceptionClasses.size() > 0) {
body.append(new EzyInstruction("\t", "\n", false).append("else {"));
body.append(new EzyInstruction("\t\t", "\n").append("throw arg3"));
body.append(new EzyInstruction("\t", "\n", false).append("}"));
} else {
body.append(new EzyInstruction("\t", "\n").append("throw arg3"));
}
return function.toString();
}
use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerImplementer method appendHandleExceptionMethodArguments.
protected void appendHandleExceptionMethodArguments(EzyExceptionHandlerMethod method, EzyInstruction instruction, Class<?> exceptionClass, String commandArg, String dataArg, String exceptionArg) {
int paramCount = 0;
Parameter[] parameters = method.getParameters();
Class<?> requestDataType = method.getRequestDataType();
for (Parameter parameter : parameters) {
Class<?> parameterType = parameter.getType();
if (parameterType == requestDataType) {
instruction.brackets(requestDataType).append(dataArg);
} 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 == String.class) {
instruction.append(commandArg);
} else if (Throwable.class.isAssignableFrom(parameterType)) {
instruction.brackets(exceptionClass).append(exceptionArg);
} else if (parameterType == boolean.class) {
instruction.append("false");
} else if (parameterType.isPrimitive()) {
instruction.append("0");
} else {
instruction.append("null");
}
if ((paramCount++) < (parameters.length - 1)) {
instruction.append(", ");
}
}
}
Aggregations