Exemplo n.º 1
0
 private void printInput() {
   MethodParameter inputParameter = method.getInputParameter();
   if (inputParameter == null) return;
   open("dt");
   around("b", "Input:");
   close("dt");
   if (inputParameter.isWrapped()) {
     open("dd");
     String typeName = inputParameter.getWrappedType();
     JaxType returnType = null;
     try {
       returnType = Utils.parseType(typeName, method.getJavaDoc().containingClass(), doclet);
     } catch (InvalidJaxTypeException e) {
       doclet.warn("Invalid @returnWrapped type: " + typeName);
       e.printStackTrace();
     }
     if (returnType != null) printOutputType(returnType);
     else around("tt", escape(typeName));
   } else {
     open("dd");
     Type returnType = inputParameter.getType();
     printOutputType(returnType);
   }
   String doc = inputParameter.getDoc();
   if (!Utils.isEmptyOrNull(doc)) {
     print(" - ");
     print(doc);
   }
   close("dd");
 }
Exemplo n.º 2
0
 private void setupPath() {
   final AnnotationDesc pathAnnotation =
       Utils.findMethodAnnotation(declaringClass, method, Path.class);
   final String rootPath = resource.getPath();
   if (pathAnnotation != null) {
     String path = (String) Utils.getAnnotationValue(pathAnnotation);
     path = Utils.removeFragmentRegexes(path, regexFragments);
     this.path = Utils.appendURLFragments(rootPath, path);
   } else this.path = rootPath;
 }
Exemplo n.º 3
0
 public void setOptions() {
   super.setOptions();
   String[][] options = parentConfiguration.root.options();
   jaxrscontext = Utils.getOption(options, "-jaxrscontext");
   enableHTTPExample = !Utils.hasOption(options, "-disablehttpexample");
   enableJavaScriptExample = !Utils.hasOption(options, "-disablejavascriptexample");
   List<String> excludeFilters = Utils.getOptions(options, "-pathexcludefilter");
   for (String excludeFilter : excludeFilters) {
     pathExcludeFilters.add(Pattern.compile(excludeFilter));
   }
 }
Exemplo n.º 4
0
 private void setupMIMEs() {
   producesAnnotation =
       Utils.findMethodAnnotation(declaringClass, method, Utils.getProducesClass());
   consumesAnnotation =
       Utils.findMethodAnnotation(declaringClass, method, Utils.getConsumesClass());
   if (producesAnnotation == null) {
     producesAnnotation = resource.getProducesAnnotation();
   }
   if (consumesAnnotation == null) {
     consumesAnnotation = resource.getConsumesAnnotation();
   }
 }
Exemplo n.º 5
0
 private void start() {
   final ClassDoc[] classes = conf.parentConfiguration.root.classes();
   for (final ClassDoc klass : classes) {
     if (Utils.findAnnotatedClass(klass, jpaAnnotations) != null) {
       handleJPAClass(klass);
     }
   }
   for (final JPAClass klass : jpaClasses) {
     klass.write(conf);
   }
   new PackageListWriter(conf, registry).write();
   new SummaryWriter(conf, registry).write();
   Utils.copyResources(conf);
 }
Exemplo n.º 6
0
 private void printIncludes() {
   MethodDoc javaDoc = method.getJavaDoc();
   Tag[] includes = Utils.getTags(javaDoc, "include");
   if (includes == null) return;
   File relativeTo = javaDoc.containingClass().position().file().getParentFile();
   for (Tag include : includes) {
     String fileName = include.text();
     File file = new File(relativeTo, fileName);
     if (!file.exists()) {
       doclet.printError(include.position(), "Missing included file: " + fileName);
       continue;
     }
     String text = Utils.readResource(file);
     print(text);
   }
 }
Exemplo n.º 7
0
  private void printOutputGenericType(JaxType type) {
    String link = null;
    if (type.getType() == null) {
      doclet.warn("Type information not found: " + type.getTypeName());
      print(type.getTypeName());
      return;
    }

    if (!type.getType().isPrimitive()) {
      link = Utils.getExternalLink(configuration.parentConfiguration, type.getType(), writer);
    }

    if (link == null) {
      print(type.getType().qualifiedTypeName());
    } else {
      around("a href='" + link + "'", type.getType().typeName());
    }
    if (type.hasParameters()) {
      boolean first = true;
      print("&lt;");
      for (JaxType genericType : type.getParameters()) {
        if (first) {
          first = false;
        } else {
          print(",");
        }
        printOutputGenericType(genericType);
      }
      print("&gt;");
    }
    print(type.getDimension());
  }
