1 /* 2 * Copyright (c) 2003, 2015, 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 enum constant 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 Jamie Ho 44 * @author Bhavesh Patel (Modified) 45 */ 46 public class EnumConstantWriterImpl extends AbstractMemberWriter 47 implements EnumConstantWriter, MemberSummaryWriter { 48 49 public EnumConstantWriterImpl(SubWriterHolderWriter writer, 50 ClassDoc classdoc) { 51 super(writer, classdoc); 52 } 53 54 public EnumConstantWriterImpl(SubWriterHolderWriter writer) { 55 super(writer); 56 } 57 58 /** 59 * {@inheritDoc} 60 */ 61 public Content getMemberSummaryHeader(ClassDoc classDoc, 62 Content memberSummaryTree) { 63 memberSummaryTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_SUMMARY); 64 Content memberTree = writer.getMemberTreeHeader(); 65 writer.addSummaryHeader(this, classDoc, memberTree); 66 return memberTree; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ 72 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 73 writer.addMemberTree(memberSummaryTree, memberTree); 74 } 75 76 /** 77 * {@inheritDoc} 78 */ 79 public Content getEnumConstantsDetailsTreeHeader(ClassDoc classDoc, 80 Content memberDetailsTree) { 81 memberDetailsTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_DETAILS); 82 Content enumConstantsDetailsTree = writer.getMemberTreeHeader(); 83 enumConstantsDetailsTree.addContent(writer.getMarkerAnchor( 84 SectionName.ENUM_CONSTANT_DETAIL)); 85 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 86 writer.enumConstantsDetailsLabel); 87 enumConstantsDetailsTree.addContent(heading); 88 return enumConstantsDetailsTree; 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 public Content getEnumConstantsTreeHeader(FieldDoc enumConstant, 95 Content enumConstantsDetailsTree) { 96 enumConstantsDetailsTree.addContent( 97 writer.getMarkerAnchor(enumConstant.name())); 98 Content enumConstantsTree = writer.getMemberTreeHeader(); 99 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 100 heading.addContent(enumConstant.name()); 101 enumConstantsTree.addContent(heading); 102 return enumConstantsTree; 103 } 104 105 /** 106 * {@inheritDoc} 107 */ 108 public Content getSignature(FieldDoc enumConstant) { 109 Content pre = new HtmlTree(HtmlTag.PRE); 110 writer.addAnnotationInfo(enumConstant, pre); 111 addModifiers(enumConstant, pre); 112 Content enumConstantLink = writer.getLink(new LinkInfoImpl( 113 configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.type())); 114 pre.addContent(enumConstantLink); 115 pre.addContent(" "); 116 if (configuration.linksource) { 117 Content enumConstantName = new StringContent(enumConstant.name()); 118 writer.addSrcLink(enumConstant, enumConstantName, pre); 119 } else { 120 addName(enumConstant.name(), pre); 121 } 122 return pre; 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 public void addDeprecated(FieldDoc enumConstant, Content enumConstantsTree) { 129 addDeprecatedInfo(enumConstant, enumConstantsTree); 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 public void addComments(FieldDoc enumConstant, Content enumConstantsTree) { 136 addComment(enumConstant, enumConstantsTree); 137 } 138 139 /** 140 * {@inheritDoc} 141 */ 142 public void addTags(FieldDoc enumConstant, Content enumConstantsTree) { 143 writer.addTagsInfo(enumConstant, enumConstantsTree); 144 } 145 146 /** 147 * {@inheritDoc} 148 */ 149 public Content getEnumConstantsDetails(Content enumConstantsDetailsTree) { 150 if (configuration.allowTag(HtmlTag.SECTION)) { 151 HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(enumConstantsDetailsTree)); 152 return htmlTree; 153 } 154 return getMemberTree(enumConstantsDetailsTree); 155 } 156 157 /** 158 * {@inheritDoc} 159 */ 160 public Content getEnumConstants(Content enumConstantsTree, 161 boolean isLastContent) { 162 return getMemberTree(enumConstantsTree, isLastContent); 163 } 164 165 /** 166 * {@inheritDoc} 167 */ 168 public void close() throws IOException { 169 writer.close(); 170 } 171 172 public int getMemberKind() { 173 return VisibleMemberMap.ENUM_CONSTANTS; 174 } 175 176 /** 177 * {@inheritDoc} 178 */ 179 public void addSummaryLabel(Content memberTree) { 180 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 181 writer.getResource("doclet.Enum_Constant_Summary")); 182 memberTree.addContent(label); 183 } 184 185 /** 186 * {@inheritDoc} 187 */ 188 public String getTableSummary() { 189 return configuration.getText("doclet.Member_Table_Summary", 190 configuration.getText("doclet.Enum_Constant_Summary"), 191 configuration.getText("doclet.enum_constants")); 192 } 193 194 /** 195 * {@inheritDoc} 196 */ 197 public Content getCaption() { 198 return configuration.getResource("doclet.Enum_Constants"); 199 } 200 201 /** 202 * {@inheritDoc} 203 */ 204 public String[] getSummaryTableHeader(ProgramElementDoc member) { 205 String[] header = new String[] { 206 configuration.getText("doclet.0_and_1", 207 configuration.getText("doclet.Enum_Constant"), 208 configuration.getText("doclet.Description")) 209 }; 210 return header; 211 } 212 213 /** 214 * {@inheritDoc} 215 */ 216 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 217 memberTree.addContent(writer.getMarkerAnchor( 218 SectionName.ENUM_CONSTANT_SUMMARY)); 219 } 220 221 /** 222 * {@inheritDoc} 223 */ 224 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 225 } 226 227 /** 228 * {@inheritDoc} 229 */ 230 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 231 } 232 233 /** 234 * {@inheritDoc} 235 */ 236 protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, 237 Content tdSummary) { 238 Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, 239 writer.getDocLink(context, (MemberDoc) member, member.name(), false)); 240 Content code = HtmlTree.CODE(memberLink); 241 tdSummary.addContent(code); 242 } 243 244 /** 245 * {@inheritDoc} 246 */ 247 @Override 248 public void setSummaryColumnStyle(HtmlTree tdTree) { 249 tdTree.addStyle(HtmlStyle.colOne); 250 } 251 252 /** 253 * {@inheritDoc} 254 */ 255 protected void addInheritedSummaryLink(ClassDoc cd, 256 ProgramElementDoc member, Content linksTree) { 257 } 258 259 /** 260 * {@inheritDoc} 261 */ 262 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 263 //Not applicable. 264 } 265 266 /** 267 * {@inheritDoc} 268 */ 269 protected Content getDeprecatedLink(ProgramElementDoc member) { 270 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, 271 (MemberDoc) member, ((FieldDoc)member).qualifiedName()); 272 } 273 274 /** 275 * {@inheritDoc} 276 */ 277 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 278 if (link) { 279 if (cd == null) { 280 return writer.getHyperLink(SectionName.ENUM_CONSTANT_SUMMARY, 281 writer.getResource("doclet.navEnum")); 282 } else { 283 return writer.getHyperLink( 284 SectionName.ENUM_CONSTANTS_INHERITANCE, 285 configuration.getClassName(cd), writer.getResource("doclet.navEnum")); 286 } 287 } else { 288 return writer.getResource("doclet.navEnum"); 289 } 290 } 291 292 /** 293 * {@inheritDoc} 294 */ 295 protected void addNavDetailLink(boolean link, Content liNav) { 296 if (link) { 297 liNav.addContent(writer.getHyperLink( 298 SectionName.ENUM_CONSTANT_DETAIL, 299 writer.getResource("doclet.navEnum"))); 300 } else { 301 liNav.addContent(writer.getResource("doclet.navEnum")); 302 } 303 } 304 }