src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.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

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

mercurial