Ejemplo n.º 1
0
 public static boolean start(RootDoc root) {
   ClassDoc[] classDocs = root.classes();
   if (ArrayUtils.isNotEmpty(classDocs)) {
     for (ClassDoc classDoc : root.classes()) scanClassDoc(result.docs, classDoc);
   }
   return true;
 }
Ejemplo n.º 2
0
  /**
   * Builds the views according to the parameters on the command line
   *
   * @param opt The options
   * @param srcRootDoc The RootDoc for the source classes
   * @param viewRootDoc The RootDoc for the view classes (may be different, or may be the same as
   *     the srcRootDoc)
   */
  public static View[] buildViews(Options opt, RootDoc srcRootDoc, RootDoc viewRootDoc) {
    if (opt.viewName != null) {
      ClassDoc viewClass = viewRootDoc.classNamed(opt.viewName);
      if (viewClass == null) {
        System.out.println(
            "View " + opt.viewName + " not found! Exiting without generating any output.");
        return null;
      }
      if (viewClass.tags("view").length == 0) {
        System.out.println(viewClass + " is not a view!");
        return null;
      }
      if (viewClass.isAbstract()) {
        System.out.println(viewClass + " is an abstract view, no output will be generated!");
        return null;
      }
      return new View[] {buildView(srcRootDoc, viewClass, opt)};
    } else if (opt.findViews) {
      List<View> views = new ArrayList<View>();
      ClassDoc[] classes = viewRootDoc.classes();

      // find view classes
      for (int i = 0; i < classes.length; i++)
        if (classes[i].tags("view").length > 0 && !classes[i].isAbstract())
          views.add(buildView(srcRootDoc, classes[i], opt));

      return views.toArray(new View[views.size()]);
    } else return new View[0];
  }
Ejemplo n.º 3
0
 public void process(RootDoc root) {
   final ClassDoc[] classes = root.classes();
   for (ClassDoc clss : classes) {
     if (isBusinessMeaningful(clss)) {
       process(clss);
     }
   }
 }
Ejemplo n.º 4
0
  public static void writeClassLists() {
    int i;
    Data data = makePackageHDF();

    ClassInfo[] classes = PackageInfo.filterHidden(Converter.convertClasses(root.classes()));
    if (classes.length == 0) {
      return;
    }

    Sorter[] sorted = new Sorter[classes.length];
    for (i = 0; i < sorted.length; i++) {
      ClassInfo cl = classes[i];
      String name = cl.name();
      sorted[i] = new Sorter(name, cl);
    }

    Arrays.sort(sorted);

    // make a pass and resolve ones that have the same name
    int firstMatch = 0;
    String lastName = sorted[0].label;
    for (i = 1; i < sorted.length; i++) {
      String s = sorted[i].label;
      if (!lastName.equals(s)) {
        if (firstMatch != i - 1) {
          // there were duplicates
          for (int j = firstMatch; j < i; j++) {
            PackageInfo pkg = ((ClassInfo) sorted[j].data).containingPackage();
            if (pkg != null) {
              sorted[j].label = sorted[j].label + " (" + pkg.name() + ")";
            }
          }
        }
        firstMatch = i;
        lastName = s;
      }
    }

    // and sort again
    Arrays.sort(sorted);

    for (i = 0; i < sorted.length; i++) {
      String s = sorted[i].label;
      ClassInfo cl = (ClassInfo) sorted[i].data;
      char first = Character.toUpperCase(s.charAt(0));
      cl.makeShortDescrHDF(data, "docs.classes." + first + '.' + i);
    }

    setPageTitle(data, "Class Index");
    ClearPage.write(data, "classes.cs", javadocDir + "classes" + htmlExtension);
  }
Ejemplo n.º 5
0
 public List<StepClassDoc> filterStepClassDocs() throws QuoteTailNotFoundException {
   List<StepClassDoc> stepClassDocs = new ArrayList<StepClassDoc>();
   int classId = 1;
   for (ClassDoc classDoc : rootDoc.classes()) {
     if (isCandidateClassDoc(classDoc)) {
       StepClassDoc stepClassDoc = new StepClassDoc(classId, classDoc);
       if (stepClassDoc.isStepClassDoc()) {
         rootDoc.printNotice("Step class found: " + classDoc);
         stepClassDocs.add(stepClassDoc);
         classId++;
       }
     }
   }
   return stepClassDocs;
 }
Ejemplo n.º 6
0
  /** Builds and outputs a single graph according to the view overrides */
  public static void buildGraph(RootDoc root, OptionProvider op, Doc contextDoc)
      throws IOException {
    if (getCommentOptions() == null) buildOptions(root);
    Options opt = op.getGlobalOptions();
    root.printNotice("Building " + op.getDisplayName());
    ClassDoc[] classes = root.classes();

    ClassGraph c = new ClassGraph(root, op, contextDoc);
    c.prologue();
    for (int i = 0; i < classes.length; i++) c.printClass(classes[i], true);
    for (int i = 0; i < classes.length; i++) c.printRelations(classes[i]);
    if (opt.inferRelationships) c.printInferredRelations(classes);
    if (opt.inferDependencies) c.printInferredDependencies(classes);

    c.printExtraClasses(root);
    c.epilogue();
  }
