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

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 1735
8ea30d59ac41
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

     1 /*
     2  * Copyright (c) 1998, 2013, 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.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.markup.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Abstract class to print the class hierarchy page for all the Classes. This
    38  * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
    39  * generate the Package Tree and global Tree(for all the classes and packages)
    40  * pages.
    41  *
    42  *  <p><b>This is NOT part of any supported API.
    43  *  If you write code that depends on this, you do so at your own risk.
    44  *  This code and its internal interfaces are subject to change or
    45  *  deletion without notice.</b>
    46  *
    47  * @author Atul M Dambalkar
    48  */
    49 public abstract class AbstractTreeWriter extends HtmlDocletWriter {
    51     /**
    52      * The class and interface tree built by using {@link ClassTree}
    53      */
    54     protected final ClassTree classtree;
    56     private static final String LI_CIRCLE  = "circle";
    58     /**
    59      * Constructor initializes classtree variable. This constructor will be used
    60      * while generating global tree file "overview-tree.html".
    61      *
    62      * @param configuration  The current configuration
    63      * @param filename   File to be generated.
    64      * @param classtree  Tree built by {@link ClassTree}.
    65      * @throws IOException
    66      * @throws DocletAbortException
    67      */
    68     protected AbstractTreeWriter(ConfigurationImpl configuration,
    69                                  DocPath filename, ClassTree classtree)
    70                                  throws IOException {
    71         super(configuration, filename);
    72         this.classtree = classtree;
    73     }
    75     /**
    76      * Add each level of the class tree. For each sub-class or
    77      * sub-interface indents the next level information.
    78      * Recurses itself to add subclasses info.
    79      *
    80      * @param parent the superclass or superinterface of the list
    81      * @param list list of the sub-classes at this level
    82      * @param isEnum true if we are generating a tree for enums
    83      * @param contentTree the content tree to which the level information will be added
    84      */
    85     protected void addLevelInfo(ClassDoc parent, List<ClassDoc> list,
    86             boolean isEnum, Content contentTree) {
    87         int size = list.size();
    88         if (size > 0) {
    89             Content ul = new HtmlTree(HtmlTag.UL);
    90             for (int i = 0; i < size; i++) {
    91                 ClassDoc local = list.get(i);
    92                 HtmlTree li = new HtmlTree(HtmlTag.LI);
    93                 li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
    94                 addPartialInfo(local, li);
    95                 addExtendsImplements(parent, local, li);
    96                 addLevelInfo(local, classtree.subs(local, isEnum),
    97                         isEnum, li);   // Recurse
    98                 ul.addContent(li);
    99             }
   100             contentTree.addContent(ul);
   101         }
   102     }
   104     /**
   105      * Add the heading for the tree depending upon tree type if it's a
   106      * Class Tree or Interface tree.
   107      *
   108      * @param list List of classes which are at the most base level, all the
   109      * other classes in this run will derive from these classes
   110      * @param heading heading for the tree
   111      * @param div the content tree to which the tree will be added
   112      */
   113     protected void addTree(List<ClassDoc> list, String heading, Content div) {
   114         if (list.size() > 0) {
   115             ClassDoc firstClassDoc = list.get(0);
   116             Content headingContent = getResource(heading);
   117             div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
   118                     headingContent));
   119             addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
   120                     list, list == classtree.baseEnums(), div);
   121         }
   122     }
   124     /**
   125      * Add information regarding the classes which this class extends or
   126      * implements.
   127      *
   128      * @param parent the parent class of the class being documented
   129      * @param cd the classdoc under consideration
   130      * @param contentTree the content tree to which the information will be added
   131      */
   132     protected void addExtendsImplements(ClassDoc parent, ClassDoc cd,
   133             Content contentTree) {
   134         ClassDoc[] interfaces = cd.interfaces();
   135         if (interfaces.length > (cd.isInterface()? 1 : 0)) {
   136             Arrays.sort(interfaces);
   137             int counter = 0;
   138             for (int i = 0; i < interfaces.length; i++) {
   139                 if (parent != interfaces[i]) {
   140                     if (! (interfaces[i].isPublic() ||
   141                             Util.isLinkable(interfaces[i], configuration))) {
   142                         continue;
   143                     }
   144                     if (counter == 0) {
   145                         if (cd.isInterface()) {
   146                             contentTree.addContent(" (");
   147                             contentTree.addContent(getResource("doclet.also"));
   148                             contentTree.addContent(" extends ");
   149                         } else {
   150                             contentTree.addContent(" (implements ");
   151                         }
   152                     } else {
   153                         contentTree.addContent(", ");
   154                     }
   155                     addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE,
   156                             interfaces[i], contentTree);
   157                     counter++;
   158                 }
   159             }
   160             if (counter > 0) {
   161                 contentTree.addContent(")");
   162             }
   163         }
   164     }
   166     /**
   167      * Add information about the class kind, if it's a "class" or "interface".
   168      *
   169      * @param cd the class being documented
   170      * @param contentTree the content tree to which the information will be added
   171      */
   172     protected void addPartialInfo(ClassDoc cd, Content contentTree) {
   173         addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree);
   174     }
   176     /**
   177      * Get the tree label for the navigation bar.
   178      *
   179      * @return a content tree for the tree label
   180      */
   181     protected Content getNavLinkTree() {
   182         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel);
   183         return li;
   184     }
   185 }

mercurial