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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2147
130b8c0e570e
parent 0
959103a6100f
child 2893
ca5783d9a597
permissions
-rw-r--r--

merge

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

mercurial