コード例 #1
0
  @Override
  public boolean process(
      Set<? extends TypeElement> supportedAnnotations, RoundEnvironment roundEnvironment) {

    // short-circuit if there are multiple rounds
    if (_isComplete) {
      return true;
    }

    Collection<String> processedPackageNames = new LinkedHashSet<String>();
    for (Element e : roundEnvironment.getElementsAnnotatedWith(RequestMapping.class)) {
      if (e instanceof ExecutableElement) {
        addPackageName(processedPackageNames, e);
        processRequestMappingMethod((ExecutableElement) e);
      }
    }

    if (_docs.getResources().size() > 0) {

      OutputStream fout = null;
      try {
        FileObject file = getOutputFile();
        boolean exists = new File(file.getName()).exists();
        fout = file.openOutputStream();
        _docs.toStream(fout);
        processingEnv
            .getMessager()
            .printMessage(
                Diagnostic.Kind.NOTE,
                String.format(
                    "Wrote REST docs for %s endpoints to %s file at %s",
                    _docs.getResources().size(), exists ? "existing" : "new", file.getName()));
      } catch (Exception e) {
        throw new RuntimeException(e); // TODO wrap in something nicer
      } finally {
        if (fout != null) {
          try {
            fout.close();
          } catch (IOException ignored) {
            // ignored
          }
        }
      }
    }
    _isComplete = true;
    return true;
  }
コード例 #2
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);
  }