1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,324 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import java.io.*; 1.32 + 1.33 +import com.sun.javadoc.*; 1.34 +import com.sun.tools.doclets.formats.html.markup.*; 1.35 +import com.sun.tools.doclets.internal.toolkit.*; 1.36 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.37 + 1.38 +/** 1.39 + * Writes field documentation in HTML format. 1.40 + * 1.41 + * <p><b>This is NOT part of any supported API. 1.42 + * If you write code that depends on this, you do so at your own risk. 1.43 + * This code and its internal interfaces are subject to change or 1.44 + * deletion without notice.</b> 1.45 + * 1.46 + * @author Robert Field 1.47 + * @author Atul M Dambalkar 1.48 + * @author Jamie Ho (rewrite) 1.49 + * @author Bhavesh Patel (Modified) 1.50 + */ 1.51 +public class FieldWriterImpl extends AbstractMemberWriter 1.52 + implements FieldWriter, MemberSummaryWriter { 1.53 + 1.54 + public FieldWriterImpl(SubWriterHolderWriter writer, ClassDoc classdoc) { 1.55 + super(writer, classdoc); 1.56 + } 1.57 + 1.58 + public FieldWriterImpl(SubWriterHolderWriter writer) { 1.59 + super(writer); 1.60 + } 1.61 + 1.62 + /** 1.63 + * {@inheritDoc} 1.64 + */ 1.65 + public Content getMemberSummaryHeader(ClassDoc classDoc, 1.66 + Content memberSummaryTree) { 1.67 + memberSummaryTree.addContent(HtmlConstants.START_OF_FIELD_SUMMARY); 1.68 + Content memberTree = writer.getMemberTreeHeader(); 1.69 + writer.addSummaryHeader(this, classDoc, memberTree); 1.70 + return memberTree; 1.71 + } 1.72 + 1.73 + /** 1.74 + * {@inheritDoc} 1.75 + */ 1.76 + public Content getFieldDetailsTreeHeader(ClassDoc classDoc, 1.77 + Content memberDetailsTree) { 1.78 + memberDetailsTree.addContent(HtmlConstants.START_OF_FIELD_DETAILS); 1.79 + Content fieldDetailsTree = writer.getMemberTreeHeader(); 1.80 + fieldDetailsTree.addContent(writer.getMarkerAnchor( 1.81 + SectionName.FIELD_DETAIL)); 1.82 + Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 1.83 + writer.fieldDetailsLabel); 1.84 + fieldDetailsTree.addContent(heading); 1.85 + return fieldDetailsTree; 1.86 + } 1.87 + 1.88 + /** 1.89 + * {@inheritDoc} 1.90 + */ 1.91 + public Content getFieldDocTreeHeader(FieldDoc field, 1.92 + Content fieldDetailsTree) { 1.93 + fieldDetailsTree.addContent( 1.94 + writer.getMarkerAnchor(field.name())); 1.95 + Content fieldDocTree = writer.getMemberTreeHeader(); 1.96 + Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 1.97 + heading.addContent(field.name()); 1.98 + fieldDocTree.addContent(heading); 1.99 + return fieldDocTree; 1.100 + } 1.101 + 1.102 + /** 1.103 + * {@inheritDoc} 1.104 + */ 1.105 + public Content getSignature(FieldDoc field) { 1.106 + Content pre = new HtmlTree(HtmlTag.PRE); 1.107 + writer.addAnnotationInfo(field, pre); 1.108 + addModifiers(field, pre); 1.109 + Content fieldlink = writer.getLink(new LinkInfoImpl( 1.110 + configuration, LinkInfoImpl.Kind.MEMBER, field.type())); 1.111 + pre.addContent(fieldlink); 1.112 + pre.addContent(" "); 1.113 + if (configuration.linksource) { 1.114 + Content fieldName = new StringContent(field.name()); 1.115 + writer.addSrcLink(field, fieldName, pre); 1.116 + } else { 1.117 + addName(field.name(), pre); 1.118 + } 1.119 + return pre; 1.120 + } 1.121 + 1.122 + /** 1.123 + * {@inheritDoc} 1.124 + */ 1.125 + public void addDeprecated(FieldDoc field, Content fieldDocTree) { 1.126 + addDeprecatedInfo(field, fieldDocTree); 1.127 + } 1.128 + 1.129 + /** 1.130 + * {@inheritDoc} 1.131 + */ 1.132 + public void addComments(FieldDoc field, Content fieldDocTree) { 1.133 + ClassDoc holder = field.containingClass(); 1.134 + if (field.inlineTags().length > 0) { 1.135 + if (holder.equals(classdoc) || 1.136 + (! (holder.isPublic() || Util.isLinkable(holder, configuration)))) { 1.137 + writer.addInlineComment(field, fieldDocTree); 1.138 + } else { 1.139 + Content link = 1.140 + writer.getDocLink(LinkInfoImpl.Kind.FIELD_DOC_COPY, 1.141 + holder, field, 1.142 + holder.isIncluded() ? 1.143 + holder.typeName() : holder.qualifiedTypeName(), 1.144 + false); 1.145 + Content codeLink = HtmlTree.CODE(link); 1.146 + Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel, holder.isClass()? 1.147 + writer.descfrmClassLabel : writer.descfrmInterfaceLabel); 1.148 + descfrmLabel.addContent(writer.getSpace()); 1.149 + descfrmLabel.addContent(codeLink); 1.150 + fieldDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel)); 1.151 + writer.addInlineComment(field, fieldDocTree); 1.152 + } 1.153 + } 1.154 + } 1.155 + 1.156 + /** 1.157 + * {@inheritDoc} 1.158 + */ 1.159 + public void addTags(FieldDoc field, Content fieldDocTree) { 1.160 + writer.addTagsInfo(field, fieldDocTree); 1.161 + } 1.162 + 1.163 + /** 1.164 + * {@inheritDoc} 1.165 + */ 1.166 + public Content getFieldDetails(Content fieldDetailsTree) { 1.167 + return getMemberTree(fieldDetailsTree); 1.168 + } 1.169 + 1.170 + /** 1.171 + * {@inheritDoc} 1.172 + */ 1.173 + public Content getFieldDoc(Content fieldDocTree, 1.174 + boolean isLastContent) { 1.175 + return getMemberTree(fieldDocTree, isLastContent); 1.176 + } 1.177 + 1.178 + /** 1.179 + * Close the writer. 1.180 + */ 1.181 + public void close() throws IOException { 1.182 + writer.close(); 1.183 + } 1.184 + 1.185 + public int getMemberKind() { 1.186 + return VisibleMemberMap.FIELDS; 1.187 + } 1.188 + 1.189 + /** 1.190 + * {@inheritDoc} 1.191 + */ 1.192 + public void addSummaryLabel(Content memberTree) { 1.193 + Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 1.194 + writer.getResource("doclet.Field_Summary")); 1.195 + memberTree.addContent(label); 1.196 + } 1.197 + 1.198 + /** 1.199 + * {@inheritDoc} 1.200 + */ 1.201 + public String getTableSummary() { 1.202 + return configuration.getText("doclet.Member_Table_Summary", 1.203 + configuration.getText("doclet.Field_Summary"), 1.204 + configuration.getText("doclet.fields")); 1.205 + } 1.206 + 1.207 + /** 1.208 + * {@inheritDoc} 1.209 + */ 1.210 + public Content getCaption() { 1.211 + return configuration.getResource("doclet.Fields"); 1.212 + } 1.213 + 1.214 + /** 1.215 + * {@inheritDoc} 1.216 + */ 1.217 + public String[] getSummaryTableHeader(ProgramElementDoc member) { 1.218 + String[] header = new String[] { 1.219 + writer.getModifierTypeHeader(), 1.220 + configuration.getText("doclet.0_and_1", 1.221 + configuration.getText("doclet.Field"), 1.222 + configuration.getText("doclet.Description")) 1.223 + }; 1.224 + return header; 1.225 + } 1.226 + 1.227 + /** 1.228 + * {@inheritDoc} 1.229 + */ 1.230 + public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 1.231 + memberTree.addContent(writer.getMarkerAnchor( 1.232 + SectionName.FIELD_SUMMARY)); 1.233 + } 1.234 + 1.235 + /** 1.236 + * {@inheritDoc} 1.237 + */ 1.238 + public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 1.239 + inheritedTree.addContent(writer.getMarkerAnchor( 1.240 + SectionName.FIELDS_INHERITANCE, configuration.getClassName(cd))); 1.241 + } 1.242 + 1.243 + /** 1.244 + * {@inheritDoc} 1.245 + */ 1.246 + public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 1.247 + Content classLink = writer.getPreQualifiedClassLink( 1.248 + LinkInfoImpl.Kind.MEMBER, cd, false); 1.249 + Content label = new StringContent(cd.isClass() ? 1.250 + configuration.getText("doclet.Fields_Inherited_From_Class") : 1.251 + configuration.getText("doclet.Fields_Inherited_From_Interface")); 1.252 + Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING, 1.253 + label); 1.254 + labelHeading.addContent(writer.getSpace()); 1.255 + labelHeading.addContent(classLink); 1.256 + inheritedTree.addContent(labelHeading); 1.257 + } 1.258 + 1.259 + /** 1.260 + * {@inheritDoc} 1.261 + */ 1.262 + protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, 1.263 + Content tdSummary) { 1.264 + Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 1.265 + writer.getDocLink(context, cd , (MemberDoc) member, member.name(), false)); 1.266 + Content code = HtmlTree.CODE(memberLink); 1.267 + tdSummary.addContent(code); 1.268 + } 1.269 + 1.270 + /** 1.271 + * {@inheritDoc} 1.272 + */ 1.273 + protected void addInheritedSummaryLink(ClassDoc cd, 1.274 + ProgramElementDoc member, Content linksTree) { 1.275 + linksTree.addContent( 1.276 + writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc)member, 1.277 + member.name(), false)); 1.278 + } 1.279 + 1.280 + /** 1.281 + * {@inheritDoc} 1.282 + */ 1.283 + protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 1.284 + FieldDoc field = (FieldDoc)member; 1.285 + addModifierAndType(field, field.type(), tdSummaryType); 1.286 + } 1.287 + 1.288 + /** 1.289 + * {@inheritDoc} 1.290 + */ 1.291 + protected Content getDeprecatedLink(ProgramElementDoc member) { 1.292 + return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 1.293 + (MemberDoc) member, ((FieldDoc)member).qualifiedName()); 1.294 + } 1.295 + 1.296 + /** 1.297 + * {@inheritDoc} 1.298 + */ 1.299 + protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 1.300 + if (link) { 1.301 + if (cd == null) { 1.302 + return writer.getHyperLink( 1.303 + SectionName.FIELD_SUMMARY, 1.304 + writer.getResource("doclet.navField")); 1.305 + } else { 1.306 + return writer.getHyperLink( 1.307 + SectionName.FIELDS_INHERITANCE, 1.308 + configuration.getClassName(cd), writer.getResource("doclet.navField")); 1.309 + } 1.310 + } else { 1.311 + return writer.getResource("doclet.navField"); 1.312 + } 1.313 + } 1.314 + 1.315 + /** 1.316 + * {@inheritDoc} 1.317 + */ 1.318 + protected void addNavDetailLink(boolean link, Content liNav) { 1.319 + if (link) { 1.320 + liNav.addContent(writer.getHyperLink( 1.321 + SectionName.FIELD_DETAIL, 1.322 + writer.getResource("doclet.navField"))); 1.323 + } else { 1.324 + liNav.addContent(writer.getResource("doclet.navField")); 1.325 + } 1.326 + } 1.327 +}