Thu, 10 Jun 2010 17:09:56 -0700
6960407: Potential rebranding issues in openjdk/langtools repository sources
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1998, 2004, 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.internal.toolkit.util.*;
34 /**
35 * Generate Index for all the Member Names with Indexing in
36 * Unicode Order. This class is a base class for {@link SingleIndexWriter} and
37 * {@link SplitIndexWriter}. It uses the functionality from
38 * {@link HtmlDocletWriter} to generate the Index Contents.
39 *
40 * @see IndexBuilder
41 * @author Atul M Dambalkar
42 */
43 public class AbstractIndexWriter extends HtmlDocletWriter {
45 /**
46 * The index of all the members with unicode character.
47 */
48 protected IndexBuilder indexbuilder;
50 /**
51 * This constructor will be used by {@link SplitIndexWriter}. Initialises
52 * path to this file and relative path from this file.
53 *
54 * @param path Path to the file which is getting generated.
55 * @param filename Name of the file which is getting genrated.
56 * @param relpath Relative path from this file to the current directory.
57 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
58 */
59 protected AbstractIndexWriter(ConfigurationImpl configuration,
60 String path, String filename,
61 String relpath, IndexBuilder indexbuilder)
62 throws IOException {
63 super(configuration, path, filename, relpath);
64 this.indexbuilder = indexbuilder;
65 }
67 /**
68 * This Constructor will be used by {@link SingleIndexWriter}.
69 *
70 * @param filename Name of the file which is getting genrated.
71 * @param indexbuilder Unicode based Index form {@link IndexBuilder}
72 */
73 protected AbstractIndexWriter(ConfigurationImpl configuration,
74 String filename, IndexBuilder indexbuilder)
75 throws IOException {
76 super(configuration, filename);
77 this.indexbuilder = indexbuilder;
78 }
80 /**
81 * Print the text "Index" in strong format in the navigation bar.
82 */
83 protected void navLinkIndex() {
84 navCellRevStart();
85 fontStyle("NavBarFont1Rev");
86 strongText("doclet.Index");
87 fontEnd();
88 navCellEnd();
89 }
91 /**
92 * Generate the member information for the unicode character along with the
93 * list of the members.
94 *
95 * @param unicode Unicode for which member list information to be generated.
96 * @param memberlist List of members for the unicode character.
97 */
98 protected void generateContents(Character unicode, List<? extends Doc> memberlist) {
99 anchor("_" + unicode + "_");
100 h2();
101 strong(unicode.toString());
102 h2End();
103 int memberListSize = memberlist.size();
104 // Display the list only if there are elements to be displayed.
105 if (memberListSize > 0) {
106 dl();
107 for (int i = 0; i < memberListSize; i++) {
108 Doc element = memberlist.get(i);
109 if (element instanceof MemberDoc) {
110 printDescription((MemberDoc)element);
111 } else if (element instanceof ClassDoc) {
112 printDescription((ClassDoc)element);
113 } else if (element instanceof PackageDoc) {
114 printDescription((PackageDoc)element);
115 }
116 }
117 dlEnd();
118 }
119 hr();
120 }
123 /**
124 * Print one line summary comment for the package.
125 *
126 * @param pkg PackageDoc passed.
127 */
128 protected void printDescription(PackageDoc pkg) {
129 dt();
130 printPackageLink(pkg, Util.getPackageName(pkg), true);
131 print(" - ");
132 print(configuration.getText("doclet.package") + " " + pkg.name());
133 dtEnd();
134 dd();
135 printSummaryComment(pkg);
136 ddEnd();
137 }
139 /**
140 * Print one line summary comment for the class.
141 *
142 * @param cd ClassDoc passed.
143 */
144 protected void printDescription(ClassDoc cd) {
145 dt();
146 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true));
147 print(" - ");
148 printClassInfo(cd);
149 dtEnd();
150 dd();
151 printComment(cd);
152 ddEnd();
153 }
155 /**
156 * Print the classkind(class, interface, exception, error of the class
157 * passed.
158 *
159 * @param cd ClassDoc.
160 */
161 protected void printClassInfo(ClassDoc cd) {
162 print(configuration.getText("doclet.in",
163 Util.getTypeName(configuration, cd, false),
164 getPackageLink(cd.containingPackage(),
165 Util.getPackageName(cd.containingPackage()), false)));
166 }
169 /**
170 * Generate Description for Class, Field, Method or Constructor.
171 * for Java.* Packages Class Members.
172 *
173 * @param member MemberDoc for the member of the Class Kind.
174 * @see com.sun.javadoc.MemberDoc
175 */
176 protected void printDescription(MemberDoc member) {
177 String name = (member instanceof ExecutableMemberDoc)?
178 member.name() + ((ExecutableMemberDoc)member).flatSignature() :
179 member.name();
180 if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
181 name = Util.escapeHtmlChars(name);
182 }
183 ClassDoc containing = member.containingClass();
184 dt();
185 printDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name, true);
186 println(" - ");
187 printMemberDesc(member);
188 println();
189 dtEnd();
190 dd();
191 printComment(member);
192 ddEnd();
193 println();
194 }
197 /**
198 * Print comment for each element in the index. If the element is deprecated
199 * and it has a @deprecated tag, use that comment. Else if the containing
200 * class for this element is deprecated, then add the word "Deprecated." at
201 * the start and then print the normal comment.
202 *
203 * @param element Index element.
204 */
205 protected void printComment(ProgramElementDoc element) {
206 Tag[] tags;
207 if (Util.isDeprecated(element)) {
208 strongText("doclet.Deprecated"); space();
209 if ((tags = element.tags("deprecated")).length > 0)
210 printInlineDeprecatedComment(element, tags[0]);
211 } else {
212 ClassDoc cont = element.containingClass();
213 while (cont != null) {
214 if (Util.isDeprecated(cont)) {
215 strongText("doclet.Deprecated"); space();
216 break;
217 }
218 cont = cont.containingClass();
219 }
220 printSummaryComment(element);
221 }
222 }
224 /**
225 * Print description about the Static Varible/Method/Constructor for a
226 * member.
227 *
228 * @param member MemberDoc for the member within the Class Kind.
229 * @see com.sun.javadoc.MemberDoc
230 */
231 protected void printMemberDesc(MemberDoc member) {
232 ClassDoc containing = member.containingClass();
233 String classdesc = Util.getTypeName(configuration, containing, true) + " " +
234 getPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
235 false);
236 if (member.isField()) {
237 if (member.isStatic()) {
238 printText("doclet.Static_variable_in", classdesc);
239 } else {
240 printText("doclet.Variable_in", classdesc);
241 }
242 } else if (member.isConstructor()) {
243 printText("doclet.Constructor_for", classdesc);
244 } else if (member.isMethod()) {
245 if (member.isStatic()) {
246 printText("doclet.Static_method_in", classdesc);
247 } else {
248 printText("doclet.Method_in", classdesc);
249 }
250 }
251 }
252 }