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