Search in sources :

Example 1 with EzyClassTree

use of com.tvd12.ezyfox.reflect.EzyClassTree in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerImplementer method makeHandleExceptionMethodContent.

protected String makeHandleExceptionMethodContent() {
    EzyMethod method = getHandleExceptionMethod();
    EzyFunction function = new EzyFunction(method).throwsException();
    EzyBody body = function.body();
    Class<?>[] exceptionClasses = handlerMethod.getExceptionClasses();
    EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
    for (Class<?> exceptionClass : exceptionTree.toList()) {
        EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if(arg4 instanceof ").append(exceptionClass.getName()).append(") {");
        body.append(instructionIf);
        EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
        instructionHandle.append("this.exceptionHandler.").append(handlerMethod.getName()).bracketopen();
        appendHandleExceptionMethodArguments(instructionHandle, exceptionClass);
        instructionHandle.bracketclose();
        body.append(instructionHandle);
        body.append(new EzyInstruction("\t", "\n", false).append("}"));
    }
    body.append(new EzyInstruction("\t", "\n", false).append("else {"));
    body.append(new EzyInstruction("\t\t", "\n").append("throw arg4"));
    body.append(new EzyInstruction("\t", "\n", false).append("}"));
    return function.toString();
}
Also used : EzyClassTree(com.tvd12.ezyfox.reflect.EzyClassTree) EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Example 2 with EzyClassTree

use of com.tvd12.ezyfox.reflect.EzyClassTree in project ezyhttp by youngmonkeys.

the class ExceptionHandlerImplementer method makeHandleExceptionMethodContent.

protected String makeHandleExceptionMethodContent() {
    EzyMethod method = getHandleExceptionMethod();
    EzyFunction function = new EzyFunction(method);
    EzyBody body = function.body();
    Class<?>[] exceptionClasses = handlerMethod.getExceptionClasses();
    EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
    for (Class<?> exceptionClass : exceptionTree.toList()) {
        EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if (arg1 instanceof ").append(exceptionClass.getName()).append(") {");
        body.append(instructionIf);
        EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
        Class<?> returnType = handlerMethod.getReturnType();
        if (returnType != void.class) {
            instructionHandle.answer();
        }
        instructionHandle.append("this.exceptionHandler.").append(handlerMethod.getName()).bracketopen();
        appendHandleExceptionMethodArguments(handlerMethod, instructionHandle, exceptionClass);
        instructionHandle.bracketclose();
        body.append(instructionHandle);
        if (returnType == void.class) {
            body.append(new EzyInstruction("\t\t", "\n").append("return null"));
        }
        body.append(new EzyInstruction("\t", "\n", false).append("}"));
    }
    body.append(new EzyInstruction("\t", "\n").append("throw arg1"));
    return toThrowExceptionFunction(method, function);
}
Also used : EzyClassTree(com.tvd12.ezyfox.reflect.EzyClassTree) EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Example 3 with EzyClassTree

use of com.tvd12.ezyfox.reflect.EzyClassTree in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementer method makeHandleExceptionMethodContent.

protected String makeHandleExceptionMethodContent() {
    EzyMethod method = getHandleExceptionMethod();
    EzyFunction function = new EzyFunction(method).throwsException();
    EzyBody body = function.body();
    Map<Class<?>, ExceptionHandlerMethod> exceptionHandlerMethodMap = controller.getExceptionHandlerMethodMap();
    Set<Class<?>> exceptionClasses = exceptionHandlerMethodMap.keySet();
    EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
    for (Class<?> exceptionClass : exceptionTree.toList()) {
        ExceptionHandlerMethod m = exceptionHandlerMethodMap.get(exceptionClass);
        EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if (arg1 instanceof ").append(exceptionClass.getName()).append(") {");
        body.append(instructionIf);
        EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
        Class<?> returnType = m.getReturnType();
        if (returnType != void.class) {
            instructionHandle.answer();
        }
        instructionHandle.append("this.controller.").append(m.getName()).bracketopen();
        appendHandleExceptionMethodArguments(m, instructionHandle, exceptionClass);
        instructionHandle.bracketclose();
        body.append(instructionHandle);
        if (returnType == void.class) {
            body.append(new EzyInstruction("\t\t", "\n").append("return null"));
        }
        body.append(new EzyInstruction("\t", "\n", false).append("}"));
    }
    body.append(new EzyInstruction("\t", "\n").append("throw arg1"));
    return function.toString();
}
Also used : EzyClassTree(com.tvd12.ezyfox.reflect.EzyClassTree) EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) ExceptionHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)

Example 4 with EzyClassTree

use of com.tvd12.ezyfox.reflect.EzyClassTree 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();
}
Also used : EzyClassTree(com.tvd12.ezyfox.reflect.EzyClassTree) EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Aggregations

EzyFunction (com.tvd12.ezyfox.asm.EzyFunction)4 EzyBody (com.tvd12.ezyfox.asm.EzyFunction.EzyBody)4 EzyInstruction (com.tvd12.ezyfox.asm.EzyInstruction)4 EzyClass (com.tvd12.ezyfox.reflect.EzyClass)4 EzyClassTree (com.tvd12.ezyfox.reflect.EzyClassTree)4 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)4 CtClass (javassist.CtClass)4 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)1 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)1