Package com.sun.javadoc

Examples of com.sun.javadoc.Type


  public static Map<String, Type> readSeeTypes(com.sun.javadoc.ProgramElementDoc item) {
    Map<String, Type> types = new HashMap<String, Type>();
    SeeTag[] seeTags = item.seeTags();
    if (seeTags != null) {
      for (SeeTag seeTag : seeTags) {
        Type type = seeTag.referencedClass();
        types.put(seeTag.referencedClassName(), type);
      }
    }
    return types;
  }
View Full Code Here


    List<ApiResponseMessage> responseMessages = generateResponseMessages();

    // ************************************
    // Return type
    // ************************************
    Type returnType = this.methodDoc.returnType();
    // first check if its a wrapper type and if so replace with the wrapped type
    returnType = firstNonNull(ApiModelParser.getReturnType(this.options, returnType), returnType);

    String returnTypeName = this.translator.typeName(returnType).value();
    Type modelType = returnType;

    ClassDoc[] viewClasses = ParserHelper.getJsonViews(this.methodDoc);

    // now see if it is a collection if so the return type will be array and the
    // containerOf will be added to the model

    String returnTypeItemsRef = null;
    String returnTypeItemsType = null;
    Type containerOf = ParserHelper.getContainerType(returnType, null);

    if (containerOf != null) {
      // its a collection, add the container of type to the model
      modelType = containerOf;
      // set the items type or ref
View Full Code Here

                }
              }

              String responseModel = null;
              if (responseModelClass != null) {
                Type responseType = ParserHelper.findModel(this.classes, responseModelClass);
                if (responseType != null) {
                  responseModel = this.translator.typeName(responseType).value();
                  if (this.options.isParseModels()) {
                    this.models.addAll(new ApiModelParser(this.options, this.translator, responseType).parse());
                  }
View Full Code Here

    for (Parameter parameter : this.methodDoc.parameters()) {
      if (!shouldIncludeParameter(this.httpMethod, excludeParams, parameter)) {
        continue;
      }

      Type paramType = parameter.type();
      String paramCategory = ParserHelper.paramTypeOf(consumesMultipart, parameter, this.options);
      String paramName = parameter.name();

      // see if its a special composite type e.g. @BeanParam
      if ("composite".equals(paramCategory)) {

        ApiModelParser modelParser = new ApiModelParser(this.options, this.translator, paramType, consumesMultipart);
        Set<Model> models = modelParser.parse();
        String rootModelId = modelParser.getRootModelId();
        for (Model model : models) {
          if (model.getId().equals(rootModelId)) {
            Map<String, Property> modelProps = model.getProperties();
            for (Map.Entry<String, Property> entry : modelProps.entrySet()) {
              Property property = entry.getValue();
              String renderedParamName = entry.getKey();
              String fawFieldName = property.getRawFieldName();

              Boolean allowMultiple = getAllowMultiple(paramCategory, fawFieldName, csvParams);
              Boolean required = getRequired(paramCategory, fawFieldName, property.getType(), optionalParams, requiredParams);

              String itemsRef = property.getItems() == null ? null : property.getItems().getRef();
              String itemsType = property.getItems() == null ? null : property.getItems().getType();

              ApiParameter param = new ApiParameter(property.getParamCategory(), renderedParamName, required, allowMultiple, property.getType(),
                  property.getFormat(), property.getDescription(), itemsRef, itemsType, property.getUniqueItems(),
                  property.getAllowableValues(), property.getMinimum(), property.getMaximum(), property.getDefaultValue());

              parameters.add(param);
            }
            break;
          }
        }

        continue;
      }

      // look for a custom input type for body params
      if ("body".equals(paramCategory)) {
        String customParamType = ParserHelper.getTagValue(this.methodDoc, this.options.getInputTypeTags());
        paramType = readCustomParamType(customParamType, paramType);
      }

      OptionalName paramTypeFormat = this.translator.parameterTypeName(consumesMultipart, parameter, paramType);
      String typeName = paramTypeFormat.value();
      String format = paramTypeFormat.getFormat();

      Boolean allowMultiple = null;
      List<String> allowableValues = null;
      String itemsRef = null;
      String itemsType = null;
      Boolean uniqueItems = null;
      String minimum = null;
      String maximum = null;
      String defaultVal = null;

      // set to form param type if data type is File
      if ("File".equals(typeName)) {
        paramCategory = "form";
      } else {

        if (this.options.isParseModels()) {
          this.models.addAll(new ApiModelParser(this.options, this.translator, paramType).parse());
        }

        // set enum values
        ClassDoc typeClassDoc = parameter.type().asClassDoc();
        allowableValues = ParserHelper.getAllowableValues(typeClassDoc);
        if (allowableValues != null) {
          typeName = "string";
        }

        // set whether its a csv param
        allowMultiple = getAllowMultiple(paramCategory, paramName, csvParams);

        // get min and max param values
        minimum = paramMinVals.get(paramName);
        maximum = paramMaxVals.get(paramName);

        String validationContext = " for the method: " + this.methodDoc.name() + " parameter: " + paramName;

        // verify min max are numbers
        ParserHelper.verifyNumericValue(validationContext + " min value.", typeName, format, minimum);
        ParserHelper.verifyNumericValue(validationContext + " max value.", typeName, format, maximum);

        // get a default value, prioritize the jaxrs annotation
        // otherwise look for the javadoc tag
        defaultVal = ParserHelper.getDefaultValue(parameter);
        if (defaultVal == null) {
          defaultVal = paramDefaultVals.get(paramName);
        }

        // verify default vs min, max and by itself
        if (defaultVal != null) {
          if (minimum == null && maximum == null) {
            // just validate the default
            ParserHelper.verifyValue(validationContext + " default value.", typeName, format, defaultVal);
          }
          // if min/max then default is validated as part of comparison
          if (minimum != null) {
            int comparison = ParserHelper.compareNumericValues(validationContext + " min value.", typeName, format, defaultVal, minimum);
            if (comparison < 0) {
              throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
                  + paramName + " it should be >= the minimum: " + minimum);
            }
          }
          if (maximum != null) {
            int comparison = ParserHelper.compareNumericValues(validationContext + " max value.", typeName, format, defaultVal, maximum);
            if (comparison > 0) {
              throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
                  + paramName + " it should be <= the maximum: " + maximum);
            }
          }
        }

        // if enum and default value check it matches the enum values
        if (allowableValues != null && defaultVal != null && !allowableValues.contains(defaultVal)) {
          throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: " + paramName
              + " it should be one of: " + allowableValues);
        }

        // set collection related fields
        // TODO: consider supporting parameterized collections as api parameters...
        Type containerOf = null;
        containerOf = ParserHelper.getContainerType(paramType, null);
        String containerTypeOf = containerOf == null ? null : this.translator.typeName(containerOf).value();
        if (containerOf != null) {
          if (ParserHelper.isPrimitive(containerOf, this.options)) {
            itemsType = containerTypeOf;
View Full Code Here

  }

  private Type readCustomParamType(String customTypeName, Type defaultType) {
    if (customTypeName != null) {
      // lookup the type from the doclet classes
      Type customType = ParserHelper.findModel(this.classes, customTypeName);
      if (customType != null) {
        // also add this custom return type to the models
        if (this.options.isParseModels()) {
          this.models.addAll(new ApiModelParser(this.options, this.translator, customType).parse());
        }
View Full Code Here

      Matcher matcher = GENERIC_RESPONSE_PATTERN.matcher(customTypeName);
      if (matcher.find()) {
        String collectionType = matcher.group(1);
        if (ParserHelper.isCollection(collectionType)) {
          String containerOfType = matcher.group(2);
          Type containerOf = null;
          String containerOfPrimitive = null;
          if (ParserHelper.isPrimitive(containerOfType, this.options)) {
            containerOfPrimitive = ParserHelper.typeOf(containerOfType, this.options)[0];
          } else {
            containerOf = ParserHelper.findModel(this.classes, containerOfType);
            if (containerOf == null) {
              raiseCustomTypeNotFoundError(containerOfType);
            }
          }

          NameToType res = new NameToType();
          res.returnTypeName = ParserHelper.typeOf(collectionType, this.options)[0];
          res.returnType = null;
          res.containerOf = containerOf;
          res.containerOfPrimitive = containerOfPrimitive;
          return res;
        } else {
          throw new UnsupportedOperationException(
              "Generic response types are not supported for custom @returnType, only collection types are allowed.");
        }
      }

      // lookup the type from the doclet classes
      Type customType = ParserHelper.findModel(this.classes, customTypeName);
      if (customType == null) {
        raiseCustomTypeNotFoundError(customTypeName);
      } else {
        customType = firstNonNull(ApiModelParser.getReturnType(this.options, customType), customType);
        String translated = this.translator.typeName(customType).value();
View Full Code Here

      }
    }
  }

  private void processSuperClass(ClassDoc classDoc, Collection<String> ignore) {
    Type type = classDoc.superclassType();
    if ((type != null) && !type.qualifiedTypeName().equals(Object.class.getCanonicalName())) {
      cc.catalysts.cdoclet.generator.Type superClass = GeneratorUtils.getType(type, getGenerator(), ignore);

      if (superClass != cc.catalysts.cdoclet.generator.Type.NULL && !ignore.contains(superClass.getName())) {
        getGenerator().setSuperclass(superClass, isException(classDoc));
      }
View Full Code Here

  }

  private String getParameterString(Parameter[] ps) {
    String result = "";
    for (int i = 0; i < ps.length; i++) {
      Type type = ps[i].type();
      String ename = type.isPrimitive() ? type.typeName()
          : getExportedName(type.asClassDoc());
      result += "<span class=jsdocParameterType>" + ename
          + "</span> <span class=jsdocParameterName>" + ps[i].name()
          + "</span>";
      if (i < ps.length - 1) {
        result += ", ";
View Full Code Here

  }

  public abstract String getDoc();

  public boolean isWrapped() {
    Type parameterType = getType();
    return !parameterType.isPrimitive() && parameterType.qualifiedTypeName().equals("java.lang.String")
           && Utils.getTag(getParameterDoc(), "inputWrapped") != null;
  }
View Full Code Here

    setupMethods();
    setupMIMEs();
    // is this a resource locator?
    if (methods.isEmpty() && !declaringMethod.returnType().isPrimitive()) {
      // Handle Class style resource locator factory methods
      Type t = declaringMethod.returnType();
      if("java.lang.Class".equals(t.qualifiedTypeName())) {
        ParameterizedType p = t.asParameterizedType();
            if (p != null) {
              t = p.typeArguments()[0];
            }
      }
       resourceLocator = new ResourceClass(t.asClassDoc(), this);
    }
  }
View Full Code Here

TOP

Related Classes of com.sun.javadoc.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.