1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 30 import com.sun.javadoc.*; 31 import com.sun.tools.doclets.formats.html.markup.*; 32 import com.sun.tools.doclets.internal.toolkit.*; 33 import com.sun.tools.doclets.internal.toolkit.util.*; 34 35 /** 36 * Writes field documentation in HTML format. 37 * 38 * <p><b>This is NOT part of any supported API. 39 * If you write code that depends on this, you do so at your own risk. 40 * This code and its internal interfaces are subject to change or 41 * deletion without notice.</b> 42 * 43 * @author Robert Field 44 * @author Atul M Dambalkar 45 * @author Jamie Ho (rewrite) 46 * @author Bhavesh Patel (Modified) 47 */ 48 public class FieldWriterImpl extends AbstractMemberWriter 49 implements FieldWriter, MemberSummaryWriter { 50 FieldWriterImpl(SubWriterHolderWriter writer, ClassDoc classdoc)51 public FieldWriterImpl(SubWriterHolderWriter writer, ClassDoc classdoc) { 52 super(writer, classdoc); 53 } 54 FieldWriterImpl(SubWriterHolderWriter writer)55 public FieldWriterImpl(SubWriterHolderWriter writer) { 56 super(writer); 57 } 58 59 /** 60 * {@inheritDoc} 61 */ getMemberSummaryHeader(ClassDoc classDoc, Content memberSummaryTree)62 public Content getMemberSummaryHeader(ClassDoc classDoc, 63 Content memberSummaryTree) { 64 memberSummaryTree.addContent(HtmlConstants.START_OF_FIELD_SUMMARY); 65 Content memberTree = writer.getMemberTreeHeader(); 66 writer.addSummaryHeader(this, classDoc, memberTree); 67 return memberTree; 68 } 69 70 /** 71 * {@inheritDoc} 72 */ getFieldDetailsTreeHeader(ClassDoc classDoc, Content memberDetailsTree)73 public Content getFieldDetailsTreeHeader(ClassDoc classDoc, 74 Content memberDetailsTree) { 75 memberDetailsTree.addContent(HtmlConstants.START_OF_FIELD_DETAILS); 76 Content fieldDetailsTree = writer.getMemberTreeHeader(); 77 fieldDetailsTree.addContent(writer.getMarkerAnchor( 78 SectionName.FIELD_DETAIL)); 79 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 80 writer.fieldDetailsLabel); 81 fieldDetailsTree.addContent(heading); 82 return fieldDetailsTree; 83 } 84 85 /** 86 * {@inheritDoc} 87 */ getFieldDocTreeHeader(FieldDoc field, Content fieldDetailsTree)88 public Content getFieldDocTreeHeader(FieldDoc field, 89 Content fieldDetailsTree) { 90 fieldDetailsTree.addContent( 91 writer.getMarkerAnchor(field.name())); 92 Content fieldDocTree = writer.getMemberTreeHeader(); 93 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 94 heading.addContent(field.name()); 95 fieldDocTree.addContent(heading); 96 return fieldDocTree; 97 } 98 99 /** 100 * {@inheritDoc} 101 */ getSignature(FieldDoc field)102 public Content getSignature(FieldDoc field) { 103 Content pre = new HtmlTree(HtmlTag.PRE); 104 writer.addAnnotationInfo(field, pre); 105 addModifiers(field, pre); 106 Content fieldlink = writer.getLink(new LinkInfoImpl( 107 configuration, LinkInfoImpl.Kind.MEMBER, field.type())); 108 pre.addContent(fieldlink); 109 pre.addContent(" "); 110 if (configuration.linksource) { 111 Content fieldName = new StringContent(field.name()); 112 writer.addSrcLink(field, fieldName, pre); 113 } else { 114 addName(field.name(), pre); 115 } 116 return pre; 117 } 118 119 /** 120 * {@inheritDoc} 121 */ addDeprecated(FieldDoc field, Content fieldDocTree)122 public void addDeprecated(FieldDoc field, Content fieldDocTree) { 123 addDeprecatedInfo(field, fieldDocTree); 124 } 125 126 /** 127 * {@inheritDoc} 128 */ addComments(FieldDoc field, Content fieldDocTree)129 public void addComments(FieldDoc field, Content fieldDocTree) { 130 ClassDoc holder = field.containingClass(); 131 if (field.inlineTags().length > 0) { 132 if (holder.equals(classdoc) || 133 (! (holder.isPublic() || Util.isLinkable(holder, configuration)))) { 134 writer.addInlineComment(field, fieldDocTree); 135 } else { 136 Content link = 137 writer.getDocLink(LinkInfoImpl.Kind.FIELD_DOC_COPY, 138 holder, field, 139 holder.isIncluded() ? 140 holder.typeName() : holder.qualifiedTypeName(), 141 false); 142 Content codeLink = HtmlTree.CODE(link); 143 Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel, holder.isClass()? 144 writer.descfrmClassLabel : writer.descfrmInterfaceLabel); 145 descfrmLabel.addContent(writer.getSpace()); 146 descfrmLabel.addContent(codeLink); 147 fieldDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel)); 148 writer.addInlineComment(field, fieldDocTree); 149 } 150 } 151 } 152 153 /** 154 * {@inheritDoc} 155 */ addTags(FieldDoc field, Content fieldDocTree)156 public void addTags(FieldDoc field, Content fieldDocTree) { 157 writer.addTagsInfo(field, fieldDocTree); 158 } 159 160 /** 161 * {@inheritDoc} 162 */ getFieldDetails(Content fieldDetailsTree)163 public Content getFieldDetails(Content fieldDetailsTree) { 164 return getMemberTree(fieldDetailsTree); 165 } 166 167 /** 168 * {@inheritDoc} 169 */ getFieldDoc(Content fieldDocTree, boolean isLastContent)170 public Content getFieldDoc(Content fieldDocTree, 171 boolean isLastContent) { 172 return getMemberTree(fieldDocTree, isLastContent); 173 } 174 175 /** 176 * Close the writer. 177 */ close()178 public void close() throws IOException { 179 writer.close(); 180 } 181 getMemberKind()182 public int getMemberKind() { 183 return VisibleMemberMap.FIELDS; 184 } 185 186 /** 187 * {@inheritDoc} 188 */ addSummaryLabel(Content memberTree)189 public void addSummaryLabel(Content memberTree) { 190 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 191 writer.getResource("doclet.Field_Summary")); 192 memberTree.addContent(label); 193 } 194 195 /** 196 * {@inheritDoc} 197 */ getTableSummary()198 public String getTableSummary() { 199 return configuration.getText("doclet.Member_Table_Summary", 200 configuration.getText("doclet.Field_Summary"), 201 configuration.getText("doclet.fields")); 202 } 203 204 /** 205 * {@inheritDoc} 206 */ getCaption()207 public Content getCaption() { 208 return configuration.getResource("doclet.Fields"); 209 } 210 211 /** 212 * {@inheritDoc} 213 */ getSummaryTableHeader(ProgramElementDoc member)214 public String[] getSummaryTableHeader(ProgramElementDoc member) { 215 String[] header = new String[] { 216 writer.getModifierTypeHeader(), 217 configuration.getText("doclet.0_and_1", 218 configuration.getText("doclet.Field"), 219 configuration.getText("doclet.Description")) 220 }; 221 return header; 222 } 223 224 /** 225 * {@inheritDoc} 226 */ addSummaryAnchor(ClassDoc cd, Content memberTree)227 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 228 memberTree.addContent(writer.getMarkerAnchor( 229 SectionName.FIELD_SUMMARY)); 230 } 231 232 /** 233 * {@inheritDoc} 234 */ addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree)235 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 236 inheritedTree.addContent(writer.getMarkerAnchor( 237 SectionName.FIELDS_INHERITANCE, configuration.getClassName(cd))); 238 } 239 240 /** 241 * {@inheritDoc} 242 */ addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree)243 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 244 Content classLink = writer.getPreQualifiedClassLink( 245 LinkInfoImpl.Kind.MEMBER, cd, false); 246 Content label = new StringContent(cd.isClass() ? 247 configuration.getText("doclet.Fields_Inherited_From_Class") : 248 configuration.getText("doclet.Fields_Inherited_From_Interface")); 249 Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING, 250 label); 251 labelHeading.addContent(writer.getSpace()); 252 labelHeading.addContent(classLink); 253 inheritedTree.addContent(labelHeading); 254 } 255 256 /** 257 * {@inheritDoc} 258 */ addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, Content tdSummary)259 protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, 260 Content tdSummary) { 261 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 262 writer.getDocLink(context, cd , (MemberDoc) member, member.name(), false)); 263 Content code = HtmlTree.CODE(memberLink); 264 tdSummary.addContent(code); 265 } 266 267 /** 268 * {@inheritDoc} 269 */ addInheritedSummaryLink(ClassDoc cd, ProgramElementDoc member, Content linksTree)270 protected void addInheritedSummaryLink(ClassDoc cd, 271 ProgramElementDoc member, Content linksTree) { 272 linksTree.addContent( 273 writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc)member, 274 member.name(), false)); 275 } 276 277 /** 278 * {@inheritDoc} 279 */ addSummaryType(ProgramElementDoc member, Content tdSummaryType)280 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 281 FieldDoc field = (FieldDoc)member; 282 addModifierAndType(field, field.type(), tdSummaryType); 283 } 284 285 /** 286 * {@inheritDoc} 287 */ getDeprecatedLink(ProgramElementDoc member)288 protected Content getDeprecatedLink(ProgramElementDoc member) { 289 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 290 (MemberDoc) member, ((FieldDoc)member).qualifiedName()); 291 } 292 293 /** 294 * {@inheritDoc} 295 */ getNavSummaryLink(ClassDoc cd, boolean link)296 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 297 if (link) { 298 if (cd == null) { 299 return writer.getHyperLink( 300 SectionName.FIELD_SUMMARY, 301 writer.getResource("doclet.navField")); 302 } else { 303 return writer.getHyperLink( 304 SectionName.FIELDS_INHERITANCE, 305 configuration.getClassName(cd), writer.getResource("doclet.navField")); 306 } 307 } else { 308 return writer.getResource("doclet.navField"); 309 } 310 } 311 312 /** 313 * {@inheritDoc} 314 */ addNavDetailLink(boolean link, Content liNav)315 protected void addNavDetailLink(boolean link, Content liNav) { 316 if (link) { 317 liNav.addContent(writer.getHyperLink( 318 SectionName.FIELD_DETAIL, 319 writer.getResource("doclet.navField"))); 320 } else { 321 liNav.addContent(writer.getResource("doclet.navField")); 322 } 323 } 324 } 325