Example #1
0
  private void parseMethod(Api api, ExecutableElement executableElement) throws IOException {

    Element actionElement =
        generator
            .getProcessingEnvironment()
            .getElementUtils()
            .getTypeElement(ApiMethodDoc.class.getName());
    TypeMirror apiMethodDocType = actionElement.asType();

    for (AnnotationMirror am : executableElement.getAnnotationMirrors()) {
      if (am.getAnnotationType().equals(apiMethodDocType)) {
        api.apiMethodDoc = Maps.newHashMap();
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> ee :
            am.getElementValues().entrySet()) {
          api.apiMethodDoc.put(ee.getKey().getSimpleName().toString(), ee.getValue());
        }
        break;
      }
    }

    // generator.log("apiMethodDoc: " + api.apiMethodDoc);

    if (null == api.apiMethodDoc) {
      generator.log("Method miss @ApiMethodDoc. " + executableElement);
      return;
    }

    api.methodName = executableElement.getSimpleName().toString();
    api.methodMapping = executableElement.getAnnotation(RequestMapping.class);
    api.parameters = Lists.newArrayList();

    for (VariableElement var : executableElement.getParameters()) {
      api.parameters.add(var);
    }
  }
Example #2
0
 public void printElement(TypeElement typeElement) {
   List<? extends AnnotationMirror> annotationMirrors = typeElement.getAnnotationMirrors();
   generator.log("class: " + typeElement + ", annotations: " + annotationMirrors);
   for (Element ele : typeElement.getEnclosedElements()) {
     if (ele.getKind().equals(ElementKind.METHOD)) {
       ExecutableElement method = (ExecutableElement) ele;
       printMethod(method);
     }
   }
 }
Example #3
0
  private void printMethod(ExecutableElement executableElement) {
    StringBuilder s = new StringBuilder(256);
    s.append("method: " + executableElement).append("\n\t");
    s.append("annotations: " + executableElement.getAnnotationMirrors()).append("\n\t");
    s.append("return: " + executableElement.getReturnType()).append("\n\t");
    for (VariableElement var : executableElement.getParameters()) {
      s.append("parameter: " + var + ", " + var.getAnnotation(ApiParameterDoc.class))
          .append("\n\t");
    }

    generator.log(s.toString());
  }
Example #4
0
  /** @throws IOException */
  public List<Api> parse(TypeElement typeElement) throws IOException {

    RequestMapping requestMapping = typeElement.getAnnotation(RequestMapping.class);
    if (requestMapping == null) {
      generator.log("Controller missing @RequestMapping, " + typeElement);
      return null;
    }

    ApiDoc apiDoc = typeElement.getAnnotation(ApiDoc.class);
    if (apiDoc == null) {
      generator.log("Controller missing @ApiDoc, " + typeElement);
      return null;
    }

    // printElement(typeElement);

    List<Api> apiList = Lists.newArrayList();

    String controllerName = typeElement.getQualifiedName().toString();

    for (Element ele : typeElement.getEnclosedElements()) {
      if (ele.getKind().equals(ElementKind.METHOD)
          && ele.getModifiers().contains(Modifier.PUBLIC)) {

        Api api = new Api();
        api.apiDoc = apiDoc;
        api.packageMapping = requestMapping;
        api.controllerName = controllerName;

        ExecutableElement method = (ExecutableElement) ele;
        this.parseMethod(api, method);
        if (api.apiMethodDoc != null) {
          apiList.add(api);
        }
      }
    }

    return apiList;
  }