Exemplo n.º 1
0
  private void processRequestMappingMethod(ExecutableElement executableElement) {
    TypeElement cls = (TypeElement) executableElement.getEnclosingElement();
    String path = getClassLevelUrlPath(cls);

    RequestMapping anno = executableElement.getAnnotation(RequestMapping.class);
    path = addMethodPathComponent(executableElement, cls, path, anno);
    RequestMethod meth = getRequestMethod(executableElement, cls, anno);

    RestDocumentation.Resource.Method doc =
        _docs.getResourceDocumentation(path).newMethodDocumentation(meth);
    String docComment = processingEnv.getElementUtils().getDocComment(executableElement);
    if (StringUtils.isNotBlank(docComment)) {
      MethodStructure methodStructure = generateMethodStructure(docComment);
      doc.setCommentText(generateJavaDocHTML(methodStructure));
      doc.setCommentSummary(methodStructure.getDescription());
    }
    buildParameterData(executableElement, doc);
    buildResponseFormat(executableElement.getReturnType(), doc);
  }
Exemplo n.º 2
0
  private static String generateJavaDocHTML(MethodStructure methodStructure) {
    DL dl = new DL();

    //
    // Deprecated
    //
    if (methodStructure.isDeprecated()) {
      DD deprecatedDD = new DD();

      B b = new B("Deprecated. ");
      deprecatedDD.addElement(b);

      I i = new I(methodStructure.getDeprecatedMessage());
      deprecatedDD.addElement(i);
      deprecatedDD.addElement(new P());

      dl.addElement(deprecatedDD);
    }

    //
    // Description
    //
    DD descriptionDD = new DD();
    P descriptionP = new P(methodStructure.getDescription(), "");
    descriptionDD.addElement(descriptionP);
    descriptionDD.addElement(new P());
    dl.addElement(descriptionDD);

    DD extraInfoDD = new DD();
    DL extraInfoDL = new DL();
    extraInfoDD.addElement(extraInfoDL);

    //
    // Params
    //
    if (!methodStructure.getParams().isEmpty()) {
      DT dt = new DT();
      dt.addElement(new B("Parameters:"));
      extraInfoDL.addElement(dt);
      for (Map.Entry<String, String> paramMap : methodStructure.getParams().entrySet()) {
        DD paramDD = new DD();
        Code paramName = new Code(paramMap.getKey());
        paramDD.addElement(paramName);
        paramDD.addElement(" - " + paramMap.getValue());
        extraInfoDL.addElement(paramDD);
      }
    }

    //
    // Returns
    //
    if (StringUtils.isNotBlank(methodStructure.getReturns())) {
      DT dt = new DT();
      dt.addElement(new B("Returns:"));
      extraInfoDL.addElement(dt);
      extraInfoDL.addElement(new DD(methodStructure.getReturns()));
    }

    //
    // Throws
    //
    if (!methodStructure.getExceptions().isEmpty()) {
      DT dt = new DT();
      dt.addElement(new B("Throws:"));
      extraInfoDL.addElement(dt);
      for (Map.Entry<String, String> exceptionMap : methodStructure.getExceptions().entrySet()) {
        DD exceptionDD = new DD();
        Code exceptionName = new Code(exceptionMap.getKey());
        exceptionDD.addElement(exceptionName);
        exceptionDD.addElement(" - " + exceptionMap.getValue());
        extraInfoDL.addElement(exceptionDD);
      }
    }

    //
    // Since
    //
    if (StringUtils.isNotBlank(methodStructure.getSince())) {
      DT dt = new DT();
      dt.addElement(new B("Since:"));
      extraInfoDL.addElement(dt);
      extraInfoDL.addElement(new DD(methodStructure.getSince()));
    }

    //
    // See
    //
    if (StringUtils.isNotBlank(methodStructure.getSeeAlso())) {
      DT dt = new DT();
      dt.addElement(new B("See Also:"));
      extraInfoDL.addElement(dt);
      extraInfoDL.addElement(new DD(methodStructure.getSeeAlso()));
    }

    dl.addElement(extraInfoDD);

    return dl.toString();
  }
Exemplo n.º 3
0
  private static MethodStructure generateMethodStructure(String docComment) {
    MethodStructure methodStructure = new MethodStructure();

    parseNameDescriptionObj(
        docComment,
        0,
        methodStructure,
        "@param",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            methodStructure.addParam(args[0], args[1]);
          }
        });
    parseNameDescriptionObj(
        docComment,
        0,
        methodStructure,
        "@throws",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            methodStructure.addException(args[0], args[1]);
          }
        });
    parseValueObj(
        docComment,
        methodStructure,
        "@return",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            methodStructure.setReturns(args[0]);
          }
        });
    parseValueObj(
        docComment,
        methodStructure,
        "@deprecated",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            if (args[0] != null && !args[0].isEmpty()) {
              methodStructure.setDeprecated(true);
              methodStructure.setDeprecatedMessage(args[0]);
            }
          }
        });
    parseValueObj(
        docComment,
        methodStructure,
        "@since",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            methodStructure.setSince(args[0]);
          }
        });
    parseValueObj(
        docComment,
        methodStructure,
        "@see",
        new ParseProcessor() {
          @Override
          public void processEntry(MethodStructure methodStructure, String... args) {
            methodStructure.setSeeAlso(args[0]);
          }
        });
    methodStructure.setDescription(
        docComment.substring(
            0, (docComment.indexOf("@") != -1 ? docComment.indexOf("@") : docComment.length())));
    return methodStructure;
  }