src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1372
78962d89f283
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.formats.html.markup.*;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    33 import com.sun.tools.doclets.internal.toolkit.util.*;
    35 /**
    36  * Generate Class Hierarchy page for all the Classes in this run.  Use
    37  * ClassTree for building the Tree. The name of
    38  * the generated file is "overview-tree.html" and it is generated in the
    39  * current or the destination directory.
    40  *
    41  *  <p><b>This is NOT part of any supported API.
    42  *  If you write code that depends on this, you do so at your own risk.
    43  *  This code and its internal interfaces are subject to change or
    44  *  deletion without notice.</b>
    45  *
    46  * @author Atul M Dambalkar
    47  * @author Bhavesh Patel (Modified)
    48  */
    49 public class TreeWriter extends AbstractTreeWriter {
    51     /**
    52      * Packages in this run.
    53      */
    54     private PackageDoc[] packages;
    56     /**
    57      * True if there are no packages specified on the command line,
    58      * False otherwise.
    59      */
    60     private boolean classesonly;
    62     /**
    63      * Constructor to construct TreeWriter object.
    64      *
    65      * @param configuration the current configuration of the doclet.
    66      * @param filename String filename
    67      * @param classtree the tree being built.
    68      */
    69     public TreeWriter(ConfigurationImpl configuration,
    70             String filename, ClassTree classtree)
    71     throws IOException {
    72         super(configuration, filename, classtree);
    73         packages = configuration.packages;
    74     classesonly = packages.length == 0;
    75     }
    77     /**
    78      * Create a TreeWriter object and use it to generate the
    79      * "overview-tree.html" file.
    80      *
    81      * @param classtree the class tree being documented.
    82      * @throws  DocletAbortException
    83      */
    84     public static void generate(ConfigurationImpl configuration,
    85                                 ClassTree classtree) {
    86         TreeWriter treegen;
    87         String filename = "overview-tree.html";
    88         try {
    89             treegen = new TreeWriter(configuration, filename, classtree);
    90             treegen.generateTreeFile();
    91             treegen.close();
    92         } catch (IOException exc) {
    93             configuration.standardmessage.error(
    94                         "doclet.exception_encountered",
    95                         exc.toString(), filename);
    96             throw new DocletAbortException();
    97         }
    98     }
   100     /**
   101      * Generate the interface hierarchy and class hierarchy.
   102      */
   103     public void generateTreeFile() throws IOException {
   104         Content body = getTreeHeader();
   105         Content headContent = getResource("doclet.Hierarchy_For_All_Packages");
   106         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
   107                 HtmlStyle.title, headContent);
   108         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
   109         addPackageTreeLinks(div);
   110         body.addContent(div);
   111         HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
   112         divTree.addStyle(HtmlStyle.contentContainer);
   113         addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
   114         addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
   115         addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
   116         addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
   117         body.addContent(divTree);
   118         addNavLinks(false, body);
   119         addBottom(body);
   120         printHtmlDocument(null, true, body);
   121     }
   123     /**
   124      * Add the links to all the package tree files.
   125      *
   126      * @param contentTree the content tree to which the links will be added
   127      */
   128     protected void addPackageTreeLinks(Content contentTree) {
   129         //Do nothing if only unnamed package is used
   130         if (packages.length == 1 && packages[0].name().length() == 0) {
   131             return;
   132         }
   133         if (!classesonly) {
   134             Content span = HtmlTree.SPAN(HtmlStyle.strong,
   135                     getResource("doclet.Package_Hierarchies"));
   136             contentTree.addContent(span);
   137             HtmlTree ul = new HtmlTree(HtmlTag.UL);
   138             ul.addStyle(HtmlStyle.horizontal);
   139             for (int i = 0; i < packages.length; i++) {
   140                 // If the package name length is 0 or if -nodeprecated option
   141                 // is set and the package is marked as deprecated, do not include
   142                 // the page in the list of package hierarchies.
   143                 if (packages[i].name().length() == 0 ||
   144                         (configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
   145                     continue;
   146                 }
   147                 String link = pathString(packages[i], "package-tree.html");
   148                 Content li = HtmlTree.LI(getHyperLink(
   149                         link, "", new StringContent(packages[i].name())));
   150                 if (i < packages.length - 1) {
   151                     li.addContent(", ");
   152                 }
   153                 ul.addContent(li);
   154             }
   155             contentTree.addContent(ul);
   156         }
   157     }
   159     /**
   160      * Get the tree header.
   161      *
   162      * @return a content tree for the tree header
   163      */
   164     protected Content getTreeHeader() {
   165         String title = configuration.getText("doclet.Window_Class_Hierarchy");
   166         Content bodyTree = getBody(true, getWindowTitle(title));
   167         addTop(bodyTree);
   168         addNavLinks(true, bodyTree);
   169         return bodyTree;
   170     }
   171 }

mercurial