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

Thu, 29 Aug 2013 11:41:20 -0700

author
jjg
date
Thu, 29 Aug 2013 11:41:20 -0700
changeset 1985
0e6577980181
parent 1735
8ea30d59ac41
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8001669: javadoc internal DocletAbortException should set cause when appropriate
Reviewed-by: darcy

duke@1 1 /*
jjg@1735 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
duke@1 28 import java.io.*;
duke@1 29 import java.util.*;
jjg@1357 30
jjg@1357 31 import com.sun.javadoc.*;
jjg@1357 32 import com.sun.tools.doclets.formats.html.markup.*;
jjg@1357 33 import com.sun.tools.doclets.internal.toolkit.*;
bpatel@766 34 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 35
duke@1 36 /**
duke@1 37 * Abstract class to print the class hierarchy page for all the Classes. This
duke@1 38 * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
duke@1 39 * generate the Package Tree and global Tree(for all the classes and packages)
duke@1 40 * pages.
duke@1 41 *
jjg@1359 42 * <p><b>This is NOT part of any supported API.
jjg@1359 43 * If you write code that depends on this, you do so at your own risk.
jjg@1359 44 * This code and its internal interfaces are subject to change or
jjg@1359 45 * deletion without notice.</b>
jjg@1359 46 *
duke@1 47 * @author Atul M Dambalkar
duke@1 48 */
duke@1 49 public abstract class AbstractTreeWriter extends HtmlDocletWriter {
duke@1 50
duke@1 51 /**
duke@1 52 * The class and interface tree built by using {@link ClassTree}
duke@1 53 */
duke@1 54 protected final ClassTree classtree;
duke@1 55
bpatel@766 56 private static final String LI_CIRCLE = "circle";
bpatel@766 57
duke@1 58 /**
jjg@1372 59 * Constructor initializes classtree variable. This constructor will be used
duke@1 60 * while generating global tree file "overview-tree.html".
duke@1 61 *
jjg@1372 62 * @param configuration The current configuration
duke@1 63 * @param filename File to be generated.
duke@1 64 * @param classtree Tree built by {@link ClassTree}.
duke@1 65 * @throws IOException
duke@1 66 * @throws DocletAbortException
duke@1 67 */
duke@1 68 protected AbstractTreeWriter(ConfigurationImpl configuration,
jjg@1372 69 DocPath filename, ClassTree classtree)
duke@1 70 throws IOException {
duke@1 71 super(configuration, filename);
duke@1 72 this.classtree = classtree;
duke@1 73 }
duke@1 74
duke@1 75 /**
bpatel@766 76 * Add each level of the class tree. For each sub-class or
duke@1 77 * sub-interface indents the next level information.
bpatel@766 78 * Recurses itself to add subclasses info.
duke@1 79 *
bpatel@766 80 * @param parent the superclass or superinterface of the list
bpatel@766 81 * @param list list of the sub-classes at this level
bpatel@766 82 * @param isEnum true if we are generating a tree for enums
bpatel@766 83 * @param contentTree the content tree to which the level information will be added
duke@1 84 */
bpatel@766 85 protected void addLevelInfo(ClassDoc parent, List<ClassDoc> list,
bpatel@766 86 boolean isEnum, Content contentTree) {
bpatel@766 87 int size = list.size();
bpatel@766 88 if (size > 0) {
bpatel@766 89 Content ul = new HtmlTree(HtmlTag.UL);
bpatel@766 90 for (int i = 0; i < size; i++) {
mcimadamore@184 91 ClassDoc local = list.get(i);
bpatel@766 92 HtmlTree li = new HtmlTree(HtmlTag.LI);
bpatel@766 93 li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
bpatel@766 94 addPartialInfo(local, li);
bpatel@766 95 addExtendsImplements(parent, local, li);
bpatel@766 96 addLevelInfo(local, classtree.subs(local, isEnum),
bpatel@766 97 isEnum, li); // Recurse
bpatel@766 98 ul.addContent(li);
duke@1 99 }
bpatel@766 100 contentTree.addContent(ul);
duke@1 101 }
duke@1 102 }
duke@1 103
duke@1 104 /**
bpatel@766 105 * Add the heading for the tree depending upon tree type if it's a
bpatel@766 106 * Class Tree or Interface tree.
duke@1 107 *
duke@1 108 * @param list List of classes which are at the most base level, all the
bpatel@766 109 * other classes in this run will derive from these classes
bpatel@766 110 * @param heading heading for the tree
bpatel@766 111 * @param div the content tree to which the tree will be added
duke@1 112 */
bpatel@766 113 protected void addTree(List<ClassDoc> list, String heading, Content div) {
duke@1 114 if (list.size() > 0) {
mcimadamore@184 115 ClassDoc firstClassDoc = list.get(0);
bpatel@766 116 Content headingContent = getResource(heading);
bpatel@766 117 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
bpatel@766 118 headingContent));
bpatel@766 119 addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
bpatel@766 120 list, list == classtree.baseEnums(), div);
duke@1 121 }
duke@1 122 }
duke@1 123
duke@1 124 /**
bpatel@766 125 * Add information regarding the classes which this class extends or
duke@1 126 * implements.
duke@1 127 *
bpatel@766 128 * @param parent the parent class of the class being documented
bpatel@766 129 * @param cd the classdoc under consideration
bpatel@766 130 * @param contentTree the content tree to which the information will be added
duke@1 131 */
bpatel@766 132 protected void addExtendsImplements(ClassDoc parent, ClassDoc cd,
bpatel@766 133 Content contentTree) {
duke@1 134 ClassDoc[] interfaces = cd.interfaces();
duke@1 135 if (interfaces.length > (cd.isInterface()? 1 : 0)) {
duke@1 136 Arrays.sort(interfaces);
duke@1 137 int counter = 0;
duke@1 138 for (int i = 0; i < interfaces.length; i++) {
duke@1 139 if (parent != interfaces[i]) {
duke@1 140 if (! (interfaces[i].isPublic() ||
jjg@1410 141 Util.isLinkable(interfaces[i], configuration))) {
duke@1 142 continue;
duke@1 143 }
duke@1 144 if (counter == 0) {
duke@1 145 if (cd.isInterface()) {
bpatel@766 146 contentTree.addContent(" (");
bpatel@766 147 contentTree.addContent(getResource("doclet.also"));
bpatel@766 148 contentTree.addContent(" extends ");
duke@1 149 } else {
bpatel@766 150 contentTree.addContent(" (implements ");
duke@1 151 }
duke@1 152 } else {
bpatel@766 153 contentTree.addContent(", ");
duke@1 154 }
jjg@1735 155 addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE,
bpatel@766 156 interfaces[i], contentTree);
duke@1 157 counter++;
duke@1 158 }
duke@1 159 }
duke@1 160 if (counter > 0) {
bpatel@766 161 contentTree.addContent(")");
duke@1 162 }
duke@1 163 }
duke@1 164 }
duke@1 165
duke@1 166 /**
bpatel@766 167 * Add information about the class kind, if it's a "class" or "interface".
duke@1 168 *
bpatel@766 169 * @param cd the class being documented
bpatel@766 170 * @param contentTree the content tree to which the information will be added
duke@1 171 */
bpatel@766 172 protected void addPartialInfo(ClassDoc cd, Content contentTree) {
jjg@1735 173 addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree);
duke@1 174 }
duke@1 175
duke@1 176 /**
bpatel@766 177 * Get the tree label for the navigation bar.
duke@1 178 *
bpatel@766 179 * @return a content tree for the tree label
duke@1 180 */
bpatel@766 181 protected Content getNavLinkTree() {
bpatel@766 182 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel);
bpatel@766 183 return li;
duke@1 184 }
duke@1 185 }

mercurial