예제 #1
0
  private static String getCommentText(FieldItem fieldItem) {
    StringBuilder sb = new StringBuilder();
    sb.append(" //");
    String comment = fieldItem.getComment();
    if (StringHelper.isNotEmpty(comment)) {
      comment = comment.replaceAll("[\\r|\\n]", " ");
      sb.append(comment);
    }

    String since = fieldItem.getSince();
    if (StringHelper.isNotEmpty(since)) {
      sb.append(" @since ");
      sb.append(since);
    }

    String deprecated = fieldItem.getDeprecated();
    if (StringHelper.isNotEmpty(deprecated)) {
      sb.append(" @deprecated ");
      sb.append(deprecated);
    }

    sb.append(" @type ");
    sb.append(fieldItem.getFormatedTypeName());
    return sb.toString();
  }
예제 #2
0
  public static String toJson(FieldItem fieldItem, List<String> paths) {
    int level = paths.size();
    StringBuilder sb = new StringBuilder();
    String fullTypeName = fieldItem.getFormatedTypeName();
    if (paths.contains(fullTypeName)) {
      // 循环...
      sb.append(StringHelper.loopTab(level + 1));
      sb.append("//{...} 循环 @type " + fullTypeName);
      return sb.toString();
    }

    List<String> myPaths = new ArrayList<String>();
    myPaths.addAll(paths);

    myPaths.add(fullTypeName);

    List<FieldItem> items = fieldItem.getItems();
    String name = fieldItem.getName();
    if (items.isEmpty()) {
      // 如果是List
      sb.append(DocletConstant.TURN_LINE);
      sb.append(StringHelper.loopTab(level + 1));
      sb.append("\"");
      sb.append(name);
      sb.append("\"");
      sb.append(" : ");
      if ("java.util.List".equals(fullTypeName)) {
        sb.append(getListDemoValue(fieldItem, myPaths));
      } else {
        sb.append(getDefaultDemoValue(fieldItem));
        if (!fieldItem.isLastOne()) {
          sb.append(",");
        }
        sb.append(getCommentText(fieldItem));
      }
    } else {
      if (StringHelper.isNotEmpty(name)) {
        sb.append(DocletConstant.TURN_LINE);
        sb.append(StringHelper.loopTab(level + 1));
        sb.append("\"");
        sb.append(name);
        sb.append("\"");
        sb.append(" : ");
      }
      if (level > 0) {
        sb.append(StringHelper.loopTab(level + 1));
      }
      sb.append("{");
      sb.append(getCommentText(fieldItem));
      items.get(items.size() - 1).setLastOne(true);
      for (FieldItem item : items) {
        sb.append(toJson(item, myPaths));
      }

      sb.append(DocletConstant.TURN_LINE);
      sb.append(StringHelper.loopTab(level + 1));
      sb.append("}");
    }
    return sb.toString();
  }