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

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1372
78962d89f283
child 1746
bd51ca92c013
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

duke@1 1 /*
jjg@1357 2 * Copyright (c) 1997, 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@1417 29 import java.util.*;
jjg@1357 30
duke@1 31 import com.sun.javadoc.*;
jjg@1357 32 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@766 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 * This abstract class exists to provide functionality needed in the
duke@1 38 * the formatting of member information. Since AbstractSubWriter and its
duke@1 39 * subclasses control this, they would be the logical place to put this.
duke@1 40 * However, because each member type has its own subclass, subclassing
duke@1 41 * can not be used effectively to change formatting. The concrete
duke@1 42 * class subclass of this class can be subclassed to change formatting.
duke@1 43 *
jjg@1359 44 * <p><b>This is NOT part of any supported API.
jjg@1359 45 * If you write code that depends on this, you do so at your own risk.
jjg@1359 46 * This code and its internal interfaces are subject to change or
jjg@1359 47 * deletion without notice.</b>
jjg@1359 48 *
duke@1 49 * @see AbstractMemberWriter
duke@1 50 * @see ClassWriterImpl
duke@1 51 *
duke@1 52 * @author Robert Field
duke@1 53 * @author Atul M Dambalkar
bpatel@243 54 * @author Bhavesh Patel (Modified)
duke@1 55 */
duke@1 56 public abstract class SubWriterHolderWriter extends HtmlDocletWriter {
duke@1 57
jjg@1372 58 public SubWriterHolderWriter(ConfigurationImpl configuration, DocPath filename)
jjg@1372 59 throws IOException {
duke@1 60 super(configuration, filename);
duke@1 61 }
duke@1 62
bpatel@766 63 /**
bpatel@766 64 * Add the summary header.
bpatel@766 65 *
bpatel@766 66 * @param mw the writer for the member being documented
bpatel@766 67 * @param cd the classdoc to be documented
bpatel@766 68 * @param memberTree the content tree to which the summary header will be added
bpatel@766 69 */
bpatel@766 70 public void addSummaryHeader(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766 71 Content memberTree) {
bpatel@766 72 mw.addSummaryAnchor(cd, memberTree);
bpatel@766 73 mw.addSummaryLabel(memberTree);
bpatel@766 74 }
bpatel@766 75
bpatel@766 76 /**
bpatel@766 77 * Get the summary table.
bpatel@766 78 *
bpatel@766 79 * @param mw the writer for the member being documented
bpatel@766 80 * @param cd the classdoc to be documented
bpatel@1417 81 * @param tableContents list of summary table contents
bpatel@1417 82 * @param showTabs true if the table needs to show tabs
bpatel@766 83 * @return the content tree for the summary table
bpatel@766 84 */
bpatel@1417 85 public Content getSummaryTableTree(AbstractMemberWriter mw, ClassDoc cd,
bpatel@1417 86 List<Content> tableContents, boolean showTabs) {
bpatel@1417 87 Content caption;
bpatel@1417 88 if (showTabs) {
bpatel@1417 89 caption = getTableCaption(mw.methodTypes);
bpatel@1417 90 generateMethodTypesScript(mw.typeMap, mw.methodTypes);
bpatel@1417 91 }
bpatel@1417 92 else {
bpatel@1417 93 caption = getTableCaption(mw.getCaption());
bpatel@1417 94 }
bpatel@766 95 Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0,
bpatel@1417 96 mw.getTableSummary(), caption);
bpatel@766 97 table.addContent(getSummaryTableHeader(mw.getSummaryTableHeader(cd), "col"));
bpatel@1417 98 for (int i = 0; i < tableContents.size(); i++) {
bpatel@1417 99 table.addContent(tableContents.get(i));
bpatel@1417 100 }
bpatel@766 101 return table;
duke@1 102 }
duke@1 103
bpatel@766 104 /**
bpatel@1417 105 * Get the summary table caption.
bpatel@1417 106 *
bpatel@1417 107 * @param methodTypes set comprising of method types to show as table caption
bpatel@1417 108 * @return the caption for the summary table
bpatel@1417 109 */
bpatel@1417 110 public Content getTableCaption(Set<MethodTypes> methodTypes) {
bpatel@1417 111 Content tabbedCaption = new HtmlTree(HtmlTag.CAPTION);
bpatel@1417 112 for (MethodTypes type : methodTypes) {
bpatel@1417 113 Content captionSpan;
bpatel@1417 114 Content span;
bpatel@1417 115 if (type.isDefaultTab()) {
bpatel@1417 116 captionSpan = HtmlTree.SPAN(new StringContent(type.text()));
bpatel@1417 117 span = HtmlTree.SPAN(type.tabId(),
bpatel@1417 118 HtmlStyle.activeTableTab, captionSpan);
bpatel@1417 119 } else {
bpatel@1417 120 captionSpan = HtmlTree.SPAN(getMethodTypeLinks(type));
bpatel@1417 121 span = HtmlTree.SPAN(type.tabId(),
bpatel@1417 122 HtmlStyle.tableTab, captionSpan);
bpatel@1417 123 }
bpatel@1417 124 Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, getSpace());
bpatel@1417 125 span.addContent(tabSpan);
bpatel@1417 126 tabbedCaption.addContent(span);
bpatel@1417 127 }
bpatel@1417 128 return tabbedCaption;
bpatel@1417 129 }
bpatel@1417 130
bpatel@1417 131 /**
bpatel@1417 132 * Get the method type links for the table caption.
bpatel@1417 133 *
bpatel@1417 134 * @param methodType the method type to be displayed as link
bpatel@1417 135 * @return the content tree for the method type link
bpatel@1417 136 */
bpatel@1417 137 public Content getMethodTypeLinks(MethodTypes methodType) {
bpatel@1417 138 StringBuilder jsShow = new StringBuilder("javascript:show(");
bpatel@1417 139 jsShow.append(methodType.value()).append(");");
bpatel@1417 140 HtmlTree link = HtmlTree.A(jsShow.toString(),
bpatel@1417 141 new StringContent(methodType.text()));
bpatel@1417 142 return link;
bpatel@1417 143 }
bpatel@1417 144
bpatel@1417 145 /**
bpatel@766 146 * Add the inherited summary header.
bpatel@766 147 *
bpatel@766 148 * @param mw the writer for the member being documented
bpatel@766 149 * @param cd the classdoc to be documented
bpatel@766 150 * @param inheritedTree the content tree to which the inherited summary header will be added
bpatel@766 151 */
bpatel@766 152 public void addInheritedSummaryHeader(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766 153 Content inheritedTree) {
bpatel@766 154 mw.addInheritedSummaryAnchor(cd, inheritedTree);
bpatel@766 155 mw.addInheritedSummaryLabel(cd, inheritedTree);
duke@1 156 }
duke@1 157
bpatel@766 158 /**
bpatel@766 159 * Add the index comment.
bpatel@766 160 *
bpatel@766 161 * @param member the member being documented
bpatel@766 162 * @param contentTree the content tree to which the comment will be added
bpatel@766 163 */
bpatel@766 164 protected void addIndexComment(Doc member, Content contentTree) {
bpatel@766 165 addIndexComment(member, member.firstSentenceTags(), contentTree);
duke@1 166 }
duke@1 167
bpatel@766 168 /**
bpatel@766 169 * Add the index comment.
bpatel@766 170 *
bpatel@766 171 * @param member the member being documented
bpatel@766 172 * @param firstSentenceTags the first sentence tags for the member to be documented
bpatel@766 173 * @param tdSummary the content tree to which the comment will be added
bpatel@766 174 */
bpatel@766 175 protected void addIndexComment(Doc member, Tag[] firstSentenceTags,
bpatel@766 176 Content tdSummary) {
bpatel@766 177 Tag[] deprs = member.tags("deprecated");
bpatel@766 178 Content div;
bpatel@766 179 if (Util.isDeprecated((ProgramElementDoc) member)) {
bpatel@766 180 Content strong = HtmlTree.STRONG(deprecatedPhrase);
bpatel@766 181 div = HtmlTree.DIV(HtmlStyle.block, strong);
bpatel@766 182 div.addContent(getSpace());
bpatel@766 183 if (deprs.length > 0) {
bpatel@766 184 addInlineDeprecatedComment(member, deprs[0], div);
bpatel@766 185 }
bpatel@766 186 tdSummary.addContent(div);
bpatel@766 187 return;
bpatel@766 188 } else {
bpatel@766 189 ClassDoc cd = ((ProgramElementDoc)member).containingClass();
bpatel@766 190 if (cd != null && Util.isDeprecated(cd)) {
bpatel@766 191 Content strong = HtmlTree.STRONG(deprecatedPhrase);
bpatel@766 192 div = HtmlTree.DIV(HtmlStyle.block, strong);
bpatel@766 193 div.addContent(getSpace());
bpatel@766 194 tdSummary.addContent(div);
bpatel@766 195 }
bpatel@766 196 }
bpatel@766 197 addSummaryComment(member, firstSentenceTags, tdSummary);
duke@1 198 }
duke@1 199
bpatel@766 200 /**
bpatel@766 201 * Add the summary type for the member.
bpatel@766 202 *
bpatel@766 203 * @param mw the writer for the member being documented
bpatel@766 204 * @param member the member to be documented
bpatel@766 205 * @param tdSummaryType the content tree to which the type will be added
bpatel@766 206 */
bpatel@766 207 public void addSummaryType(AbstractMemberWriter mw, ProgramElementDoc member,
bpatel@766 208 Content tdSummaryType) {
bpatel@766 209 mw.addSummaryType(member, tdSummaryType);
bpatel@766 210 }
bpatel@766 211
bpatel@766 212 /**
bpatel@766 213 * Add the summary link for the member.
bpatel@766 214 *
bpatel@766 215 * @param mw the writer for the member being documented
bpatel@766 216 * @param member the member to be documented
bpatel@766 217 * @param contentTree the content tree to which the link will be added
bpatel@766 218 */
bpatel@766 219 public void addSummaryLinkComment(AbstractMemberWriter mw,
bpatel@766 220 ProgramElementDoc member, Content contentTree) {
bpatel@766 221 addSummaryLinkComment(mw, member, member.firstSentenceTags(), contentTree);
duke@1 222 }
duke@1 223
bpatel@766 224 /**
bpatel@766 225 * Add the summary link comment.
bpatel@766 226 *
bpatel@766 227 * @param mw the writer for the member being documented
bpatel@766 228 * @param member the member being documented
bpatel@766 229 * @param firstSentenceTags the first sentence tags for the member to be documented
bpatel@766 230 * @param tdSummary the content tree to which the comment will be added
bpatel@766 231 */
bpatel@766 232 public void addSummaryLinkComment(AbstractMemberWriter mw,
bpatel@766 233 ProgramElementDoc member, Tag[] firstSentenceTags, Content tdSummary) {
bpatel@766 234 addIndexComment(member, firstSentenceTags, tdSummary);
bpatel@766 235 }
bpatel@766 236
bpatel@766 237 /**
bpatel@766 238 * Add the inherited member summary.
bpatel@766 239 *
bpatel@766 240 * @param mw the writer for the member being documented
bpatel@766 241 * @param cd the class being documented
bpatel@766 242 * @param member the member being documented
bpatel@766 243 * @param isFirst true if its the first link being documented
bpatel@766 244 * @param linksTree the content tree to which the summary will be added
bpatel@766 245 */
bpatel@766 246 public void addInheritedMemberSummary(AbstractMemberWriter mw, ClassDoc cd,
bpatel@766 247 ProgramElementDoc member, boolean isFirst, Content linksTree) {
duke@1 248 if (! isFirst) {
bpatel@766 249 linksTree.addContent(", ");
duke@1 250 }
bpatel@766 251 mw.addInheritedSummaryLink(cd, member, linksTree);
duke@1 252 }
duke@1 253
bpatel@766 254 /**
bpatel@766 255 * Get the document content header tree
bpatel@766 256 *
bpatel@766 257 * @return a content tree the document content header
bpatel@766 258 */
bpatel@766 259 public Content getContentHeader() {
bpatel@766 260 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 261 div.addStyle(HtmlStyle.contentContainer);
bpatel@766 262 return div;
bpatel@766 263 }
bpatel@766 264
bpatel@766 265 /**
bpatel@766 266 * Get the member header tree
bpatel@766 267 *
bpatel@766 268 * @return a content tree the member header
bpatel@766 269 */
bpatel@766 270 public Content getMemberTreeHeader() {
bpatel@766 271 HtmlTree li = new HtmlTree(HtmlTag.LI);
bpatel@766 272 li.addStyle(HtmlStyle.blockList);
bpatel@766 273 return li;
bpatel@766 274 }
bpatel@766 275
bpatel@766 276 /**
bpatel@766 277 * Get the member tree
bpatel@766 278 *
bpatel@766 279 * @param contentTree the tree used to generate the complete member tree
bpatel@766 280 * @return a content tree for the member
bpatel@766 281 */
bpatel@766 282 public Content getMemberTree(Content contentTree) {
bpatel@766 283 Content ul = HtmlTree.UL(HtmlStyle.blockList, contentTree);
bpatel@766 284 return ul;
bpatel@766 285 }
bpatel@766 286
bpatel@766 287 /**
bpatel@766 288 * Get the member summary tree
bpatel@766 289 *
bpatel@766 290 * @param contentTree the tree used to generate the member summary tree
bpatel@766 291 * @return a content tree for the member summary
bpatel@766 292 */
bpatel@766 293 public Content getMemberSummaryTree(Content contentTree) {
bpatel@766 294 return getMemberTree(HtmlStyle.summary, contentTree);
bpatel@766 295 }
bpatel@766 296
bpatel@766 297 /**
bpatel@766 298 * Get the member details tree
bpatel@766 299 *
bpatel@766 300 * @param contentTree the tree used to generate the member details tree
bpatel@766 301 * @return a content tree for the member details
bpatel@766 302 */
bpatel@766 303 public Content getMemberDetailsTree(Content contentTree) {
bpatel@766 304 return getMemberTree(HtmlStyle.details, contentTree);
bpatel@766 305 }
bpatel@766 306
bpatel@766 307 /**
bpatel@766 308 * Get the member tree
bpatel@766 309 *
bpatel@766 310 * @param style the style class to be added to the content tree
bpatel@766 311 * @param contentTree the tree used to generate the complete member tree
bpatel@766 312 */
bpatel@766 313 public Content getMemberTree(HtmlStyle style, Content contentTree) {
bpatel@766 314 Content div = HtmlTree.DIV(style, getMemberTree(contentTree));
bpatel@766 315 return div;
bpatel@766 316 }
duke@1 317 }

mercurial