Esempio n. 1
0
 private static void addAllInterfaceTypes(
     Map<ClassDoc, Type> results,
     Type type,
     Type[] interfaceTypes,
     boolean raw,
     Configuration configuration) {
   for (int i = 0; i < interfaceTypes.length; i++) {
     Type interfaceType = interfaceTypes[i];
     ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
     if (!(interfaceClassDoc.isPublic()
         || (configuration != null && isLinkable(interfaceClassDoc, configuration)))) {
       continue;
     }
     if (raw) interfaceType = interfaceType.asClassDoc();
     results.put(interfaceClassDoc, interfaceType);
     List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration);
     for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
       Type superInterface = iter.next();
       results.put(superInterface.asClassDoc(), superInterface);
     }
   }
   if (type instanceof ParameterizedType)
     findAllInterfaceTypes(results, (ParameterizedType) type, configuration);
   else if (((ClassDoc) type).typeParameters().length == 0)
     findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
   else findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
 }
Esempio n. 2
0
 protected String llniType(Type t, boolean handleize, boolean longDoubleOK) {
   String res = null;
   String elmt = t.typeName();
   if (t.dimension().indexOf("[]") != -1) {
     if ((t.dimension().indexOf("[][]") != -1) || (t.asClassDoc() != null)) res = "IArrayOfRef";
     else if (elmt.equals("boolean")) res = "IArrayOfBoolean";
     else if (elmt.equals("byte")) res = "IArrayOfByte";
     else if (elmt.equals("char")) res = "IArrayOfChar";
     else if (elmt.equals("int")) res = "IArrayOfInt";
     else if (elmt.equals("long")) res = "IArrayOfLong";
     else if (elmt.equals("float")) res = "IArrayOfFloat";
     else if (elmt.equals("double")) res = "IArrayOfDouble";
     if (!handleize) res = "DEREFERENCED_" + res;
   } else {
     if (elmt.equals("void")) res = "void";
     else if ((elmt.equals("boolean"))
         || (elmt.equals("byte"))
         || (elmt.equals("char"))
         || (elmt.equals("short"))
         || (elmt.equals("int"))) res = "java_int";
     else if (elmt.equals("long")) res = longDoubleOK ? "java_long" : "val32 /* java_long */";
     else if (elmt.equals("float")) res = "java_float";
     else if (elmt.equals("double"))
       res = res = longDoubleOK ? "java_double" : "val32 /* java_double */";
     else if (t.asClassDoc() != null) {
       res = "I" + mangleClassName(t.asClassDoc().qualifiedName());
       if (!handleize) res = "DEREFERENCED_" + res;
     }
   }
   return res;
 }
