Esempio n. 1
0
 private static boolean hasDefaultConstructor(ClassDoc classDoc) {
   ConstructorDoc[] cdocs = classDoc.constructors();
   for (int i = 0; i < cdocs.length; i++) {
     ConstructorDoc cdoc = cdocs[i];
     if (cdoc.parameters().length == 0) {
       if (!cdoc.isPrivate()) {
         return true;
       }
     }
   }
   return false;
 }
 /**
  * Build the sorted list of all the deprecated APIs in this run. Build separate lists for
  * deprecated packages, classes, constructors, methods and fields.
  *
  * @param configuration the current configuration of the doclet.
  */
 private void buildDeprecatedAPIInfo(Configuration configuration) {
   PackageDoc[] packages = configuration.packages;
   PackageDoc pkg;
   for (int c = 0; c < packages.length; c++) {
     pkg = packages[c];
     if (Util.isDeprecated(pkg)) {
       getList(PACKAGE).add(pkg);
     }
   }
   ClassDoc[] classes = configuration.root.classes();
   for (int i = 0; i < classes.length; i++) {
     ClassDoc cd = classes[i];
     if (Util.isDeprecated(cd)) {
       if (cd.isOrdinaryClass()) {
         getList(CLASS).add(cd);
       } else if (cd.isInterface()) {
         getList(INTERFACE).add(cd);
       } else if (cd.isException()) {
         getList(EXCEPTION).add(cd);
       } else if (cd.isEnum()) {
         getList(ENUM).add(cd);
       } else if (cd.isError()) {
         getList(ERROR).add(cd);
       } else if (cd.isAnnotationType()) {
         getList(ANNOTATION_TYPE).add(cd);
       }
     }
     composeDeprecatedList(getList(FIELD), cd.fields());
     composeDeprecatedList(getList(METHOD), cd.methods());
     composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
     if (cd.isEnum()) {
       composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
     }
     if (cd.isAnnotationType()) {
       composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), ((AnnotationTypeDoc) cd).elements());
     }
   }
   sortDeprecatedLists();
 }
  /**
   * Parses the data for a class type definition
   *
   * @param docClass
   * @return
   */
  protected static Class ParseClass(ClassDoc docClass) {
    assert (docClass != null);

    Class xmlClass = new Class();

    // illegal use of this class.
    assert (xmlClass != null);

    xmlClass.name = docClass.name();
    xmlClass.qualifiedName = docClass.qualifiedName();
    xmlClass.isSerializable = docClass.isSerializable();
    xmlClass.isExternalizable = docClass.isExternalizable();
    xmlClass.isAbstract = docClass.isAbstract();
    xmlClass.isException = docClass.isException();
    xmlClass.isError = docClass.isError();
    xmlClass.comment = docClass.commentText();
    xmlClass.scope = DetermineScope(docClass);
    xmlClass.isIncluded = docClass.isIncluded();
    xmlClass.typeVariables =
        ParseTypeVariables(docClass.typeParameters(), docClass.typeParamTags());
    Type superClassType = docClass.superclassType();
    if (superClassType != null) {
      xmlClass.superClass = ParseType(superClassType);
    }

    Type[] interfaces = docClass.interfaceTypes();

    ArrayList<TypeInfo> interfaceTypeNames = new ArrayList<TypeInfo>();
    if (interfaces != null && interfaces.length > 0) {
      for (Type interfaceType : interfaces) {
        interfaceTypeNames.add(ParseType(interfaceType));
      }

      xmlClass.interfaces = interfaceTypeNames.toArray(new TypeInfo[] {});
    }

    ConstructorDoc[] constructors = docClass.constructors();

    if (constructors != null && constructors.length > 0) {
      ArrayList<Constructor> constructorList = new ArrayList<Constructor>();

      for (ConstructorDoc constructor : constructors) {
        constructorList.add(ParseConstructor(constructor));
      }

      xmlClass.constructors = constructorList.toArray(new Constructor[] {});
    } else {
      log.debug("No constructors in class: " + docClass.name());
    }

    MethodDoc[] methods = docClass.methods();

    if (methods != null && methods.length > 0) {
      ArrayList<Method> methodList = new ArrayList<Method>();

      for (MethodDoc method : methods) {
        methodList.add(ParseMethod(method));
      }

      xmlClass.methods = methodList.toArray(new Method[] {});
    } else {
      log.debug("No methods in class: " + docClass.name());
    }

    FieldDoc[] fields = docClass.fields();

    if (fields != null && fields.length > 0) {
      ArrayList<Field> fieldList = new ArrayList<Field>();

      for (FieldDoc field : fields) {
        fieldList.add(ParseField(field));
      }

      xmlClass.fields = fieldList.toArray(new Field[] {});
    }

    xmlClass.annotationInstances =
        ParseAnnotationInstances(docClass.annotations(), docClass.qualifiedName());
    return xmlClass;
  }
  /**
   * Prints the class if needed.
   *
   * <p>A class is a rootClass if it's included among the classes returned by RootDoc.classes(),
   * this information is used to properly compute relative links in diagrams for UMLDoc
   */
  public String printClass(ClassDoc c, boolean rootClass) {
    ClassInfo ci;
    boolean toPrint;
    Options opt = optionProvider.getOptionsFor(c);

    String className = c.toString();
    if ((ci = getClassInfo(className)) != null) toPrint = !ci.nodePrinted;
    else {
      toPrint = true;
      ci = newClassInfo(className, true, hidden(c));
    }
    if (toPrint && !hidden(c) && (!c.isEnum() || opt.showEnumerations)) {
      // Associate classname's alias
      String r = className;
      w.println("\t// " + r);
      // Create label
      w.print("\t" + ci.name + " [label=");

      boolean showMembers =
          (opt.showAttributes && c.fields().length > 0)
              || (c.isEnum() && opt.showEnumConstants && c.enumConstants().length > 0)
              || (opt.showOperations && c.methods().length > 0)
              || (opt.showConstructors && c.constructors().length > 0);

      externalTableStart(opt, c.qualifiedName(), classToUrl(c, rootClass));

      // Calculate the number of innerTable rows we will emmit
      int nRows = 1;
      if (showMembers) {
        if (opt.showAttributes) nRows++;
        else if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) nRows++;
        if (c.isEnum() && opt.showEnumConstants) nRows++;
        if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) nRows++;
      }

      firstInnerTableStart(opt, nRows);
      if (c.isInterface()) tableLine(Align.CENTER, guilWrap(opt, "interface"));
      if (c.isEnum()) tableLine(Align.CENTER, guilWrap(opt, "enumeration"));
      stereotype(opt, c, Align.CENTER);
      Font font = c.isAbstract() && !c.isInterface() ? Font.CLASS_ABSTRACT : Font.CLASS;
      String qualifiedName = qualifiedName(opt, r);
      int startTemplate = qualifiedName.indexOf('<');
      int idx = 0;
      if (startTemplate < 0) idx = qualifiedName.lastIndexOf('.');
      else idx = qualifiedName.lastIndexOf('.', startTemplate);
      if (opt.showComment)
        tableLine(Align.LEFT, htmlNewline(escape(c.commentText())), opt, Font.CLASS);
      else if (opt.postfixPackage && idx > 0 && idx < (qualifiedName.length() - 1)) {
        String packageName = qualifiedName.substring(0, idx);
        String cn = className.substring(idx + 1);
        tableLine(Align.CENTER, escape(cn), opt, font);
        tableLine(Align.CENTER, packageName, opt, Font.PACKAGE);
      } else {
        tableLine(Align.CENTER, escape(qualifiedName), opt, font);
      }
      tagvalue(opt, c);
      firstInnerTableEnd(opt, nRows);

      /*
       * Warning: The boolean expressions guarding innerTableStart()
       * in this block, should match those in the code block above
       * marked: "Calculate the number of innerTable rows we will emmit"
       */
      if (showMembers) {
        if (opt.showAttributes) {
          innerTableStart();
          FieldDoc[] fields = c.fields();
          // if there are no fields, print an empty line to generate proper HTML
          if (fields.length == 0) tableLine(Align.LEFT, "");
          else attributes(opt, c.fields());
          innerTableEnd();
        } else if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) {
          // show an emtpy box if we don't show attributes but
          // we show operations
          innerTableStart();
          tableLine(Align.LEFT, "");
          innerTableEnd();
        }
        if (c.isEnum() && opt.showEnumConstants) {
          innerTableStart();
          FieldDoc[] ecs = c.enumConstants();
          // if there are no constants, print an empty line to generate proper HTML
          if (ecs.length == 0) {
            tableLine(Align.LEFT, "");
          } else {
            for (FieldDoc fd : c.enumConstants()) {
              tableLine(Align.LEFT, fd.name());
            }
          }
          innerTableEnd();
        }
        if (!c.isEnum() && (opt.showConstructors || opt.showOperations)) {
          innerTableStart();
          boolean printedLines = false;
          if (opt.showConstructors) printedLines |= operations(opt, c.constructors());
          if (opt.showOperations) printedLines |= operations(opt, c.methods());

          if (!printedLines)
            // if there are no operations nor constructors,
            // print an empty line to generate proper HTML
            tableLine(Align.LEFT, "");

          innerTableEnd();
        }
      }
      externalTableEnd();
      w.print(", URL=\"" + classToUrl(c, rootClass) + "\"");
      nodeProperties(opt);

      // If needed, add a note for this node
      int ni = 0;
      for (Tag t : c.tags("note")) {
        String noteName = "n" + ni + "c" + ci.name;
        w.print("\t// Note annotation\n");
        w.print("\t" + noteName + " [label=");
        externalTableStart(
            UmlGraph.getCommentOptions(), c.qualifiedName(), classToUrl(c, rootClass));
        innerTableStart();
        tableLine(
            Align.LEFT, htmlNewline(escape(t.text())), UmlGraph.getCommentOptions(), Font.CLASS);
        innerTableEnd();
        externalTableEnd();
        nodeProperties(UmlGraph.getCommentOptions());
        w.print("\t" + noteName + " -> " + relationNode(c) + "[arrowhead=none];\n");
        ni++;
      }
      ci.nodePrinted = true;
    }
    return ci.name;
  }