src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html;
aoqi@0 27
aoqi@0 28 import java.io.*;
aoqi@0 29 import java.util.*;
aoqi@0 30
aoqi@0 31 import com.sun.javadoc.*;
aoqi@0 32 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Write the Constants Summary Page in HTML format.
aoqi@0 38 *
aoqi@0 39 * <p><b>This is NOT part of any supported API.
aoqi@0 40 * If you write code that depends on this, you do so at your own risk.
aoqi@0 41 * This code and its internal interfaces are subject to change or
aoqi@0 42 * deletion without notice.</b>
aoqi@0 43 *
aoqi@0 44 * @author Jamie Ho
aoqi@0 45 * @author Bhavesh Patel (Modified)
aoqi@0 46 * @since 1.4
aoqi@0 47 */
aoqi@0 48 public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
aoqi@0 49 implements ConstantsSummaryWriter {
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * The configuration used in this run of the standard doclet.
aoqi@0 53 */
aoqi@0 54 ConfigurationImpl configuration;
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * The current class being documented.
aoqi@0 58 */
aoqi@0 59 private ClassDoc currentClassDoc;
aoqi@0 60
aoqi@0 61 private final String constantsTableSummary;
aoqi@0 62
aoqi@0 63 private final String[] constantsTableHeader;
aoqi@0 64
aoqi@0 65 /**
aoqi@0 66 * Construct a ConstantsSummaryWriter.
aoqi@0 67 * @param configuration the configuration used in this run
aoqi@0 68 * of the standard doclet.
aoqi@0 69 */
aoqi@0 70 public ConstantsSummaryWriterImpl(ConfigurationImpl configuration)
aoqi@0 71 throws IOException {
aoqi@0 72 super(configuration, DocPaths.CONSTANT_VALUES);
aoqi@0 73 this.configuration = configuration;
aoqi@0 74 constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary",
aoqi@0 75 configuration.getText("doclet.Constants_Summary"));
aoqi@0 76 constantsTableHeader = new String[] {
aoqi@0 77 getModifierTypeHeader(),
aoqi@0 78 configuration.getText("doclet.ConstantField"),
aoqi@0 79 configuration.getText("doclet.Value")
aoqi@0 80 };
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 /**
aoqi@0 84 * {@inheritDoc}
aoqi@0 85 */
aoqi@0 86 public Content getHeader() {
aoqi@0 87 String label = configuration.getText("doclet.Constants_Summary");
aoqi@0 88 Content bodyTree = getBody(true, getWindowTitle(label));
aoqi@0 89 addTop(bodyTree);
aoqi@0 90 addNavLinks(true, bodyTree);
aoqi@0 91 return bodyTree;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 /**
aoqi@0 95 * {@inheritDoc}
aoqi@0 96 */
aoqi@0 97 public Content getContentsHeader() {
aoqi@0 98 return new HtmlTree(HtmlTag.UL);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 /**
aoqi@0 102 * {@inheritDoc}
aoqi@0 103 */
aoqi@0 104 public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName,
aoqi@0 105 Set<String> printedPackageHeaders, Content contentListTree) {
aoqi@0 106 String packageName = pkg.name();
aoqi@0 107 //add link to summary
aoqi@0 108 Content link;
aoqi@0 109 if (packageName.length() == 0) {
aoqi@0 110 link = getHyperLink(getDocLink(
aoqi@0 111 SectionName.UNNAMED_PACKAGE_ANCHOR),
aoqi@0 112 defaultPackageLabel, "", "");
aoqi@0 113 } else {
aoqi@0 114 Content packageNameContent = getPackageLabel(parsedPackageName);
aoqi@0 115 packageNameContent.addContent(".*");
aoqi@0 116 link = getHyperLink(DocLink.fragment(parsedPackageName),
aoqi@0 117 packageNameContent, "", "");
aoqi@0 118 printedPackageHeaders.add(parsedPackageName);
aoqi@0 119 }
aoqi@0 120 contentListTree.addContent(HtmlTree.LI(link));
aoqi@0 121 }
aoqi@0 122
aoqi@0 123 /**
aoqi@0 124 * {@inheritDoc}
aoqi@0 125 */
aoqi@0 126 public Content getContentsList(Content contentListTree) {
aoqi@0 127 Content titleContent = getResource(
aoqi@0 128 "doclet.Constants_Summary");
aoqi@0 129 Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
aoqi@0 130 HtmlStyle.title, titleContent);
aoqi@0 131 Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
aoqi@0 132 Content headingContent = getResource(
aoqi@0 133 "doclet.Contents");
aoqi@0 134 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
aoqi@0 135 headingContent));
aoqi@0 136 div.addContent(contentListTree);
aoqi@0 137 return div;
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 /**
aoqi@0 141 * {@inheritDoc}
aoqi@0 142 */
aoqi@0 143 public Content getConstantSummaries() {
aoqi@0 144 HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV);
aoqi@0 145 summariesDiv.addStyle(HtmlStyle.constantValuesContainer);
aoqi@0 146 return summariesDiv;
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 /**
aoqi@0 150 * {@inheritDoc}
aoqi@0 151 */
aoqi@0 152 public void addPackageName(PackageDoc pkg, String parsedPackageName,
aoqi@0 153 Content summariesTree) {
aoqi@0 154 Content pkgNameContent;
aoqi@0 155 if (parsedPackageName.length() == 0) {
aoqi@0 156 summariesTree.addContent(getMarkerAnchor(
aoqi@0 157 SectionName.UNNAMED_PACKAGE_ANCHOR));
aoqi@0 158 pkgNameContent = defaultPackageLabel;
aoqi@0 159 } else {
aoqi@0 160 summariesTree.addContent(getMarkerAnchor(
aoqi@0 161 parsedPackageName));
aoqi@0 162 pkgNameContent = getPackageLabel(parsedPackageName);
aoqi@0 163 }
aoqi@0 164 Content headingContent = new StringContent(".*");
aoqi@0 165 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
aoqi@0 166 pkgNameContent);
aoqi@0 167 heading.addContent(headingContent);
aoqi@0 168 summariesTree.addContent(heading);
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 /**
aoqi@0 172 * {@inheritDoc}
aoqi@0 173 */
aoqi@0 174 public Content getClassConstantHeader() {
aoqi@0 175 HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0 176 ul.addStyle(HtmlStyle.blockList);
aoqi@0 177 return ul;
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 /**
aoqi@0 181 * Get the table caption and header for the constant summary table
aoqi@0 182 *
aoqi@0 183 * @param cd classdoc to be documented
aoqi@0 184 * @return constant members header content
aoqi@0 185 */
aoqi@0 186 public Content getConstantMembersHeader(ClassDoc cd) {
aoqi@0 187 //generate links backward only to public classes.
aoqi@0 188 Content classlink = (cd.isPublic() || cd.isProtected()) ?
aoqi@0 189 getLink(new LinkInfoImpl(configuration,
aoqi@0 190 LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)) :
aoqi@0 191 new StringContent(cd.qualifiedName());
aoqi@0 192 String name = cd.containingPackage().name();
aoqi@0 193 if (name.length() > 0) {
aoqi@0 194 Content cb = new ContentBuilder();
aoqi@0 195 cb.addContent(name);
aoqi@0 196 cb.addContent(".");
aoqi@0 197 cb.addContent(classlink);
aoqi@0 198 return getClassName(cb);
aoqi@0 199 } else {
aoqi@0 200 return getClassName(classlink);
aoqi@0 201 }
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 /**
aoqi@0 205 * Get the class name in the table caption and the table header.
aoqi@0 206 *
aoqi@0 207 * @param classStr the class name to print.
aoqi@0 208 * @return the table caption and header
aoqi@0 209 */
aoqi@0 210 protected Content getClassName(Content classStr) {
aoqi@0 211 Content table = HtmlTree.TABLE(HtmlStyle.constantsSummary, 0, 3, 0, constantsTableSummary,
aoqi@0 212 getTableCaption(classStr));
aoqi@0 213 table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
aoqi@0 214 return table;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 /**
aoqi@0 218 * {@inheritDoc}
aoqi@0 219 */
aoqi@0 220 public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields,
aoqi@0 221 Content classConstantTree) {
aoqi@0 222 currentClassDoc = cd;
aoqi@0 223 Content tbody = new HtmlTree(HtmlTag.TBODY);
aoqi@0 224 for (int i = 0; i < fields.size(); ++i) {
aoqi@0 225 HtmlTree tr = new HtmlTree(HtmlTag.TR);
aoqi@0 226 if (i%2 == 0)
aoqi@0 227 tr.addStyle(HtmlStyle.altColor);
aoqi@0 228 else
aoqi@0 229 tr.addStyle(HtmlStyle.rowColor);
aoqi@0 230 addConstantMember(fields.get(i), tr);
aoqi@0 231 tbody.addContent(tr);
aoqi@0 232 }
aoqi@0 233 Content table = getConstantMembersHeader(cd);
aoqi@0 234 table.addContent(tbody);
aoqi@0 235 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
aoqi@0 236 classConstantTree.addContent(li);
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 /**
aoqi@0 240 * Add the row for the constant summary table.
aoqi@0 241 *
aoqi@0 242 * @param member the field to be documented.
aoqi@0 243 * @param trTree an htmltree object for the table row
aoqi@0 244 */
aoqi@0 245 private void addConstantMember(FieldDoc member, HtmlTree trTree) {
aoqi@0 246 trTree.addContent(getTypeColumn(member));
aoqi@0 247 trTree.addContent(getNameColumn(member));
aoqi@0 248 trTree.addContent(getValue(member));
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 /**
aoqi@0 252 * Get the type column for the constant summary table row.
aoqi@0 253 *
aoqi@0 254 * @param member the field to be documented.
aoqi@0 255 * @return the type column of the constant table row
aoqi@0 256 */
aoqi@0 257 private Content getTypeColumn(FieldDoc member) {
aoqi@0 258 Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() +
aoqi@0 259 "." + member.name());
aoqi@0 260 Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor);
aoqi@0 261 Content code = new HtmlTree(HtmlTag.CODE);
aoqi@0 262 StringTokenizer mods = new StringTokenizer(member.modifiers());
aoqi@0 263 while(mods.hasMoreTokens()) {
aoqi@0 264 Content modifier = new StringContent(mods.nextToken());
aoqi@0 265 code.addContent(modifier);
aoqi@0 266 code.addContent(getSpace());
aoqi@0 267 }
aoqi@0 268 Content type = getLink(new LinkInfoImpl(configuration,
aoqi@0 269 LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type()));
aoqi@0 270 code.addContent(type);
aoqi@0 271 tdType.addContent(code);
aoqi@0 272 return tdType;
aoqi@0 273 }
aoqi@0 274
aoqi@0 275 /**
aoqi@0 276 * Get the name column for the constant summary table row.
aoqi@0 277 *
aoqi@0 278 * @param member the field to be documented.
aoqi@0 279 * @return the name column of the constant table row
aoqi@0 280 */
aoqi@0 281 private Content getNameColumn(FieldDoc member) {
aoqi@0 282 Content nameContent = getDocLink(
aoqi@0 283 LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false);
aoqi@0 284 Content code = HtmlTree.CODE(nameContent);
aoqi@0 285 return HtmlTree.TD(code);
aoqi@0 286 }
aoqi@0 287
aoqi@0 288 /**
aoqi@0 289 * Get the value column for the constant summary table row.
aoqi@0 290 *
aoqi@0 291 * @param member the field to be documented.
aoqi@0 292 * @return the value column of the constant table row
aoqi@0 293 */
aoqi@0 294 private Content getValue(FieldDoc member) {
aoqi@0 295 Content valueContent = new StringContent(member.constantValueExpression());
aoqi@0 296 Content code = HtmlTree.CODE(valueContent);
aoqi@0 297 return HtmlTree.TD(HtmlStyle.colLast, code);
aoqi@0 298 }
aoqi@0 299
aoqi@0 300 /**
aoqi@0 301 * {@inheritDoc}
aoqi@0 302 */
aoqi@0 303 public void addFooter(Content contentTree) {
aoqi@0 304 addNavLinks(false, contentTree);
aoqi@0 305 addBottom(contentTree);
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 /**
aoqi@0 309 * {@inheritDoc}
aoqi@0 310 */
aoqi@0 311 public void printDocument(Content contentTree) throws IOException {
aoqi@0 312 printHtmlDocument(null, true, contentTree);
aoqi@0 313 }
aoqi@0 314 }

mercurial