Exemplo n.º 8
0
 private void setupMethods() {
   for (Class<?> methodAnnotation : MethodAnnotations) {
     final AnnotationDesc annotation =
         Utils.findMethodAnnotation(declaringClass, method, methodAnnotation);
     if (annotation != null) methods.add(annotation);
   }
 }
Exemplo n.º 9
0
  private void printOutputGenericType(Type type) {
    String link = null;
    if (!type.isPrimitive()) {
      link = Utils.getExternalLink(configuration.parentConfiguration, type, writer);
    }

    if (link == null) {
      print(type.qualifiedTypeName());
    } else {
      around("a href='" + link + "'", type.typeName());
    }
    ParameterizedType pType = type.asParameterizedType();
    if (pType != null) {
      boolean first = true;
      print("&lt;");
      for (Type genericType : pType.typeArguments()) {
        if (first) {
          first = false;
        } else {
          print(",");
        }
        printOutputGenericType(genericType);
      }
      print("&gt;");
    }
    print(type.dimension());
  }
Exemplo n.º 10
0
 public List<String> getConsumes() {
   AnnotationDesc consumes = getConsumesAnnotation();
   if (consumes == null) {
     return Collections.emptyList();
   } else {
     return Arrays.asList(Utils.getAnnotationValues(consumes));
   }
 }
Exemplo n.º 11
0
  private void printHTTPExample(String httpMethod) {
    around("b", "HTTP Example:");
    open("pre");
    String absPath = Utils.getAbsolutePath(this, resource);

    print(httpMethod + " " + absPath);
    Map<String, MethodParameter> matrixParameters = method.getMatrixParameters();
    if (!matrixParameters.isEmpty()) {
      for (String name : matrixParameters.keySet()) {
        print(";");
        print(name);
        print("=…");
      }
    }
    Map<String, MethodParameter> queryParameters = method.getQueryParameters();
    if (!queryParameters.isEmpty()) {
      print("?");
      boolean first = true;
      for (String name : queryParameters.keySet()) {
        if (!first) print("&amp;");
        print(name);
        print("=…");
        first = false;
      }
    }
    print("\n");

    Map<String, MethodParameter> headerParameters = method.getHeaderParameters();
    if (!headerParameters.isEmpty()) {
      for (String name : headerParameters.keySet()) {
        print(name);
        print(": …\n");
      }
    }
    Map<String, MethodParameter> cookieParameters = method.getCookieParameters();
    if (!cookieParameters.isEmpty()) {
      for (String name : cookieParameters.keySet()) {
        print("Cookie: ");
        print(name);
        print("=…\n");
      }
    }

    Map<String, MethodParameter> formParameters = method.getFormParameters();
    if (!formParameters.isEmpty()) {
      print("\n");
      boolean first = true;
      for (String name : formParameters.keySet()) {
        if (!first) print("&amp;");
        print(name);
        print("=…");
        first = false;
      }
    }
    print("\n");
    close("pre");
  }
Exemplo n.º 12
0
 public static Type getCollectionType(Type type, JAXDoclet<?> doclet) {
   Type collectionType = Utils.findSuperType(type, "java.util.Collection");
   // FIXME: this is dodgy at best
   if (collectionType != null) {
     ParameterizedType parameterizedType = type.asParameterizedType();
     Type[] types = parameterizedType == null ? null : parameterizedType.typeArguments();
     if (types != null && types.length == 1) return types[0];
     return doclet.forName("java.lang.Object");
   }
   return type;
 }
Exemplo n.º 13
0
 private void printParameters(Map<String, MethodParameter> parameters, String header) {
   if (parameters.isEmpty()) return;
   open("dt");
   around("b", header + " parameters:");
   close("dt");
   for (MethodParameter param : parameters.values()) {
     open("dd");
     around("b", param.getName());
     String doc = param.getDoc();
     if (!Utils.isEmptyOrNull(doc)) print(" - " + param.getDoc());
     close("dd");
   }
 }
