Пример #1
0
 public ResourceMethod(MethodDoc method, MethodDoc declaringMethod, ResourceClass resource) {
   this.resource = resource;
   this.method = method;
   this.declaringClass = resource.getDeclaringClass();
   this.declaringMethod = declaringMethod;
   this.output = new MethodOutput(declaringMethod);
   try {
     formClass = Class.forName("org.jboss.resteasy.annotations.Form");
   } catch (ClassNotFoundException e) {
     // we won't support @Form
   }
   setupPath();
   setupParameters();
   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);
   }
 }
Пример #2
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("<");
      for (Type genericType : pType.typeArguments()) {
        if (first) {
          first = false;
        } else {
          print(",");
        }
        printOutputGenericType(genericType);
      }
      print(">");
    }
    print(type.dimension());
  }
Пример #3
0
  /**
   * Prints dependencies recovered from the methods of a class. A dependency is inferred only if
   * another relation between the two classes is not already in the graph.
   *
   * @param classes
   */
  public void printInferredDependencies(ClassDoc c) {
    Options opt = optionProvider.getOptionsFor(c);

    String sourceName = c.toString();
    if (hidden(c)) return;

    Set<Type> types = new HashSet<Type>();
    // harvest method return and parameter types
    for (MethodDoc method : filterByVisibility(c.methods(false), opt.inferDependencyVisibility)) {
      types.add(method.returnType());
      for (Parameter parameter : method.parameters()) {
        types.add(parameter.type());
      }
    }
    // and the field types
    if (!opt.inferRelationships) {
      for (FieldDoc field : filterByVisibility(c.fields(false), opt.inferDependencyVisibility)) {
        types.add(field.type());
      }
    }
    // see if there are some type parameters
    if (c.asParameterizedType() != null) {
      ParameterizedType pt = c.asParameterizedType();
      types.addAll(Arrays.asList(pt.typeArguments()));
    }
    // see if type parameters extend something
    for (TypeVariable tv : c.typeParameters()) {
      if (tv.bounds().length > 0) types.addAll(Arrays.asList(tv.bounds()));
    }

    // and finally check for explicitly imported classes (this
    // assumes there are no unused imports...)
    if (opt.useImports) types.addAll(Arrays.asList(c.importedClasses()));

    // compute dependencies
    for (Type type : types) {
      // skip primitives and type variables, as well as dependencies
      // on the source class
      if (type.isPrimitive()
          || type instanceof WildcardType
          || type instanceof TypeVariable
          || c.toString().equals(type.asClassDoc().toString())) continue;

      // check if the destination is excluded from inference
      ClassDoc fc = type.asClassDoc();
      if (hidden(fc)) continue;

      // check if source and destination are in the same package and if we are allowed
      // to infer dependencies between classes in the same package
      if (!opt.inferDepInPackage && c.containingPackage().equals(fc.containingPackage())) continue;

      // if source and dest are not already linked, add a dependency
      RelationPattern rp = getClassInfo(sourceName).getRelation(fc.toString());
      if (rp == null || rp.matchesOne(new RelationPattern(RelationDirection.OUT))) {
        relation(opt, RelationType.DEPEND, c, fc, "", "", "");
      }
    }
  }
Пример #4
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;
 }
Пример #5
0
  protected static GenericsInfo ParseGenerics(ParameterizedType parameterized) {
    GenericsInfo generics = null;

    if (parameterized != null
        && parameterized.typeArguments() != null
        && parameterized.typeArguments().length > 0) {
      generics = new GenericsInfo();

      Type[] types = parameterized.typeArguments();

      TypeInfo[] typeInfoList = new TypeInfo[types.length];

      for (int i = 0; i < types.length; i++) {
        typeInfoList[i] = ParseType(types[i]);
      }

      generics.typeArguments = typeInfoList;
    }

    return generics;
  }
Пример #6
0
 /** Print the parameters of the parameterized type t */
 private String typeParameters(Options opt, ParameterizedType t) {
   String tp = "";
   if (t == null) return tp;
   Type args[] = t.typeArguments();
   tp += "&lt;";
   for (int i = 0; i < args.length; i++) {
     tp += type(opt, args[i]);
     if (i != args.length - 1) tp += ", ";
   }
   tp += "&gt;";
   return tp;
 }
Пример #7
0
 private Type[] getInterfaceTypeArguments(ClassDoc iface, Type t) {
   if (t instanceof ParameterizedType) {
     ParameterizedType pt = (ParameterizedType) t;
     if (iface != null && iface.equals(t.asClassDoc())) {
       return pt.typeArguments();
     } else {
       for (Type pti : pt.interfaceTypes()) {
         Type[] result = getInterfaceTypeArguments(iface, pti);
         if (result != null) return result;
       }
       if (pt.superclassType() != null)
         return getInterfaceTypeArguments(iface, pt.superclassType());
     }
   } else if (t instanceof ClassDoc) {
     ClassDoc cd = (ClassDoc) t;
     for (Type pti : cd.interfaceTypes()) {
       Type[] result = getInterfaceTypeArguments(iface, pti);
       if (result != null) return result;
     }
     if (cd.superclassType() != null) return getInterfaceTypeArguments(iface, cd.superclassType());
   }
   return null;
 }