Esempio n. 3
0
 protected final String jniType(Type t) {
   String elmT = t.typeName();
   if (t.dimension().indexOf("[]") != -1) {
     if (elmT.equals("boolean")) return "jbooleanArray";
     else if (elmT.equals("byte")) return "jbyteArray";
     else if (elmT.equals("char")) return "jcharArray";
     else if (elmT.equals("short")) return "jshortArray";
     else if (elmT.equals("int")) return "jintArray";
     else if (elmT.equals("long")) return "jlongArray";
     else if (elmT.equals("float")) return "jfloatArray";
     else if (elmT.equals("double")) return "jdoubleArray";
     else if ((t.dimension().indexOf("[][]") != -1) || (t.asClassDoc() != null))
       return "jobjectArray";
   } else {
     if (elmT.equals("void")) return "void";
     else if (elmT.equals("boolean")) return "jboolean";
     else if (elmT.equals("byte")) return "jbyte";
     else if (elmT.equals("char")) return "jchar";
     else if (elmT.equals("short")) return "jshort";
     else if (elmT.equals("int")) return "jint";
     else if (elmT.equals("long")) return "jlong";
     else if (elmT.equals("float")) return "jfloat";
     else if (elmT.equals("double")) return "jdouble";
     else if (t.asClassDoc() != null) {
       if (elmT.equals("String")) return "jstring";
       else if (t.asClassDoc().subclassOf(root.classNamed("java.lang.Class"))) return "jclass";
       else return "jobject";
     }
   }
   Util.bug("jni.unknown.type");
   return null; /* dead code. */
 }
  /**
   * 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, "", "", "");
      }
    }
  }
Esempio n. 5
0
  public static Type findSuperTypeFromClass(final ClassDoc klass, String typeName) {
    if (klass.qualifiedTypeName().equals(typeName)) return klass;

    // find it in the interfaces
    final Type foundType = findSuperTypeFromInterface(klass, typeName);
    if (foundType != null) {
      return foundType;
    }

    final Type superclass = klass.superclassType();
    if (superclass != null && superclass.asClassDoc() != null) {
      return findSuperTypeFromClass(superclass.asClassDoc(), typeName);
    }
    return null;
  }
Esempio n. 6
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);
   }
 }
Esempio n. 7
0
 public static Type findSuperType(final Type type, String typeName) {
   ClassDoc doc = type.asClassDoc();
   if (doc == null) return null;
   if (doc.isInterface()) return findSuperTypeFromInterface(doc, typeName);
   if (doc.isClass() && !doc.isEnum() && !doc.isError() && !doc.isException())
     return findSuperTypeFromClass(doc, typeName);
   return null;
 }
Esempio n. 8
0
  /**
   * For the class return all implemented interfaces including the superinterfaces of the
   * implementing interfaces, also iterate over for all the superclasses. For interface return all
   * the extended interfaces as well as superinterfaces for those extended interfaces.
   *
   * @param type type whose implemented or super interfaces are sought.
   * @param configuration the current configuration of the doclet.
   * @param sort if true, return list of interfaces sorted alphabetically.
   * @return List of all the required interfaces.
   */
  public static List<Type> getAllInterfaces(Type type, Configuration configuration, boolean sort) {
    Map<ClassDoc, Type> results =
        sort ? new TreeMap<ClassDoc, Type>() : new LinkedHashMap<ClassDoc, Type>();
    Type[] interfaceTypes = null;
    Type superType = null;
    if (type instanceof ParameterizedType) {
      interfaceTypes = ((ParameterizedType) type).interfaceTypes();
      superType = ((ParameterizedType) type).superclassType();
    } else if (type instanceof ClassDoc) {
      interfaceTypes = ((ClassDoc) type).interfaceTypes();
      superType = ((ClassDoc) type).superclassType();
    } else {
      interfaceTypes = type.asClassDoc().interfaceTypes();
      superType = type.asClassDoc().superclassType();
    }

    for (int i = 0; i < interfaceTypes.length; i++) {
      Type interfaceType = interfaceTypes[i];
      ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
      if (!(interfaceClassDoc.isPublic()
          || (configuration == null || isLinkable(interfaceClassDoc, configuration)))) {
        continue;
      }
      results.put(interfaceClassDoc, interfaceType);
      List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration, sort);
      for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
        Type t = iter.next();
        results.put(t.asClassDoc(), t);
      }
    }
    if (superType == null) return new ArrayList<Type>(results.values());
    // Try walking the tree.
    addAllInterfaceTypes(
        results,
        superType,
        superType instanceof ClassDoc
            ? ((ClassDoc) superType).interfaceTypes()
            : ((ParameterizedType) superType).interfaceTypes(),
        false,
        configuration);
    List<Type> resultsList = new ArrayList<Type>(results.values());
    if (sort) {
      Collections.sort(resultsList, new TypeComparator());
    }
    return resultsList;
  }
Esempio n. 9
0
  public static ClassDoc findAnnotatedClass(
      final ClassDoc klass, final Class<?>... soughtAnnotations) {
    if (!klass.isClass() || isExcluded(klass)) return null;
    if (hasAnnotation(klass, soughtAnnotations)) {
      return klass;
    }
    // find it in the interfaces
    final ClassDoc foundClassDoc = findAnnotatedInterface(klass, soughtAnnotations);
    if (foundClassDoc != null) {
      return foundClassDoc;
    }

    final Type superclass = klass.superclassType();
    if (superclass != null && superclass.asClassDoc() != null) {
      return findAnnotatedClass(superclass.asClassDoc(), soughtAnnotations);
    }
    return null;
  }
 /**
  * Get link to next class.
  *
  * @return a content tree for the next class link
  */
 public Content getNavLinkNext() {
   Content li;
   if (next != null) {
     Content nextLink =
         getLink(
             new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, next.asClassDoc())
                 .label(nextclassLabel)
                 .strong(true));
     li = HtmlTree.LI(nextLink);
   } else li = HtmlTree.LI(nextclassLabel);
   return li;
 }
 /**
  * Get link to previous class.
  *
  * @return a content tree for the previous class link
  */
 public Content getNavLinkPrevious() {
   Content li;
   if (prev != null) {
     Content prevLink =
         getLink(
             new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS, prev.asClassDoc())
                 .label(prevclassLabel)
                 .strong(true));
     li = HtmlTree.LI(prevLink);
   } else li = HtmlTree.LI(prevclassLabel);
   return li;
 }
Esempio n. 12
0
  private FieldRelationInfo getFieldRelationInfo(FieldDoc field) {
    Type type = field.type();
    if (type.isPrimitive() || type instanceof WildcardType || type instanceof TypeVariable)
      return null;

    if (type.dimension().endsWith("[]")) {
      return new FieldRelationInfo(type.asClassDoc(), true);
    }

    Options opt = optionProvider.getOptionsFor(type.asClassDoc());
    if (opt.matchesCollPackageExpression(type.qualifiedTypeName())) {
      Type[] argTypes = getInterfaceTypeArguments(collectionClassDoc, type);
      if (argTypes != null && argTypes.length == 1 && !argTypes[0].isPrimitive())
        return new FieldRelationInfo(argTypes[0].asClassDoc(), true);

      argTypes = getInterfaceTypeArguments(mapClassDoc, type);
      if (argTypes != null && argTypes.length == 2 && !argTypes[1].isPrimitive())
        return new FieldRelationInfo(argTypes[1].asClassDoc(), true);
    }

    return new FieldRelationInfo(type.asClassDoc(), false);
  }
