public static List collectInfos()

in impl/src/main/java/org/apache/peeco/impl/PeecoUtils.java [130:170]


    public static List<HttpHandlerInfo> collectInfos(Class clazz) throws RuntimeException
    {
        ArrayList<HttpHandlerInfo> infos = new ArrayList<>();

        for (Method method : clazz.getDeclaredMethods())
        {
            if (method.isAnnotationPresent(HttpHandler.class))
            {
                Class type = method.getDeclaringClass();
                HttpHandler annotation = method.getAnnotation(HttpHandler.class);
                boolean isRequestInParameterTypes = false;

                for (Class parameterType : method.getParameterTypes())
                {
                    if (parameterType.equals(Request.class))
                    {
                        isRequestInParameterTypes = true;
                    }
                }

                if (annotation != null
                        && (method.getReturnType() == Response.class || method.getReturnType() == CompletionStage.class)
                        && isRequestInParameterTypes)
                {
                    infos.add(new HttpHandlerInfo(type, method, annotation));
                }
                else
                {
                    throw new RuntimeException("Invalid method signature: " + method + ". The return type of the annotated method must be " +
                            Response.class.toString() + " or " + CompletionStage.class.toString() + "<Response>. The method signature must contain " +
                            Request.class.toString() + ".");
                }
            }
        }

        //Matching.EXACT should be first in the list
        Comparator<HttpHandlerInfo> infoMatchingComparator = Comparator.comparing((HttpHandlerInfo info) -> info.annotation.matching());
        infos.sort(infoMatchingComparator);

        return infos;
    }