Mon, 09 Mar 2009 23:53:41 -0700
Merge
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 1998-2004 Sun Microsystems, Inc. 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 |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun 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 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 29 | |
duke@1 | 30 | import com.sun.javadoc.*; |
duke@1 | 31 | import java.io.*; |
duke@1 | 32 | import java.util.*; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Abstract class to print the class hierarchy page for all the Classes. This |
duke@1 | 36 | * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to |
duke@1 | 37 | * generate the Package Tree and global Tree(for all the classes and packages) |
duke@1 | 38 | * pages. |
duke@1 | 39 | * |
duke@1 | 40 | * @author Atul M Dambalkar |
duke@1 | 41 | */ |
duke@1 | 42 | public abstract class AbstractTreeWriter extends HtmlDocletWriter { |
duke@1 | 43 | |
duke@1 | 44 | /** |
duke@1 | 45 | * The class and interface tree built by using {@link ClassTree} |
duke@1 | 46 | */ |
duke@1 | 47 | protected final ClassTree classtree; |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * Constructor initilises classtree variable. This constructor will be used |
duke@1 | 51 | * while generating global tree file "overview-tree.html". |
duke@1 | 52 | * |
duke@1 | 53 | * @param filename File to be generated. |
duke@1 | 54 | * @param classtree Tree built by {@link ClassTree}. |
duke@1 | 55 | * @throws IOException |
duke@1 | 56 | * @throws DocletAbortException |
duke@1 | 57 | */ |
duke@1 | 58 | protected AbstractTreeWriter(ConfigurationImpl configuration, |
duke@1 | 59 | String filename, ClassTree classtree) |
duke@1 | 60 | throws IOException { |
duke@1 | 61 | super(configuration, filename); |
duke@1 | 62 | this.classtree = classtree; |
duke@1 | 63 | } |
duke@1 | 64 | |
duke@1 | 65 | /** |
duke@1 | 66 | * Create appropriate directory for the package and also initilise the |
duke@1 | 67 | * relative path from this generated file to the current or |
duke@1 | 68 | * the destination directory. This constructor will be used while |
duke@1 | 69 | * generating "package tree" file. |
duke@1 | 70 | * |
duke@1 | 71 | * @param path Directories in this path will be created if they are not |
duke@1 | 72 | * already there. |
duke@1 | 73 | * @param filename Name of the package tree file to be generated. |
duke@1 | 74 | * @param classtree The tree built using {@link ClassTree}. |
duke@1 | 75 | * for the package pkg. |
duke@1 | 76 | * @param pkg PackageDoc for which tree file will be generated. |
duke@1 | 77 | * @throws IOException |
duke@1 | 78 | * @throws DocletAbortException |
duke@1 | 79 | */ |
duke@1 | 80 | protected AbstractTreeWriter(ConfigurationImpl configuration, |
duke@1 | 81 | String path, String filename, |
duke@1 | 82 | ClassTree classtree, PackageDoc pkg) |
duke@1 | 83 | throws IOException { |
duke@1 | 84 | super(configuration, |
duke@1 | 85 | path, filename, DirectoryManager.getRelativePath(pkg.name())); |
duke@1 | 86 | this.classtree = classtree; |
duke@1 | 87 | } |
duke@1 | 88 | |
duke@1 | 89 | /** |
duke@1 | 90 | * Generate each level of the class tree. For each sub-class or |
duke@1 | 91 | * sub-interface indents the next level information. |
duke@1 | 92 | * Recurses itself to generate subclasses info. |
duke@1 | 93 | * To iterate is human, to recurse is divine - L. Peter Deutsch. |
duke@1 | 94 | * |
duke@1 | 95 | * @param parent the superclass or superinterface of the list. |
duke@1 | 96 | * @param list list of the sub-classes at this level. |
duke@1 | 97 | * @param isEnum true if we are generating a tree for enums. |
duke@1 | 98 | */ |
mcimadamore@184 | 99 | protected void generateLevelInfo(ClassDoc parent, List<ClassDoc> list, |
duke@1 | 100 | boolean isEnum) { |
duke@1 | 101 | if (list.size() > 0) { |
duke@1 | 102 | ul(); |
duke@1 | 103 | for (int i = 0; i < list.size(); i++) { |
mcimadamore@184 | 104 | ClassDoc local = list.get(i); |
duke@1 | 105 | printPartialInfo(local); |
duke@1 | 106 | printExtendsImplements(parent, local); |
duke@1 | 107 | generateLevelInfo(local, classtree.subs(local, isEnum), |
duke@1 | 108 | isEnum); // Recurse |
duke@1 | 109 | } |
duke@1 | 110 | ulEnd(); |
duke@1 | 111 | } |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | /** |
duke@1 | 115 | * Generate the heading for the tree depending upon tree type if it's a |
duke@1 | 116 | * Class Tree or Interface tree and also print the tree. |
duke@1 | 117 | * |
duke@1 | 118 | * @param list List of classes which are at the most base level, all the |
duke@1 | 119 | * other classes in this run will derive from these classes. |
duke@1 | 120 | * @param heading Heading for the tree. |
duke@1 | 121 | */ |
mcimadamore@184 | 122 | protected void generateTree(List<ClassDoc> list, String heading) { |
duke@1 | 123 | if (list.size() > 0) { |
mcimadamore@184 | 124 | ClassDoc firstClassDoc = list.get(0); |
duke@1 | 125 | printTreeHeading(heading); |
duke@1 | 126 | generateLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null, |
duke@1 | 127 | list, |
duke@1 | 128 | list == classtree.baseEnums()); |
duke@1 | 129 | } |
duke@1 | 130 | } |
duke@1 | 131 | |
duke@1 | 132 | /** |
duke@1 | 133 | * Print the information regarding the classes which this class extends or |
duke@1 | 134 | * implements. |
duke@1 | 135 | * |
duke@1 | 136 | * @param cd The classdoc under consideration. |
duke@1 | 137 | */ |
duke@1 | 138 | protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) { |
duke@1 | 139 | ClassDoc[] interfaces = cd.interfaces(); |
duke@1 | 140 | if (interfaces.length > (cd.isInterface()? 1 : 0)) { |
duke@1 | 141 | Arrays.sort(interfaces); |
duke@1 | 142 | int counter = 0; |
duke@1 | 143 | for (int i = 0; i < interfaces.length; i++) { |
duke@1 | 144 | if (parent != interfaces[i]) { |
duke@1 | 145 | if (! (interfaces[i].isPublic() || |
duke@1 | 146 | Util.isLinkable(interfaces[i], configuration()))) { |
duke@1 | 147 | continue; |
duke@1 | 148 | } |
duke@1 | 149 | if (counter == 0) { |
duke@1 | 150 | if (cd.isInterface()) { |
duke@1 | 151 | print(" (" + configuration.getText("doclet.also") + " extends "); |
duke@1 | 152 | } else { |
duke@1 | 153 | print(" (implements "); |
duke@1 | 154 | } |
duke@1 | 155 | } else { |
duke@1 | 156 | print(", "); |
duke@1 | 157 | } |
duke@1 | 158 | printPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE, |
duke@1 | 159 | interfaces[i]); |
duke@1 | 160 | counter++; |
duke@1 | 161 | } |
duke@1 | 162 | } |
duke@1 | 163 | if (counter > 0) { |
duke@1 | 164 | println(")"); |
duke@1 | 165 | } |
duke@1 | 166 | } |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * Print information about the class kind, if it's a "class" or "interface". |
duke@1 | 171 | * |
duke@1 | 172 | * @param cd classdoc. |
duke@1 | 173 | */ |
duke@1 | 174 | protected void printPartialInfo(ClassDoc cd) { |
duke@1 | 175 | li("circle"); |
bpatel@182 | 176 | printPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd); |
duke@1 | 177 | } |
duke@1 | 178 | |
duke@1 | 179 | /** |
duke@1 | 180 | * Print the heading for the tree. |
duke@1 | 181 | * |
duke@1 | 182 | * @param heading Heading for the tree. |
duke@1 | 183 | */ |
duke@1 | 184 | protected void printTreeHeading(String heading) { |
duke@1 | 185 | h2(); |
duke@1 | 186 | println(configuration.getText(heading)); |
duke@1 | 187 | h2End(); |
duke@1 | 188 | } |
duke@1 | 189 | |
duke@1 | 190 | /** |
duke@1 | 191 | * Highlight "Tree" word in the navigation bar, since this is the tree page. |
duke@1 | 192 | */ |
duke@1 | 193 | protected void navLinkTree() { |
duke@1 | 194 | navCellRevStart(); |
duke@1 | 195 | fontStyle("NavBarFont1Rev"); |
bpatel@182 | 196 | strongText("doclet.Tree"); |
duke@1 | 197 | fontEnd(); |
duke@1 | 198 | navCellEnd(); |
duke@1 | 199 | } |
duke@1 | 200 | } |