Search in sources :

Example 1 with RouteNode

use of com.luojilab.router.facade.annotation.RouteNode in project ChidoriX by Chihiro23333.

the class RouterProcessor method parseRouteNodes.

private void parseRouteNodes(Set<? extends Element> routeElements) {
    TypeMirror type_Activity = elements.getTypeElement(ACTIVITY).asType();
    for (Element element : routeElements) {
        TypeMirror tm = element.asType();
        RouteNode route = element.getAnnotation(RouteNode.class);
        if (types.isSubtype(tm, type_Activity)) {
            // Activity
            logger.info(">>> Found activity route: " + tm.toString() + " <<<");
            Node node = new Node();
            String path = route.path();
            checkPath(path);
            node.setPath(path);
            node.setDesc(route.desc());
            node.setPriority(route.priority());
            node.setNodeType(NodeType.ACTIVITY);
            node.setRawType(element);
            Map<String, Integer> paramsType = new HashMap<>();
            Map<String, String> paramsDesc = new HashMap<>();
            for (Element field : element.getEnclosedElements()) {
                if (field.getKind().isField() && field.getAnnotation(Autowired.class) != null) {
                    Autowired paramConfig = field.getAnnotation(Autowired.class);
                    paramsType.put(StringUtils.isEmpty(paramConfig.name()) ? field.getSimpleName().toString() : paramConfig.name(), typeUtils.typeExchange(field));
                    paramsDesc.put(StringUtils.isEmpty(paramConfig.name()) ? field.getSimpleName().toString() : paramConfig.name(), typeUtils.typeDesc(field));
                }
            }
            node.setParamsType(paramsType);
            node.setParamsDesc(paramsDesc);
            if (!routerNodes.contains(node)) {
                routerNodes.add(node);
            }
        } else {
            throw new IllegalStateException("only activity can be annotated by RouteNode");
        }
    }
}
Also used : Autowired(com.luojilab.router.facade.annotation.Autowired) TypeMirror(javax.lang.model.type.TypeMirror) HashMap(java.util.HashMap) RouteNode(com.luojilab.router.facade.annotation.RouteNode) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) Node(com.luojilab.router.facade.model.Node) RouteNode(com.luojilab.router.facade.annotation.RouteNode)

Aggregations

Autowired (com.luojilab.router.facade.annotation.Autowired)1 RouteNode (com.luojilab.router.facade.annotation.RouteNode)1 Node (com.luojilab.router.facade.model.Node)1 HashMap (java.util.HashMap)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1