Thu, 29 Aug 2013 11:41:20 -0700
8001669: javadoc internal DocletAbortException should set cause when appropriate
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2001, 2013, 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 * Write the Constants Summary Page in HTML format.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 *
44 * @author Jamie Ho
45 * @author Bhavesh Patel (Modified)
46 * @since 1.4
47 */
48 public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
49 implements ConstantsSummaryWriter {
51 /**
52 * The configuration used in this run of the standard doclet.
53 */
54 ConfigurationImpl configuration;
56 /**
57 * The current class being documented.
58 */
59 private ClassDoc currentClassDoc;
61 private final String constantsTableSummary;
63 private final String[] constantsTableHeader;
65 /**
66 * Construct a ConstantsSummaryWriter.
67 * @param configuration the configuration used in this run
68 * of the standard doclet.
69 */
70 public ConstantsSummaryWriterImpl(ConfigurationImpl configuration)
71 throws IOException {
72 super(configuration, DocPaths.CONSTANT_VALUES);
73 this.configuration = configuration;
74 constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary",
75 configuration.getText("doclet.Constants_Summary"));
76 constantsTableHeader = new String[] {
77 getModifierTypeHeader(),
78 configuration.getText("doclet.ConstantField"),
79 configuration.getText("doclet.Value")
80 };
81 }
83 /**
84 * {@inheritDoc}
85 */
86 public Content getHeader() {
87 String label = configuration.getText("doclet.Constants_Summary");
88 Content bodyTree = getBody(true, getWindowTitle(label));
89 addTop(bodyTree);
90 addNavLinks(true, bodyTree);
91 return bodyTree;
92 }
94 /**
95 * {@inheritDoc}
96 */
97 public Content getContentsHeader() {
98 return new HtmlTree(HtmlTag.UL);
99 }
101 /**
102 * {@inheritDoc}
103 */
104 public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName,
105 Set<String> printedPackageHeaders, Content contentListTree) {
106 String packageName = pkg.name();
107 //add link to summary
108 Content link;
109 if (packageName.length() == 0) {
110 link = getHyperLink(DocLink.fragment(DocletConstants.UNNAMED_PACKAGE_ANCHOR),
111 defaultPackageLabel, "", "");
112 } else {
113 Content packageNameContent = getPackageLabel(parsedPackageName);
114 packageNameContent.addContent(".*");
115 link = getHyperLink(DocLink.fragment(parsedPackageName),
116 packageNameContent, "", "");
117 printedPackageHeaders.add(parsedPackageName);
118 }
119 contentListTree.addContent(HtmlTree.LI(link));
120 }
122 /**
123 * {@inheritDoc}
124 */
125 public Content getContentsList(Content contentListTree) {
126 Content titleContent = getResource(
127 "doclet.Constants_Summary");
128 Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
129 HtmlStyle.title, titleContent);
130 Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
131 Content headingContent = getResource(
132 "doclet.Contents");
133 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
134 headingContent));
135 div.addContent(contentListTree);
136 return div;
137 }
139 /**
140 * {@inheritDoc}
141 */
142 public Content getConstantSummaries() {
143 HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV);
144 summariesDiv.addStyle(HtmlStyle.constantValuesContainer);
145 return summariesDiv;
146 }
148 /**
149 * {@inheritDoc}
150 */
151 public void addPackageName(PackageDoc pkg, String parsedPackageName,
152 Content summariesTree) {
153 Content pkgNameContent;
154 if (parsedPackageName.length() == 0) {
155 summariesTree.addContent(getMarkerAnchor(
156 DocletConstants.UNNAMED_PACKAGE_ANCHOR));
157 pkgNameContent = defaultPackageLabel;
158 } else {
159 summariesTree.addContent(getMarkerAnchor(
160 parsedPackageName));
161 pkgNameContent = getPackageLabel(parsedPackageName);
162 }
163 Content headingContent = new StringContent(".*");
164 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
165 pkgNameContent);
166 heading.addContent(headingContent);
167 summariesTree.addContent(heading);
168 }
170 /**
171 * {@inheritDoc}
172 */
173 public Content getClassConstantHeader() {
174 HtmlTree ul = new HtmlTree(HtmlTag.UL);
175 ul.addStyle(HtmlStyle.blockList);
176 return ul;
177 }
179 /**
180 * Get the table caption and header for the constant summary table
181 *
182 * @param cd classdoc to be documented
183 * @return constant members header content
184 */
185 public Content getConstantMembersHeader(ClassDoc cd) {
186 //generate links backward only to public classes.
187 Content classlink = (cd.isPublic() || cd.isProtected()) ?
188 getLink(new LinkInfoImpl(configuration,
189 LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)) :
190 new StringContent(cd.qualifiedName());
191 String name = cd.containingPackage().name();
192 if (name.length() > 0) {
193 Content cb = new ContentBuilder();
194 cb.addContent(name);
195 cb.addContent(".");
196 cb.addContent(classlink);
197 return getClassName(cb);
198 } else {
199 return getClassName(classlink);
200 }
201 }
203 /**
204 * Get the class name in the table caption and the table header.
205 *
206 * @param classStr the class name to print.
207 * @return the table caption and header
208 */
209 protected Content getClassName(Content classStr) {
210 Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary,
211 getTableCaption(classStr));
212 table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
213 return table;
214 }
216 /**
217 * {@inheritDoc}
218 */
219 public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields,
220 Content classConstantTree) {
221 currentClassDoc = cd;
222 Content tbody = new HtmlTree(HtmlTag.TBODY);
223 for (int i = 0; i < fields.size(); ++i) {
224 HtmlTree tr = new HtmlTree(HtmlTag.TR);
225 if (i%2 == 0)
226 tr.addStyle(HtmlStyle.altColor);
227 else
228 tr.addStyle(HtmlStyle.rowColor);
229 addConstantMember(fields.get(i), tr);
230 tbody.addContent(tr);
231 }
232 Content table = getConstantMembersHeader(cd);
233 table.addContent(tbody);
234 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
235 classConstantTree.addContent(li);
236 }
238 /**
239 * Add the row for the constant summary table.
240 *
241 * @param member the field to be documented.
242 * @param trTree an htmltree object for the table row
243 */
244 private void addConstantMember(FieldDoc member, HtmlTree trTree) {
245 trTree.addContent(getTypeColumn(member));
246 trTree.addContent(getNameColumn(member));
247 trTree.addContent(getValue(member));
248 }
250 /**
251 * Get the type column for the constant summary table row.
252 *
253 * @param member the field to be documented.
254 * @return the type column of the constant table row
255 */
256 private Content getTypeColumn(FieldDoc member) {
257 Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() +
258 "." + member.name());
259 Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor);
260 Content code = new HtmlTree(HtmlTag.CODE);
261 StringTokenizer mods = new StringTokenizer(member.modifiers());
262 while(mods.hasMoreTokens()) {
263 Content modifier = new StringContent(mods.nextToken());
264 code.addContent(modifier);
265 code.addContent(getSpace());
266 }
267 Content type = getLink(new LinkInfoImpl(configuration,
268 LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type()));
269 code.addContent(type);
270 tdType.addContent(code);
271 return tdType;
272 }
274 /**
275 * Get the name column for the constant summary table row.
276 *
277 * @param member the field to be documented.
278 * @return the name column of the constant table row
279 */
280 private Content getNameColumn(FieldDoc member) {
281 Content nameContent = getDocLink(
282 LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false);
283 Content code = HtmlTree.CODE(nameContent);
284 return HtmlTree.TD(code);
285 }
287 /**
288 * Get the value column for the constant summary table row.
289 *
290 * @param member the field to be documented.
291 * @return the value column of the constant table row
292 */
293 private Content getValue(FieldDoc member) {
294 Content valueContent = new StringContent(member.constantValueExpression());
295 Content code = HtmlTree.CODE(valueContent);
296 return HtmlTree.TD(HtmlStyle.colLast, code);
297 }
299 /**
300 * {@inheritDoc}
301 */
302 public void addFooter(Content contentTree) {
303 addNavLinks(false, contentTree);
304 addBottom(contentTree);
305 }
307 /**
308 * {@inheritDoc}
309 */
310 public void printDocument(Content contentTree) throws IOException {
311 printHtmlDocument(null, true, contentTree);
312 }
313 }