Ejemplo n.º 7
0
  public static boolean start(RootDoc root) {
    try {
      init(root);
      ClassDoc[] classes = root.classes();
      ArrayList<String> generatesTestClasses = new ArrayList<String>();
      for (int i = 0; i < classes.length; i++) {
        ClassDoc classDoc = classes[i];
        if (classDoc.isAbstract()
            || classDoc.isInterface()
            || classDoc.isEnum()
            || classDoc.isPrivate()
            || classDoc.isAnnotationType()) {
        } else if (!hasDefaultConstructor(classDoc)) {
          System.out.println(classDoc.qualifiedTypeName() + " does not have default Constructor.");
        } else {
          ClassBean testClassBean = ClassBeanCreator.create(classDoc);
          if (testClassBean.hasMethods()) {
            JavaCodeWriter writer = getWriter(testClassBean);
            if (writer != null) {
              JavaCodeGenerator.generate(testClassBean, writer);
              generatesTestClasses.add(classDoc.qualifiedTypeName());
              writer.close();
            }
          } else {
            System.out.println(
                classDoc.qualifiedTypeName() + " does not have any methods to cover.");
          }
        }
      }
      System.out.println("---------REPORT-----------------------------------------------");
      for (Iterator iterator = generatesTestClasses.iterator(); iterator.hasNext(); ) {
        String clsName = (String) iterator.next();
        System.out.println("\t" + clsName);
      }
      System.out.println("-------------------------------------------------------------");

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
Ejemplo n.º 8
0
  private static void generateText(RootDoc root) throws IOException {
    List<RestMethod> methods = new ArrayList<RestMethod>();

    for (ClassDoc classDoc : root.classes()) {
      for (MethodDoc methodDoc : classDoc.methods()) {
        if (methodDoc.isPublic()) {
          methods.add(new RestMethod(methodDoc));
        }
      }
    }

    FileWriter jsonFile = null;

    try {
      jsonFile = new FileWriter(outputDir + "/candlepin_comments.json");
      mapper.writeValue(jsonFile, methods);
    } finally {
      jsonFile.close();
    }
  }
Ejemplo n.º 9
0
  /**
   * The entry point for processing provides an object to access the various attributes of all the
   * classes being documented.
   *
   * @param rootDoc the root of the documentation tree
   * @return some boolean value
   */
  public static boolean start(RootDoc rootDoc) {
    ClassDoc[] classes;
    Iterator i = null;
    readConfig();
    my_initialize();
    classes = rootDoc.classes();
    i = m_pipeline.values().iterator();

    while (i.hasNext()) {
      tool = (FeatureTool) i.next();
      for (int i = 0; i < classes.length; i++) {
        m_commentQualityRecords.add(tool.process(classes[i]));
      }
    }

    // correlate/aggregate quality reports

    // display quality reports

    return true;
  }
Ejemplo n.º 10
0
  private void startGeneration(RootDoc root) throws Exception {
    if (root.classes().length == 0) {
      configuration.message.error("doclet.No_Public_Classes_To_Document");
      return;
    }
    configuration.setOptions();
    configuration
        .getDocletSpecificMsg()
        .notice("doclet.build_version", configuration.getDocletSpecificBuildDate());

    configuration.tagletManager.addCustomTag(new SequenceDiagramTag());
    configuration.tagletManager.addCustomTag(new DotDiagramTag());
    configuration.tagletManager.addNewSimpleCustomTag("ArchitectureDocument", "", "X");

    ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);

    generateClassFiles(root, classtree);
    if (configuration.sourcepath != null && configuration.sourcepath.length() > 0) {
      StringTokenizer pathTokens =
          new StringTokenizer(configuration.sourcepath, String.valueOf(File.pathSeparatorChar));
      boolean first = true;
      while (pathTokens.hasMoreTokens()) {
        Util.copyDocFiles(
            configuration,
            pathTokens.nextToken() + File.separator,
            DocletConstants.DOC_FILES_DIR_NAME,
            first);
        first = false;
      }
    }

    PackageListWriter.generate(configuration);
    generatePackageFiles(classtree);

    generateOtherFiles(root, classtree);
    configuration.tagletManager.printReport();
  }
Ejemplo n.º 11
0
  /** @throws Exception . */
  public void run() throws Exception {

    // GENERATE DOCUMENTATIONS IN DOC CLASSES
    ClassDoc[] classes = documentation.classes();
    List<DocController> controllers = generateControllers(classes);
    logger.log(
        Level.INFO,
        "Generated "
            + controllers.size()
            + " controlles, creating HTML documentation using velocity template.");

    // TRANSLATE DOC CLASSES INTO HTML DOCUMENTATION USING VELOCITY TEMPLATE
    String generatedHtml = generateHtmlDocumentation(controllers);

    // WRITE GENERATED HTML TO A FILE
    FileWriter velocityfileWriter = null;
    try {
      File file = new File(docPath);
      File parentFile = file.getParentFile();
      if (parentFile != null) {
        if (parentFile.mkdirs()) {
          logger.log(
              Level.FINEST,
              "The directory "
                  + parentFile.getAbsolutePath()
                  + " was created, along with all necessary parent directories.");
        }
      }
      logger.log(Level.INFO, "Write generated velocity to " + file.getAbsolutePath());
      velocityfileWriter = new FileWriter(file);
      velocityfileWriter.write(generatedHtml);
    } finally {
      if (velocityfileWriter != null) {
        velocityfileWriter.close();
      }
    }
  }
Ejemplo n.º 12
0
  /**
   * Create a new ClassGraph.
   *
   * <p>The packages passed as an argument are the ones specified on the command line.
   *
   * <p>Local URLs will be generated for these packages.
   *
   * @param root The root of docs as provided by the javadoc API
   * @param optionProvider The main option provider
   * @param contextDoc The current context for generating relative links, may be a ClassDoc or a
   *     PackageDoc (used by UMLDoc)
   */
  public ClassGraph(RootDoc root, OptionProvider optionProvider, Doc contextDoc) {
    this.optionProvider = optionProvider;
    this.collectionClassDoc = root.classNamed("java.util.Collection");
    this.mapClassDoc = root.classNamed("java.util.Map");
    this.contextDoc = contextDoc;

    // to gather the packages containing specified classes, loop thru them and gather
    // package definitions. User root.specifiedPackages is not safe, since the user
    // may specify just a list of classes (human users usually don't, but automated tools do)
    rootClasses = new HashSet<String>();
    for (ClassDoc classDoc : root.classes()) {
      rootClasses.add(classDoc.qualifiedName());
      rootClassdocs.put(classDoc.qualifiedName(), classDoc);
    }

    Options opt = optionProvider.getGlobalOptions();
    if (opt.compact) {
      linePrefix = "";
      linePostfix = "";
    } else {
      linePrefix = "\t";
      linePostfix = "\n";
    }
  }
Ejemplo n.º 13
0
 /** Return the ClassDoc for the specified class; null if not found. */
 private static ClassDoc findClass(RootDoc root, String name) {
   ClassDoc[] classes = root.classes();
   for (ClassDoc cd : classes) if (cd.name().equals(name)) return cd;
   return null;
 }
 public static boolean start(RootDoc root) {
   ClassDoc cd = root.classes()[0];
   FieldDoc fd = cd.fields()[0];
   fd.firstSentenceTags();
   return true;
 }
 public static boolean start(com.sun.javadoc.RootDoc root) {
   ClassDoc[] classes = root.classes();
   if (classes.length != 1) throw new Error("1 " + Arrays.asList(classes));
   return true;
 }
Ejemplo n.º 16
0
 /**
  * Constructor. Build the Tree using the Root of this Javadoc run.
  *
  * @param root Root of the Document.
  * @param configuration The curren configuration of the doclet.
  */
 public ClassTree(RootDoc root, Configuration configuration) {
   buildTree(root.classes(), configuration);
 }
Ejemplo n.º 17
0
  /**
   * The entry point into the Parser class.
   *
   * @param root A RootDoc intstance obtained via the doclet API
   * @return A XML (XStream) serializable element, containing everything parsed from javadoc doclet
   */
  public static Root ParseRoot(RootDoc root) {
    processingStorage = new HashMap<PackageDoc, ParserMediary>();

    try {
      md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      log.error("unable to acquire MD5 algorithm", e);
      return null;
    }

    rootXml = new Root();

    ClassDoc[] allClasses = root.classes();

    for (ClassDoc classDoc : allClasses) {
      PackageDoc doc = classDoc.containingPackage();

      ParserMediary mediary = null;

      // the age old 'if I have it pull out existing, if I don't make a new one'
      if (processingStorage.containsKey(doc)) {
        mediary = processingStorage.get(doc);
      } else {
        mediary =
            new ParserMediary(
                doc.name(),
                doc.commentText(),
                ParseAnnotationInstances(doc.annotations(), doc.name()));

        processingStorage.put(doc, mediary);
      }

      if (classDoc.isIncluded()) {
        // dev comment--why do enums show up as ordinary class?
        if (classDoc.isOrdinaryClass() || classDoc.isException() || classDoc.isError()) {
          mediary.addClass(ParseClass(classDoc));
        } else if (classDoc.isEnum()) {
          mediary.addEnum(ParseEnum(classDoc));
        } else if (isAnnotation(classDoc)) {
          mediary.addAnnotation(ParseAnnotation(classDoc));
        } else if (classDoc.isInterface()) {
          mediary.addInterface(ParseInterface(classDoc));
        }
      } else {
        log.debug("Skipping not-included class " + classDoc.qualifiedName());
      }
    }

    if (processingStorage.size() > 0) {
      List list = new ArrayList<Package>();

      for (ParserMediary mediary : processingStorage.values()) {
        list.add(mediary.wrapup());
      }

      rootXml.packages = (Package[]) list.toArray(new Package[] {});
    } else {
      log.warn("No packages found!");
    }

    return rootXml;
  }