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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 1357
c75be5bc5283
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

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

mercurial