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