/**
   * Parse type variables for generics
   *
   * @param variables
   * @return
   */
  protected static TypeVar[] ParseTypeVariables(TypeVariable[] variables, ParamTag[] tags) {
    TypeVar[] vars = null;

    if (variables != null && variables.length > 0) {
      ArrayList<TypeVar> varsList = new ArrayList<TypeVar>();

      for (TypeVariable variable : variables) {
        TypeVar var = new TypeVar();
        var.name = variable.typeName();
        Type[] bounds = variable.bounds();
        if (bounds != null && bounds.length > 0) {
          ArrayList<String> list = new ArrayList<String>();

          for (Type bound : bounds) {
            list.add(bound.qualifiedTypeName());
          }

          var.bounds = list.toArray(new String[] {});
        }
        for (ParamTag tag : tags)
          if (tag.parameterName().equals(var.name)) var.comment = tag.parameterComment();

        varsList.add(var);
      }

      vars = varsList.toArray(new TypeVar[] {});
    }

    return vars;
  }
Exemple #2
0
 /**
  * Given an array of <code>Tag</code>s representing this custom tag, return its string
  * representation. Print a warning for param tags that do not map to parameters. Print a warning
  * for param tags that are duplicated.
  *
  * @param paramTags the array of <code>ParamTag</code>s to convert.
  * @param writer the TagletWriter that will write this tag.
  * @param alreadyDocumented the set of exceptions that have already been documented.
  * @param rankMap a {@link java.util.Map} which holds ordering information about the parameters.
  * @param nameMap a {@link java.util.Map} which holds a mapping of a rank of a parameter to its
  *     name. This is used to ensure that the right name is used when parameter documentation is
  *     inherited.
  * @return the TagletOutput representation of this <code>Tag</code>.
  */
 private TagletOutput processParamTags(
     boolean isNonTypeParams,
     ParamTag[] paramTags,
     Map rankMap,
     TagletWriter writer,
     Set alreadyDocumented) {
   TagletOutput result = writer.getOutputInstance();
   if (paramTags.length > 0) {
     for (int i = 0; i < paramTags.length; ++i) {
       ParamTag pt = paramTags[i];
       String paramName = isNonTypeParams ? pt.parameterName() : "<" + pt.parameterName() + ">";
       if (!rankMap.containsKey(pt.parameterName())) {
         writer
             .getMsgRetriever()
             .warning(
                 pt.position(),
                 isNonTypeParams ? "doclet.Parameters_warn" : "doclet.Type_Parameters_warn",
                 paramName);
       }
       String rank = (String) rankMap.get(pt.parameterName());
       if (rank != null && alreadyDocumented.contains(rank)) {
         writer
             .getMsgRetriever()
             .warning(
                 pt.position(),
                 isNonTypeParams
                     ? "doclet.Parameters_dup_warn"
                     : "doclet.Type_Parameters_dup_warn",
                 paramName);
       }
       result.appendOutput(
           processParamTag(
               isNonTypeParams, writer, pt, pt.parameterName(), alreadyDocumented.size() == 0));
       alreadyDocumented.add(rank);
     }
   }
   return result;
 }
  /**
   * Parses a constructor type definition
   *
   * @param docConstructor
   * @return
   */
  protected static Constructor ParseConstructor(ConstructorDoc docConstructor) {
    assert (docConstructor != null);

    Constructor xmlConstructor = new Constructor();

    xmlConstructor.name = docConstructor.name();
    xmlConstructor.comment = docConstructor.commentText();
    xmlConstructor.scope = DetermineScope(docConstructor);
    xmlConstructor.isVarArgs = docConstructor.isVarArgs();
    xmlConstructor.isDefault =
        docConstructor.position().line() == docConstructor.containingClass().position().line();

    Parameter[] parameters = docConstructor.parameters();

    if (parameters != null && parameters.length > 0) {
      ParamTag[] paramComments = docConstructor.paramTags();

      ArrayList<Param> methodList = new ArrayList<Param>();

      for (Parameter parameter : parameters) {
        ParamTag paramComment = null;

        // look to see if this parameter has comments
        // if so, paramComment will be set
        for (ParamTag testParam : paramComments) {
          String testParamName = testParam.parameterName();
          if (testParamName != null) {
            if (testParamName.compareTo(parameter.name()) == 0) {
              paramComment = testParam;
              break;
            }
          }
        }

        methodList.add(ParseParameter(parameter, paramComment));
      }

      xmlConstructor.parameters = methodList.toArray(new Param[] {});
    } else {
      log.debug("No parameters for method: " + docConstructor.name());
    }

    // parse annotations for the constructor
    xmlConstructor.annotationInstances =
        ParseAnnotationInstances(docConstructor.annotations(), docConstructor.qualifiedName());

    return xmlConstructor;
  }
  /**
   * Parses a method type definition
   *
   * @param docMethod
   * @return
   */
  protected static Method ParseMethod(MethodDoc docMethod) {
    assert (docMethod != null);

    Method xmlMethod = new Method();

    xmlMethod.name = docMethod.name();
    xmlMethod.hash = computeHash(docMethod.qualifiedName(), docMethod.signature());
    xmlMethod.qualifiedName = docMethod.qualifiedName();
    xmlMethod.comment = docMethod.commentText();
    xmlMethod.signature = docMethod.signature();
    xmlMethod.isNative = docMethod.isNative();
    xmlMethod.isVarArgs = docMethod.isVarArgs();
    xmlMethod.isSynchronized = docMethod.isSynchronized();
    xmlMethod.isFinal = docMethod.isFinal();
    xmlMethod.isAbstract = docMethod.isAbstract();
    xmlMethod.isStatic = docMethod.isStatic();

    xmlMethod.scope = DetermineScope(docMethod);

    // Parse parameters of the method
    Parameter[] parameters = docMethod.parameters();

    if (parameters != null && parameters.length > 0) {
      ParamTag[] paramComments = docMethod.paramTags();

      ArrayList<Param> paramList = new ArrayList<Param>();

      for (Parameter parameter : parameters) {
        ParamTag paramComment = null;

        // look to see if this parameter has comments
        // if so, paramComment will be set
        for (ParamTag testParam : paramComments) {
          String testParamName = testParam.parameterName();
          if (testParamName != null) {
            if (testParamName.compareTo(parameter.name()) == 0) {
              paramComment = testParam;
              break;
            }
          }
        }

        paramList.add(ParseParameter(parameter, paramComment));
      }

      xmlMethod.parameters = paramList.toArray(new Param[] {});
    } else {
      log.debug("No parameters for method: " + docMethod.name());
    }

    // Parse result data

    Result returnInfo = new Result();

    Tag[] returnTags = docMethod.tags("@return");
    if (returnTags != null && returnTags.length > 0) {
      // there should be only one return tag.  but heck,
      // if they specify two, so what...
      StringBuilder builder = new StringBuilder();
      for (Tag returnTag : returnTags) {
        String returnTagText = returnTag.text();
        if (returnTagText != null) {
          builder.append(returnTagText);
          builder.append("\n");
        }
      }

      returnInfo.comment = builder.substring(0, builder.length() - 1);
    }

    returnInfo.type = ParseType(docMethod.returnType());
    xmlMethod.result = returnInfo;

    // Parse exceptions of the method

    Type[] types = docMethod.thrownExceptionTypes();
    ThrowsTag[] exceptionComments = docMethod.throwsTags();

    if (types != null && types.length > 0) {
      ArrayList<ExceptionInstance> exceptionList = new ArrayList<ExceptionInstance>();

      for (Type exceptionType : types) {
        ExceptionInstance exception = new ExceptionInstance();

        exception.type = ParseType(exceptionType);

        for (ThrowsTag exceptionComment : exceptionComments) {
          if (exceptionType == exceptionComment.exceptionType()) {
            exception.comment = exceptionComment.exceptionComment();

            ClassDoc exceptionDetails = exceptionComment.exception();

            // not yet parsing Exceptions defined within the supplied code set
            exception.type = ParseType(exceptionComment.exceptionType());
            break;
          }
        }

        exceptionList.add(exception);
      }

      xmlMethod.exceptions = exceptionList.toArray(new ExceptionInstance[] {});
    }

    // parse annotations from the method
    xmlMethod.annotationInstances =
        ParseAnnotationInstances(docMethod.annotations(), docMethod.qualifiedName());

    return xmlMethod;
  }