Search in sources :

Example 1 with ArgInfo

use of ren.yale.java.method.ArgInfo in project Summer by yale8848.

the class MethodsProcessor method get.

public static void get(List<ClassInfo> classInfos, Class clazz) {
    Path path = (Path) clazz.getAnnotation(Path.class);
    if (path == null || path.value() == null) {
        return;
    }
    ClassInfo classInfo = new ClassInfo();
    classInfo.setClassPath(path.value());
    classInfo.setClazzObj(newClass(clazz));
    classInfo.setClazz(clazz);
    Interceptor[] interceptorsClazz = getBefores((Before) clazz.getAnnotation(Before.class));
    if (interceptorsClazz != null) {
        classInfo.setBefores(interceptorsClazz);
    }
    interceptorsClazz = getAfters((After) clazz.getAnnotation(After.class));
    if (interceptorsClazz != null) {
        classInfo.setAfters(interceptorsClazz);
    }
    for (Method method : clazz.getMethods()) {
        Class mt = method.getDeclaringClass();
        if (mt == Object.class) {
            continue;
        }
        MethodInfo methodInfo = new MethodInfo();
        Interceptor[] interceptorsMethod = getBefores((Before) method.getAnnotation(Before.class));
        if (interceptorsMethod != null) {
            methodInfo.setBefores(interceptorsMethod);
        }
        interceptorsMethod = getAfters((After) method.getAnnotation(After.class));
        if (interceptorsMethod != null) {
            methodInfo.setAfters(interceptorsMethod);
        }
        Blocking blocking = method.getAnnotation(Blocking.class);
        if (blocking != null) {
            methodInfo.setBlocking(true);
        }
        Path pathMthod = (Path) method.getAnnotation(Path.class);
        Produces produces = (Produces) method.getAnnotation(Produces.class);
        methodInfo.setMethodPath(getPathValue(pathMthod));
        methodInfo.setProducesType(getProducesValue(produces));
        methodInfo.setHttpMethod(getHttpMethod(method));
        methodInfo.setMethod(method);
        Parameter[] parameters = method.getParameters();
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] annotations = method.getParameterAnnotations();
        int i = 0;
        for (Annotation[] an : annotations) {
            ArgInfo argInfo = new ArgInfo();
            argInfo.setAnnotation(an);
            argInfo.setClazz(parameterTypes[i]);
            argInfo.setParameter(parameters[i]);
            for (Annotation ant : an) {
                if (ant instanceof Context) {
                    argInfo.setContext(true);
                } else if (ant instanceof DefaultValue) {
                    argInfo.setDefaultValue(((DefaultValue) ant).value());
                } else if (ant instanceof PathParam) {
                    argInfo.setPathParam(true);
                    argInfo.setPathParam(((PathParam) ant).value());
                } else if (ant instanceof QueryParam) {
                    argInfo.setQueryParam(true);
                    argInfo.setQueryParam(((QueryParam) ant).value());
                } else if (ant instanceof FormParam) {
                    argInfo.setFormParam(true);
                    argInfo.setFormParam(((FormParam) ant).value());
                }
            }
            i++;
            methodInfo.addArgInfo(argInfo);
        }
        classInfo.addMethodInfo(methodInfo);
    }
    classInfos.add(classInfo);
}
Also used : Context(javax.ws.rs.core.Context) Blocking(ren.yale.java.annotation.Blocking) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ArgInfo(ren.yale.java.method.ArgInfo) After(ren.yale.java.aop.After) Parameter(java.lang.reflect.Parameter) MethodInfo(ren.yale.java.method.MethodInfo) Interceptor(ren.yale.java.interceptor.Interceptor) ClassInfo(ren.yale.java.method.ClassInfo)

Example 2 with ArgInfo

use of ren.yale.java.method.ArgInfo in project Summer by yale8848.

the class SummerRouter method getArgs.

private Object[] getArgs(RoutingContext routingContext, ClassInfo classInfo, MethodInfo methodInfo) {
    Object[] objects = new Object[methodInfo.getArgInfoList().size()];
    int i = 0;
    for (ArgInfo argInfo : methodInfo.getArgInfoList()) {
        if (argInfo.isContext()) {
            objects[i] = getContext(routingContext, argInfo);
        } else if (argInfo.isQueryParam()) {
            objects[i] = getQueryParamArg(routingContext, argInfo);
        } else if (argInfo.isFormParam()) {
            objects[i] = getFromParamArg(routingContext, argInfo);
        } else if (argInfo.isPathParam()) {
            objects[i] = getPathParamArg(routingContext, argInfo);
        } else {
            objects[i] = null;
        }
        i++;
    }
    return objects;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ArgInfo(ren.yale.java.method.ArgInfo)

Aggregations

ArgInfo (ren.yale.java.method.ArgInfo)2 JsonObject (io.vertx.core.json.JsonObject)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Context (javax.ws.rs.core.Context)1 Blocking (ren.yale.java.annotation.Blocking)1 After (ren.yale.java.aop.After)1 Interceptor (ren.yale.java.interceptor.Interceptor)1 ClassInfo (ren.yale.java.method.ClassInfo)1 MethodInfo (ren.yale.java.method.MethodInfo)1