Exemplo n.º 14
0
 /*
  * Path won't be to jaxb class private void printSees() { MethodDoc javaDoc =
  * method.getJavaDoc(); TagletOutputImpl output = new TagletOutputImpl("");
  * Set<String> tagletsSet = new HashSet<String>(); tagletsSet.add("see");
  * Utils.genTagOuput(configuration.tagletManager, javaDoc,
  * configuration.tagletManager.getCustomTags(javaDoc), writer
  * .getTagletWriterInstance(false), output, tagletsSet);
  * writer.print(output.toString()); }
  */
 private void printTaglets(String tagletName) {
   MethodDoc javaDoc = method.getJavaDoc();
   TagletOutputImpl output = new TagletOutputImpl("");
   Set<String> tagletsSet = new HashSet<String>();
   tagletsSet.add(tagletName);
   Utils.genTagOuput(
       configuration.parentConfiguration.tagletManager,
       javaDoc,
       configuration.parentConfiguration.tagletManager.getCustomTags(javaDoc),
       writer.getTagletWriterInstance(false),
       output,
       tagletsSet);
   writer.print(output.toString());
 }
Exemplo n.º 15
0
 private void printMethod(String httpMethod) {
   around("a name='" + httpMethod + "'", "");
   if (getJAXRSConfiguration().enableHTTPExample
       || getJAXRSConfiguration().enableJavaScriptExample) {
     open("table class='examples'", "tr");
     if (getJAXRSConfiguration().enableHTTPExample) {
       open("td");
       printHTTPExample(httpMethod);
       close("td");
     }
     if (getJAXRSConfiguration().enableJavaScriptExample) {
       open("td");
       printAPIExample();
       close("td");
     }
     close("tr", "table");
   }
   if (!Utils.isEmptyOrNull(method.getDoc())) {
     open("p");
     print(method.getDoc());
     close("p");
   }
   printIncludes();
   open("dl");
   printInput();
   printOutput();
   printParameters(method.getQueryParameters(), "Query");
   // done on resource
   // printParameters(method.getPathParameters(), "Path");
   printParameters(method.getMatrixParameters(), "Matrix");
   printParameters(method.getFormParameters(), "Form");
   printParameters(method.getCookieParameters(), "Cookie");
   printParameters(method.getHeaderParameters(), "Header");
   printMIMEs(method.getProduces(), "Produces");
   printMIMEs(method.getConsumes(), "Consumes");
   printHTTPCodes();
   printHTTPRequestHeaders();
   printHTTPResponseHeaders();
   // printSees();
   close("dl");
 }
Exemplo n.º 16
0
 private void handleJPAClass(final ClassDoc klass) {
   ClassDoc superDoc = klass.superclass();
   if (!registry.isJPAClass(klass.qualifiedTypeName())
       && !klass.isPrimitive()
       && !klass.qualifiedTypeName().startsWith("java.")
       && !klass.isEnum()) {
     String fqName = klass.qualifiedTypeName();
     JPAClass jpaClass = new JPAClass(klass, registry, this);
     jpaClasses.add(jpaClass);
     registry.addJPAClass(jpaClass);
     // load all used types
     List<JPAMember> members = jpaClass.getMembers();
     for (JPAMember member : members) {
       Type type = member.getJavaType();
       ClassDoc doc = type.asClassDoc();
       if (doc != null && Utils.findAnnotatedClass(doc, jpaAnnotations) != null) {
         handleJPAClass(doc);
       }
     }
   }
 }
Exemplo n.º 17
0
  private void printOutput() {
    open("dt");
    around("b", "Output:");
    close("dt");

    MethodOutput output = method.getOutput();

    if (output.isOutputWrapped()) {
      for (int i = 0; i < output.getOutputWrappedCount(); i++) {
        open("dd");
        String typeName = output.getWrappedOutputType(i);
        JaxType returnType = null;
        try {
          returnType = Utils.parseType(typeName, method.getJavaDoc().containingClass(), doclet);
        } catch (InvalidJaxTypeException e) {
          doclet.warn("Invalid @returnWrapped type: " + typeName);
          e.printStackTrace();
        }
        if (returnType != null) printOutputType(returnType);
        else around("tt", escape(typeName));
        if (output.getOutputDoc(i) != null) {
          print(" - ");
          print(output.getOutputDoc(i));
        }
        close("dd");
      }
    } else {
      open("dd");
      Type returnType = output.getOutputType();
      printOutputType(returnType);
      if (output.getOutputDoc() != null) {
        print(" - ");
        print(output.getOutputDoc());
      }
      close("dd");
    }
  }
