示例#1
0
 private List<Method> parseMethods(List nodes, Node parent) {
   List<Method> methods = new ArrayList<Method>(nodes.size());
   for (Element node : (List<Element>) nodes) {
     Method method = new Method();
     method.setName(node.attributeValue("name"));
     method.setParent(parent);
     DocResult docResult = parseDoc(node, method);
     method.setReturntype(node.attributeValue("returntype"));
     method.setArgs(parseFields(node.elements("arg"), docResult, method));
     method.setExs(parseFields(node.elements("ex"), docResult, method));
     methods.add(method);
   }
   return methods;
 }
示例#2
0
 private List<Enum> parseEnums(Element el, Node parent) {
   if (el == null) {
     return Collections.EMPTY_LIST;
   }
   List<Element> nodes = el.elements();
   List<Enum> enums = new ArrayList<Enum>(nodes.size());
   for (Element node : nodes) {
     Enum e = new Enum();
     e.setName(node.attributeValue("name"));
     e.setParent(parent);
     e.setFields(parseFields(node.elements("item"), parseDoc(node, e), e));
     enums.add(e);
   }
   return enums;
 }
示例#3
0
 private List<Service> parseServices(Element el, Node parent) {
   if (el == null) {
     return Collections.EMPTY_LIST;
   }
   List<Element> nodes = el.elements();
   List<Service> services = new ArrayList<Service>(nodes.size());
   for (Element node : nodes) {
     Service service = new Service();
     service.setName(node.attributeValue("name"));
     service.setParent(parent);
     parseDoc(node, service);
     service.setMethods(parseMethods(node.elements("method"), service));
     services.add(service);
   }
   Collections.sort(services);
   return services;
 }
示例#4
0
 private List<Object> parseObjects(Element el, Node parent) {
   if (el == null) {
     return Collections.EMPTY_LIST;
   }
   List<Element> nodes = el.elements();
   List<Object> objects = new ArrayList<Object>(nodes.size());
   for (Element node : nodes) {
     Object object = new Object();
     object.setName(node.attributeValue("name"));
     object.setParent(parent);
     DocResult docResult = parseDoc(node, object);
     object.setEx("true".equals(node.attributeValue("isEx")));
     object.setFields(parseFields(node.elements("field"), docResult, object));
     objects.add(object);
   }
   return objects;
 }
示例#5
0
 private List<Field> parseFields(List nodes, DocResult outerDoc, Node parent) {
   List<Field> fields = new ArrayList<Field>(nodes.size());
   for (Element node : (List<Element>) nodes) {
     Field field = new Field();
     String name = node.attributeValue("name");
     field.setName(name);
     field.setParent(parent);
     DocResult docResult = parseDoc(node, field);
     String type = node.attributeValue("type");
     field.setType(type);
     field.setRequired(!"optional".equals(node.attributeValue("required")));
     String index = node.attributeValue("index");
     if (index != null) {
       field.setIndex(Integer.parseInt(index));
     }
     String nodeName = node.getName();
     if ("const".equals(nodeName)) { // 常量
       field.setValue(node.element("value").getStringValue());
     } else if ("item".equals(nodeName)) { // 枚举项
       String value = node.attributeValue("value");
       field.setIndex(Integer.parseInt(value)); // 设置枚举项的index为对应value
       field.setValue(value);
     } else if ("ex".equals(nodeName)) { // 异常
       Doc fieldDoc = field.getDoc();
       if (fieldDoc == DocResult.NULL) {
         field.setDoc(fieldDoc = new Doc());
       }
       for (Map.Entry<String, String> entry : docResult.getErrors().entrySet()) { // 将doc中的异常信息写入属性
         fieldDoc.putTag(entry.getKey(), entry.getValue());
       }
       if (outerDoc != null) { // 方法文档不为空
         String outerEx = outerDoc.getError(name); // 读取方法文档中的异常描述
         if (StringUtils.isEmpty(fieldDoc.getDesc()) && outerEx != null) { // 如果自己的文档没有注释,则设置为方法的注释
           fieldDoc.setDesc(outerEx);
         }
         if ("Type.AnyException"
             .equals(type)) { // 如果是通用的AnyException,则将外部定义的类似@error 315 无效用户状态写入属性
           for (Map.Entry<String, String> entry : outerDoc.getErrors().entrySet()) {
             String key = entry.getKey();
             if (!key.endsWith("Exception")) { // 若果是Exception说明不是一个异常代码
               fieldDoc.putTag(entry.getKey(), entry.getValue());
             }
           }
         }
       }
     } else {
       field.setValue(node.attributeValue("default"));
     }
     if (outerDoc != null) {
       Doc outerFieldDoc = outerDoc.getFidleDoc(field.getName()); // 判断外部是否定义了字段的描述文档
       if (outerFieldDoc != null) {
         Doc fieldDoc = field.getDoc();
         if (fieldDoc == DocResult.NULL) {
           field.setDoc(outerFieldDoc);
         } else {
           if (StringUtils.isEmpty(fieldDoc.getDesc())) {
             fieldDoc.setDesc(outerFieldDoc.getDesc());
           }
           for (Map.Entry<String, String> entry : outerFieldDoc.getTags().entrySet()) {
             fieldDoc.putTagIfAbsent(entry.getKey(), entry.getValue()); // 默认内部注视优先
           }
         }
       }
     }
     fields.add(field);
   }
   return fields;
 }