Esempio n. 13
0
 public static Type findSuperTypeFromInterface(final ClassDoc klass, String typeName) {
   // find it in the interfaces
   final Type[] interfaceTypes = klass.interfaceTypes();
   for (final Type interfaceType : interfaceTypes) {
     final ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
     if (interfaceClassDoc != null) {
       if (interfaceClassDoc.qualifiedTypeName().equals(typeName)) return interfaceClassDoc;
       final Type foundType = findSuperTypeFromInterface(interfaceClassDoc, typeName);
       if (foundType != null) {
         return foundType;
       }
     }
   }
   return null;
 }
Esempio n. 14
0
 public static ClassDoc findAnnotatedInterface(
     final ClassDoc klass, final Class<?>... soughtAnnotations) {
   // find it in the interfaces
   final Type[] interfaceTypes = klass.interfaceTypes();
   for (final Type interfaceType : interfaceTypes) {
     final ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
     if (interfaceClassDoc != null && !isExcluded(interfaceClassDoc)) {
       if (hasAnnotation(interfaceClassDoc, soughtAnnotations)) {
         return interfaceClassDoc;
       }
       final ClassDoc foundClassDoc = findAnnotatedInterface(interfaceClassDoc, soughtAnnotations);
       if (foundClassDoc != null) {
         return foundClassDoc;
       }
     }
   }
   return null;
 }
Esempio n. 15
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);
       }
     }
   }
 }
Esempio n. 16
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;
 }
Esempio n. 17
0
  /** Print a class's relations */
  public void printRelations(ClassDoc c) {
    Options opt = optionProvider.getOptionsFor(c);
    if (hidden(c)
        || c.name()
            .equals("")) // avoid phantom classes, they may pop up when the source uses annotations
    return;
    String className = c.toString();

    // Print generalization (through the Java superclass)
    Type s = c.superclassType();
    if (s != null
        && !s.toString().equals("java.lang.Object")
        && !c.isEnum()
        && !hidden(s.asClassDoc())) {
      ClassDoc sc = s.asClassDoc();
      w.println(
          "\t//"
              + c
              + " extends "
              + s
              + "\n"
              + "\t"
              + relationNode(sc)
              + " -> "
              + relationNode(c)
              + " [dir=back,arrowtail=empty];");
      getClassInfo(className)
          .addRelation(sc.toString(), RelationType.EXTENDS, RelationDirection.OUT);
      getClassInfo(sc.toString())
          .addRelation(className, RelationType.EXTENDS, RelationDirection.IN);
    }

    // Print generalizations (through @extends tags)
    for (Tag tag : c.tags("extends"))
      if (!hidden(tag.text())) {
        ClassDoc from = c.findClass(tag.text());
        w.println(
            "\t//"
                + c
                + " extends "
                + tag.text()
                + "\n"
                + "\t"
                + relationNode(from, tag.text())
                + " -> "
                + relationNode(c)
                + " [dir=back,arrowtail=empty];");
        getClassInfo(className)
            .addRelation(tag.text(), RelationType.EXTENDS, RelationDirection.OUT);
        getClassInfo(tag.text()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN);
      }
    // Print realizations (Java interfaces)
    for (Type iface : c.interfaceTypes()) {
      ClassDoc ic = iface.asClassDoc();
      if (!hidden(ic)) {
        w.println(
            "\t//"
                + c
                + " implements "
                + ic
                + "\n\t"
                + relationNode(ic)
                + " -> "
                + relationNode(c)
                + " [dir=back,arrowtail=empty,style=dashed];");
        getClassInfo(className)
            .addRelation(ic.toString(), RelationType.IMPLEMENTS, RelationDirection.OUT);
        getClassInfo(ic.toString())
            .addRelation(className, RelationType.IMPLEMENTS, RelationDirection.IN);
      }
    }
    // Print other associations
    allRelation(opt, RelationType.ASSOC, c);
    allRelation(opt, RelationType.NAVASSOC, c);
    allRelation(opt, RelationType.HAS, c);
    allRelation(opt, RelationType.NAVHAS, c);
    allRelation(opt, RelationType.COMPOSED, c);
    allRelation(opt, RelationType.NAVCOMPOSED, c);
    allRelation(opt, RelationType.DEPEND, c);
  }
Esempio n. 18
0
 public static String getExternalLink(
     Configuration configuration, Type type, HtmlDocletWriter writer) {
   return getExternalLink(
       configuration, type.asClassDoc().containingPackage().name(), type.typeName(), writer);
 }