Exemplo n.º 18
0
 public static boolean isCollection(Type type) {
   Type collectionType = Utils.findSuperType(type, "java.util.Collection");
   // FIXME: this is dodgy at best
   return collectionType != null;
 }
Exemplo n.º 19
0
 private void setupParameters() {
   int i = -1;
   for (final Parameter parameter : method.parameters()) {
     i++;
     final AnnotationDesc pathParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, PathParam.class);
     if (pathParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(pathParamAnnotation);
       pathParameters.add(
           new RealMethodParameter(
               parameter, i, pathParamAnnotation, MethodParameterType.Path, declaringMethod));
       continue;
     }
     final AnnotationDesc matrixParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, MatrixParam.class);
     if (matrixParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(matrixParamAnnotation);
       matrixParameters.add(
           new RealMethodParameter(
               parameter, i, matrixParamAnnotation, MethodParameterType.Matrix, declaringMethod));
       continue;
     }
     final AnnotationDesc queryParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, QueryParam.class);
     if (queryParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(queryParamAnnotation);
       queryParameters.add(
           new RealMethodParameter(
               parameter, i, queryParamAnnotation, MethodParameterType.Query, declaringMethod));
       continue;
     }
     final AnnotationDesc cookieParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, CookieParam.class);
     if (cookieParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(cookieParamAnnotation);
       cookieParameters.add(
           new RealMethodParameter(
               parameter, i, cookieParamAnnotation, MethodParameterType.Cookie, declaringMethod));
       continue;
     }
     final AnnotationDesc formParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, FormParam.class);
     if (formParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(formParamAnnotation);
       formParameters.add(
           new RealMethodParameter(
               parameter, i, formParamAnnotation, MethodParameterType.Form, declaringMethod));
       continue;
     }
     final AnnotationDesc headerParamAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, HeaderParam.class);
     if (headerParamAnnotation != null) {
       String name = (String) Utils.getAnnotationValue(headerParamAnnotation);
       headerParameters.add(
           new RealMethodParameter(
               parameter, i, headerParamAnnotation, MethodParameterType.Header, declaringMethod));
       continue;
     }
     if (formClass != null) {
       final AnnotationDesc formAnnotation =
           Utils.findParameterAnnotation(declaringMethod, parameter, i, formClass);
       if (formAnnotation != null) {
         walkFormParameter(parameter.type().asClassDoc());
         continue;
       }
     }
     final AnnotationDesc contextAnnotation =
         Utils.findParameterAnnotation(declaringMethod, parameter, i, Context.class);
     if (contextAnnotation == null) {
       this.inputParameter =
           new RealMethodParameter(parameter, i, null, MethodParameterType.Input, declaringMethod);
     }
   }
 }
