Example #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);
  }
Example #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();
  }