ConstructorWriterImpl.java revision 2571:10fc81ac75b4
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 26package com.sun.tools.doclets.formats.html; 27 28import java.io.*; 29import java.util.*; 30 31import com.sun.javadoc.*; 32import com.sun.tools.doclets.formats.html.markup.*; 33import com.sun.tools.doclets.internal.toolkit.*; 34import com.sun.tools.doclets.internal.toolkit.util.*; 35 36/** 37 * Writes constructor documentation. 38 * 39 * <p><b>This is NOT part of any supported API. 40 * If you write code that depends on this, you do so at your own risk. 41 * This code and its internal interfaces are subject to change or 42 * deletion without notice.</b> 43 * 44 * @author Robert Field 45 * @author Atul M Dambalkar 46 * @author Bhavesh Patel (Modified) 47 */ 48public class ConstructorWriterImpl extends AbstractExecutableMemberWriter 49 implements ConstructorWriter, MemberSummaryWriter { 50 51 private boolean foundNonPubConstructor = false; 52 53 /** 54 * Construct a new ConstructorWriterImpl. 55 * 56 * @param writer The writer for the class that the constructors belong to. 57 * @param classDoc the class being documented. 58 */ 59 public ConstructorWriterImpl(SubWriterHolderWriter writer, 60 ClassDoc classDoc) { 61 super(writer, classDoc); 62 VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc, 63 VisibleMemberMap.CONSTRUCTORS, configuration); 64 List<ProgramElementDoc> constructors = new ArrayList<>(visibleMemberMap.getMembersFor(classDoc)); 65 for (ProgramElementDoc constructor : constructors) { 66 if (constructor.isProtected() || constructor.isPrivate()) { 67 setFoundNonPubConstructor(true); 68 } 69 } 70 } 71 72 /** 73 * Construct a new ConstructorWriterImpl. 74 * 75 * @param writer The writer for the class that the constructors belong to. 76 */ 77 public ConstructorWriterImpl(SubWriterHolderWriter writer) { 78 super(writer); 79 } 80 81 /** 82 * {@inheritDoc} 83 */ 84 public Content getMemberSummaryHeader(ClassDoc classDoc, 85 Content memberSummaryTree) { 86 memberSummaryTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_SUMMARY); 87 Content memberTree = writer.getMemberTreeHeader(); 88 writer.addSummaryHeader(this, classDoc, memberTree); 89 return memberTree; 90 } 91 92 /** 93 * {@inheritDoc} 94 */ 95 public Content getConstructorDetailsTreeHeader(ClassDoc classDoc, 96 Content memberDetailsTree) { 97 memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS); 98 Content constructorDetailsTree = writer.getMemberTreeHeader(); 99 constructorDetailsTree.addContent(writer.getMarkerAnchor( 100 SectionName.CONSTRUCTOR_DETAIL)); 101 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, 102 writer.constructorDetailsLabel); 103 constructorDetailsTree.addContent(heading); 104 return constructorDetailsTree; 105 } 106 107 /** 108 * {@inheritDoc} 109 */ 110 public Content getConstructorDocTreeHeader(ConstructorDoc constructor, 111 Content constructorDetailsTree) { 112 String erasureAnchor; 113 if ((erasureAnchor = getErasureAnchor(constructor)) != null) { 114 constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor))); 115 } 116 constructorDetailsTree.addContent( 117 writer.getMarkerAnchor(writer.getAnchor(constructor))); 118 Content constructorDocTree = writer.getMemberTreeHeader(); 119 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); 120 heading.addContent(constructor.name()); 121 constructorDocTree.addContent(heading); 122 return constructorDocTree; 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 public Content getSignature(ConstructorDoc constructor) { 129 Content pre = new HtmlTree(HtmlTag.PRE); 130 writer.addAnnotationInfo(constructor, pre); 131 addModifiers(constructor, pre); 132 if (configuration.linksource) { 133 Content constructorName = new StringContent(constructor.name()); 134 writer.addSrcLink(constructor, constructorName, pre); 135 } else { 136 addName(constructor.name(), pre); 137 } 138 int indent = pre.charCount(); 139 addParameters(constructor, pre, indent); 140 addExceptions(constructor, pre, indent); 141 return pre; 142 } 143 144 /** 145 * {@inheritDoc} 146 */ 147 @Override 148 public void setSummaryColumnStyle(HtmlTree tdTree) { 149 if (foundNonPubConstructor) 150 tdTree.addStyle(HtmlStyle.colLast); 151 else 152 tdTree.addStyle(HtmlStyle.colOne); 153 } 154 155 /** 156 * {@inheritDoc} 157 */ 158 public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) { 159 addDeprecatedInfo(constructor, constructorDocTree); 160 } 161 162 /** 163 * {@inheritDoc} 164 */ 165 public void addComments(ConstructorDoc constructor, Content constructorDocTree) { 166 addComment(constructor, constructorDocTree); 167 } 168 169 /** 170 * {@inheritDoc} 171 */ 172 public void addTags(ConstructorDoc constructor, Content constructorDocTree) { 173 writer.addTagsInfo(constructor, constructorDocTree); 174 } 175 176 /** 177 * {@inheritDoc} 178 */ 179 public Content getConstructorDetails(Content constructorDetailsTree) { 180 return getMemberTree(constructorDetailsTree); 181 } 182 183 /** 184 * {@inheritDoc} 185 */ 186 public Content getConstructorDoc(Content constructorDocTree, 187 boolean isLastContent) { 188 return getMemberTree(constructorDocTree, isLastContent); 189 } 190 191 /** 192 * Close the writer. 193 */ 194 public void close() throws IOException { 195 writer.close(); 196 } 197 198 /** 199 * Let the writer know whether a non public constructor was found. 200 * 201 * @param foundNonPubConstructor true if we found a non public constructor. 202 */ 203 public void setFoundNonPubConstructor(boolean foundNonPubConstructor) { 204 this.foundNonPubConstructor = foundNonPubConstructor; 205 } 206 207 /** 208 * {@inheritDoc} 209 */ 210 public void addSummaryLabel(Content memberTree) { 211 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 212 writer.getResource("doclet.Constructor_Summary")); 213 memberTree.addContent(label); 214 } 215 216 /** 217 * {@inheritDoc} 218 */ 219 public String getTableSummary() { 220 return configuration.getText("doclet.Member_Table_Summary", 221 configuration.getText("doclet.Constructor_Summary"), 222 configuration.getText("doclet.constructors")); 223 } 224 225 /** 226 * {@inheritDoc} 227 */ 228 public Content getCaption() { 229 return configuration.getResource("doclet.Constructors"); 230 } 231 232 /** 233 * {@inheritDoc} 234 */ 235 public String[] getSummaryTableHeader(ProgramElementDoc member) { 236 String[] header; 237 if (foundNonPubConstructor) { 238 header = new String[] { 239 configuration.getText("doclet.Modifier"), 240 configuration.getText("doclet.0_and_1", 241 configuration.getText("doclet.Constructor"), 242 configuration.getText("doclet.Description")) 243 }; 244 } 245 else { 246 header = new String[] { 247 configuration.getText("doclet.0_and_1", 248 configuration.getText("doclet.Constructor"), 249 configuration.getText("doclet.Description")) 250 }; 251 } 252 return header; 253 } 254 255 /** 256 * {@inheritDoc} 257 */ 258 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 259 memberTree.addContent(writer.getMarkerAnchor( 260 SectionName.CONSTRUCTOR_SUMMARY)); 261 } 262 263 /** 264 * {@inheritDoc} 265 */ 266 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { 267 } 268 269 /** 270 * {@inheritDoc} 271 */ 272 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { 273 } 274 275 public int getMemberKind() { 276 return VisibleMemberMap.CONSTRUCTORS; 277 } 278 279 /** 280 * {@inheritDoc} 281 */ 282 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 283 if (link) { 284 return writer.getHyperLink(SectionName.CONSTRUCTOR_SUMMARY, 285 writer.getResource("doclet.navConstructor")); 286 } else { 287 return writer.getResource("doclet.navConstructor"); 288 } 289 } 290 291 /** 292 * {@inheritDoc} 293 */ 294 protected void addNavDetailLink(boolean link, Content liNav) { 295 if (link) { 296 liNav.addContent(writer.getHyperLink( 297 SectionName.CONSTRUCTOR_DETAIL, 298 writer.getResource("doclet.navConstructor"))); 299 } else { 300 liNav.addContent(writer.getResource("doclet.navConstructor")); 301 } 302 } 303 304 /** 305 * {@inheritDoc} 306 */ 307 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { 308 if (foundNonPubConstructor) { 309 Content code = new HtmlTree(HtmlTag.CODE); 310 if (member.isProtected()) { 311 code.addContent("protected "); 312 } else if (member.isPrivate()) { 313 code.addContent("private "); 314 } else if (member.isPublic()) { 315 code.addContent(writer.getSpace()); 316 } else { 317 code.addContent( 318 configuration.getText("doclet.Package_private")); 319 } 320 tdSummaryType.addContent(code); 321 } 322 } 323} 324