Exemplo n.º 20
0
  private void walkFormParameter(ClassDoc formDoc) {
    // walk all fields
    for (FieldDoc field : formDoc.fields(false)) {
      final AnnotationDesc pathParamAnnotation = Utils.findAnnotation(field, PathParam.class);
      if (pathParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(pathParamAnnotation);
        pathParameters.add(
            new FormFieldParameter(field, pathParamAnnotation, MethodParameterType.Path));
        continue;
      }
      final AnnotationDesc matrixParamAnnotation = Utils.findAnnotation(field, MatrixParam.class);
      if (matrixParamAnnotation != null) {
        matrixParameters.add(
            new FormFieldParameter(field, matrixParamAnnotation, MethodParameterType.Matrix));
        continue;
      }
      final AnnotationDesc queryParamAnnotation = Utils.findAnnotation(field, QueryParam.class);
      if (queryParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(queryParamAnnotation);
        queryParameters.add(
            new FormFieldParameter(field, queryParamAnnotation, MethodParameterType.Query));
        continue;
      }
      final AnnotationDesc headerParamAnnotation = Utils.findAnnotation(field, HeaderParam.class);
      if (headerParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(headerParamAnnotation);
        headerParameters.add(
            new FormFieldParameter(field, headerParamAnnotation, MethodParameterType.Header));
        continue;
      }
      final AnnotationDesc cookieParamAnnotation = Utils.findAnnotation(field, CookieParam.class);
      if (cookieParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(cookieParamAnnotation);
        cookieParameters.add(
            new FormFieldParameter(field, cookieParamAnnotation, MethodParameterType.Cookie));
        continue;
      }
      final AnnotationDesc formParamAnnotation = Utils.findAnnotation(field, FormParam.class);
      if (formParamAnnotation != null) {
        formParameters.add(
            new FormFieldParameter(field, formParamAnnotation, MethodParameterType.Form));
        continue;
      }
      // Recurse into the embedded @Form field
      if (formClass != null) {
        final AnnotationDesc formAnnotation = Utils.findAnnotation(field, formClass);
        if (formAnnotation != null) {
          walkFormParameter(field.type().asClassDoc());
          continue;
        }
      }

      final AnnotationDesc contextAnnotation = Utils.findAnnotation(field, Context.class);
      if (contextAnnotation == null) {
        this.inputParameter = new FormFieldParameter(field, null, MethodParameterType.Input);
        continue;
      }
    }
    // and methods
    for (MethodDoc method : formDoc.methods(false)) {
      if (!method.returnType().qualifiedTypeName().equals("void")
          || method.parameters().length != 1
          || !method.name().startsWith("set")) continue;
      Parameter parameter = method.parameters()[0];
      final AnnotationDesc pathParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, PathParam.class);
      if (pathParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(pathParamAnnotation);
        pathParameters.add(
            new FormMethodParameter(method, pathParamAnnotation, MethodParameterType.Path));
        continue;
      }
      final AnnotationDesc matrixParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, MatrixParam.class);
      if (matrixParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(matrixParamAnnotation);
        matrixParameters.add(
            new FormMethodParameter(method, matrixParamAnnotation, MethodParameterType.Matrix));
        continue;
      }
      final AnnotationDesc queryParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, QueryParam.class);
      if (queryParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(queryParamAnnotation);
        queryParameters.add(
            new FormMethodParameter(method, queryParamAnnotation, MethodParameterType.Query));
        continue;
      }
      final AnnotationDesc headerParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, HeaderParam.class);
      if (headerParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(headerParamAnnotation);
        headerParameters.add(
            new FormMethodParameter(method, headerParamAnnotation, MethodParameterType.Header));
        continue;
      }
      final AnnotationDesc cookieParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, CookieParam.class);
      if (cookieParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(cookieParamAnnotation);
        cookieParameters.add(
            new FormMethodParameter(method, cookieParamAnnotation, MethodParameterType.Cookie));
        continue;
      }
      final AnnotationDesc formParamAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, FormParam.class);
      if (formParamAnnotation != null) {
        String name = (String) Utils.getAnnotationValue(formParamAnnotation);
        formParameters.add(
            new FormMethodParameter(method, formParamAnnotation, MethodParameterType.Form));
        continue;
      }
      // I'm not sure if @Form can be used on setter methods on an @Form field, but just in case...
      if (formClass != null) {
        // recurse into @Form parameters
        final AnnotationDesc formAnnotation =
            Utils.findParameterAnnotation(method, parameter, 0, formClass);
        if (formAnnotation != null) {
          walkFormParameter(parameter.type().asClassDoc());
          continue;
        }
      }
      final AnnotationDesc contextAnnotation =
          Utils.findParameterAnnotation(method, parameter, 0, Context.class);
      if (contextAnnotation == null) {
        this.inputParameter = new FormMethodParameter(method, null, MethodParameterType.Input);
      }
    }
  }
Exemplo n.º 21
0
 public boolean hasHTTPMethod(Class<? extends Annotation> method) {
   return Utils.findAnnotation(methods.toArray(new AnnotationDesc[0]), method) != null;
 }