예제 #1
0
  /**
   * Adds a syntax to the syntaxsection
   *
   * @param doc, doc item that has to be add to the syntax section
   */
  void addSyntax(Doc doc) {
    if (doc.isConstructor() || doc.isMethod()) {
      StringBuffer syntaxBuffer = new StringBuffer();
      for (Parameter parameter : ((ExecutableMemberDoc) doc).parameters()) {
        syntaxBuffer.append(parameter.typeName() + " " + parameter.name());
        syntaxBuffer.append(", ");
      }
      if (syntaxBuffer.length() > 2) {
        syntaxBuffer.delete(syntaxBuffer.length() - 2, syntaxBuffer.length());
      }

      String returnType = "";

      if (doc.isMethod()) {
        MethodDoc methodDoc = (MethodDoc) doc;
        returnType = methodDoc.returnType().toString();
        int lastDot = returnType.lastIndexOf('.');
        if (lastDot != -1) {
          returnType = returnType.substring(lastDot + 1);
        }
        returnType += " ";
      }

      if (doc.isConstructor()) {
        addSyntax("<em>" + doc.commentText() + "</em>");
      }

      addSyntax(returnType + doc.name() + "(" + syntaxBuffer.toString() + ")");
    } else if (doc.isField()) {
      FieldDoc fieldDoc = (FieldDoc) doc;
      addSyntax(fieldDoc.type().typeName() + " " + doc.name());
    }
  }
 private static void processParameterAnnotations(MethodDoc methodDoc, MethodModel methodModel) {
   Parameter[] params = methodDoc.parameters();
   // Start with false here.  If we find the userId parameter this will be changed to true.
   methodModel.setIsAuthenticationRequired(false);
   Map<String, ParameterModel> paramMap = new HashMap<String, ParameterModel>();
   if (params != null) {
     for (Parameter param : params) {
       AnnotationDesc[] paramAnnos = param.annotations();
       if (paramAnnos != null) {
         for (AnnotationDesc ad : paramAnnos) {
           String qualifiedName = ad.annotationType().qualifiedName();
           Map<String, Object> annotationMap = mapAnnotation(ad);
           System.out.println(annotationMap);
           if (RequestBody.class.getName().equals(qualifiedName)) {
             // Request body
             String schema = SchemaUtils.getEffectiveSchema(param.type().qualifiedTypeName());
             if (schema != null) {
               Link link =
                   new Link("${" + param.type().qualifiedTypeName() + "}", param.typeName());
               methodModel.setRequestBody(link);
             }
           } else if (PathVariable.class.getName().equals(qualifiedName)) {
             // Path parameter
             ParameterModel paramModel = new ParameterModel();
             paramModel.setName(param.name());
             methodModel.addPathVariable(paramModel);
             paramMap.put(param.name(), paramModel);
           } else if (RequestParam.class.getName().equals(qualifiedName)) {
             // if this is the userId parameter then we do now show it,
             // rather it means this method requires authentication.
             if (AuthorizationConstants.USER_ID_PARAM.equals(
                 annotationMap.get(REQUEST_PARAMETER_VALUE))) {
               methodModel.setIsAuthenticationRequired(true);
             } else {
               ParameterModel paramModel = new ParameterModel();
               paramModel.setName(param.name());
               paramModel.setIsOptional(!(isRequired(annotationMap)));
               methodModel.addParameter(paramModel);
               paramMap.put(param.name(), paramModel);
             }
           }
         }
       }
     }
   }
   ParamTag[] paramTags = methodDoc.paramTags();
   if (paramTags != null) {
     for (ParamTag paramTag : paramTags) {
       ParameterModel paramModel = paramMap.get(paramTag.parameterName());
       if (paramModel != null) {
         paramModel.setDescription(paramTag.parameterComment());
       }
     }
   }
   System.out.println(methodModel);
   // Lookup the parameter descriptions
 }
예제 #3
0
  /**
   * Parses a method parameter type definition
   *
   * @param docParameter
   * @param paramComment
   * @return
   */
  protected static Param ParseParameter(Parameter docParameter, ParamTag paramComment) {
    assert (docParameter != null);

    Param xmlParameter = new Param();
    xmlParameter.name = docParameter.name();

    xmlParameter.type = ParseType(docParameter.type());

    if (paramComment != null) {
      xmlParameter.comment = paramComment.parameterComment();
    }

    xmlParameter.annotationInstances =
        ParseAnnotationInstances(docParameter.annotations(), docParameter.typeName());
    return xmlParameter;
  }