Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
bpatel@233 | 28 | import java.io.*; |
bpatel@233 | 29 | import java.util.*; |
bpatel@233 | 30 | |
bpatel@233 | 31 | import com.sun.javadoc.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 34 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Writes constructor documentation. |
duke@1 | 38 | * |
duke@1 | 39 | * @author Robert Field |
duke@1 | 40 | * @author Atul M Dambalkar |
bpatel@243 | 41 | * @author Bhavesh Patel (Modified) |
duke@1 | 42 | */ |
duke@1 | 43 | public class ConstructorWriterImpl extends AbstractExecutableMemberWriter |
duke@1 | 44 | implements ConstructorWriter, MemberSummaryWriter { |
duke@1 | 45 | |
duke@1 | 46 | private boolean foundNonPubConstructor = false; |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * Construct a new ConstructorWriterImpl. |
duke@1 | 50 | * |
duke@1 | 51 | * @param writer The writer for the class that the constructors belong to. |
duke@1 | 52 | * @param classDoc the class being documented. |
duke@1 | 53 | */ |
duke@1 | 54 | public ConstructorWriterImpl(SubWriterHolderWriter writer, |
duke@1 | 55 | ClassDoc classDoc) { |
duke@1 | 56 | super(writer, classDoc); |
duke@1 | 57 | VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc, |
duke@1 | 58 | VisibleMemberMap.CONSTRUCTORS, configuration().nodeprecated); |
jjg@74 | 59 | List<ProgramElementDoc> constructors = new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc)); |
duke@1 | 60 | for (int i = 0; i < constructors.size(); i++) { |
jjg@74 | 61 | if ((constructors.get(i)).isProtected() || |
jjg@74 | 62 | (constructors.get(i)).isPrivate()) { |
duke@1 | 63 | setFoundNonPubConstructor(true); |
duke@1 | 64 | } |
duke@1 | 65 | } |
duke@1 | 66 | } |
duke@1 | 67 | |
duke@1 | 68 | /** |
duke@1 | 69 | * Construct a new ConstructorWriterImpl. |
duke@1 | 70 | * |
duke@1 | 71 | * @param writer The writer for the class that the constructors belong to. |
duke@1 | 72 | */ |
duke@1 | 73 | public ConstructorWriterImpl(SubWriterHolderWriter writer) { |
duke@1 | 74 | super(writer); |
duke@1 | 75 | } |
duke@1 | 76 | |
duke@1 | 77 | /** |
bpatel@766 | 78 | * {@inheritDoc} |
duke@1 | 79 | */ |
bpatel@766 | 80 | public Content getMemberSummaryHeader(ClassDoc classDoc, |
bpatel@766 | 81 | Content memberSummaryTree) { |
bpatel@766 | 82 | memberSummaryTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_SUMMARY); |
bpatel@766 | 83 | Content memberTree = writer.getMemberTreeHeader(); |
bpatel@766 | 84 | writer.addSummaryHeader(this, classDoc, memberTree); |
bpatel@766 | 85 | return memberTree; |
duke@1 | 86 | } |
duke@1 | 87 | |
duke@1 | 88 | /** |
bpatel@766 | 89 | * {@inheritDoc} |
duke@1 | 90 | */ |
bpatel@766 | 91 | public Content getConstructorDetailsTreeHeader(ClassDoc classDoc, |
bpatel@766 | 92 | Content memberDetailsTree) { |
bpatel@766 | 93 | memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS); |
bpatel@766 | 94 | Content constructorDetailsTree = writer.getMemberTreeHeader(); |
bpatel@766 | 95 | constructorDetailsTree.addContent(writer.getMarkerAnchor("constructor_detail")); |
bpatel@766 | 96 | Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, |
bpatel@766 | 97 | writer.constructorDetailsLabel); |
bpatel@766 | 98 | constructorDetailsTree.addContent(heading); |
bpatel@766 | 99 | return constructorDetailsTree; |
duke@1 | 100 | } |
duke@1 | 101 | |
duke@1 | 102 | /** |
bpatel@766 | 103 | * {@inheritDoc} |
duke@1 | 104 | */ |
bpatel@766 | 105 | public Content getConstructorDocTreeHeader(ConstructorDoc constructor, |
bpatel@766 | 106 | Content constructorDetailsTree) { |
bpatel@766 | 107 | String erasureAnchor; |
bpatel@766 | 108 | if ((erasureAnchor = getErasureAnchor(constructor)) != null) { |
bpatel@766 | 109 | constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor))); |
bpatel@766 | 110 | } |
bpatel@766 | 111 | constructorDetailsTree.addContent( |
bpatel@766 | 112 | writer.getMarkerAnchor(writer.getAnchor(constructor))); |
bpatel@766 | 113 | Content constructorDocTree = writer.getMemberTreeHeader(); |
bpatel@766 | 114 | Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); |
bpatel@766 | 115 | heading.addContent(constructor.name()); |
bpatel@766 | 116 | constructorDocTree.addContent(heading); |
bpatel@766 | 117 | return constructorDocTree; |
duke@1 | 118 | } |
duke@1 | 119 | |
duke@1 | 120 | /** |
bpatel@766 | 121 | * {@inheritDoc} |
duke@1 | 122 | */ |
bpatel@766 | 123 | public Content getSignature(ConstructorDoc constructor) { |
bpatel@766 | 124 | writer.displayLength = 0; |
bpatel@766 | 125 | Content pre = new HtmlTree(HtmlTag.PRE); |
bpatel@766 | 126 | writer.addAnnotationInfo(constructor, pre); |
bpatel@766 | 127 | addModifiers(constructor, pre); |
bpatel@766 | 128 | if (configuration().linksource) { |
bpatel@766 | 129 | Content constructorName = new StringContent(constructor.name()); |
bpatel@766 | 130 | writer.addSrcLink(constructor, constructorName, pre); |
bpatel@766 | 131 | } else { |
bpatel@766 | 132 | addName(constructor.name(), pre); |
duke@1 | 133 | } |
bpatel@766 | 134 | addParameters(constructor, pre); |
bpatel@766 | 135 | addExceptions(constructor, pre); |
bpatel@766 | 136 | return pre; |
duke@1 | 137 | } |
duke@1 | 138 | |
duke@1 | 139 | /** |
bpatel@766 | 140 | * {@inheritDoc} |
duke@1 | 141 | */ |
bpatel@766 | 142 | @Override |
bpatel@766 | 143 | public void setSummaryColumnStyle(HtmlTree tdTree) { |
bpatel@766 | 144 | if (foundNonPubConstructor) |
bpatel@766 | 145 | tdTree.addStyle(HtmlStyle.colLast); |
bpatel@766 | 146 | else |
bpatel@766 | 147 | tdTree.addStyle(HtmlStyle.colOne); |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** |
bpatel@766 | 151 | * {@inheritDoc} |
duke@1 | 152 | */ |
bpatel@766 | 153 | public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 154 | addDeprecatedInfo(constructor, constructorDocTree); |
duke@1 | 155 | } |
duke@1 | 156 | |
duke@1 | 157 | /** |
bpatel@766 | 158 | * {@inheritDoc} |
duke@1 | 159 | */ |
bpatel@766 | 160 | public void addComments(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 161 | addComment(constructor, constructorDocTree); |
duke@1 | 162 | } |
duke@1 | 163 | |
duke@1 | 164 | /** |
bpatel@766 | 165 | * {@inheritDoc} |
duke@1 | 166 | */ |
bpatel@766 | 167 | public void addTags(ConstructorDoc constructor, Content constructorDocTree) { |
bpatel@766 | 168 | writer.addTagsInfo(constructor, constructorDocTree); |
duke@1 | 169 | } |
duke@1 | 170 | |
duke@1 | 171 | /** |
bpatel@766 | 172 | * {@inheritDoc} |
duke@1 | 173 | */ |
bpatel@766 | 174 | public Content getConstructorDetails(Content constructorDetailsTree) { |
bpatel@766 | 175 | return getMemberTree(constructorDetailsTree); |
duke@1 | 176 | } |
duke@1 | 177 | |
duke@1 | 178 | /** |
bpatel@766 | 179 | * {@inheritDoc} |
duke@1 | 180 | */ |
bpatel@766 | 181 | public Content getConstructorDoc(Content constructorDocTree, |
bpatel@766 | 182 | boolean isLastContent) { |
bpatel@766 | 183 | return getMemberTree(constructorDocTree, isLastContent); |
duke@1 | 184 | } |
duke@1 | 185 | |
duke@1 | 186 | /** |
duke@1 | 187 | * Close the writer. |
duke@1 | 188 | */ |
duke@1 | 189 | public void close() throws IOException { |
duke@1 | 190 | writer.close(); |
duke@1 | 191 | } |
duke@1 | 192 | |
duke@1 | 193 | /** |
duke@1 | 194 | * Let the writer know whether a non public constructor was found. |
duke@1 | 195 | * |
duke@1 | 196 | * @param foundNonPubConstructor true if we found a non public constructor. |
duke@1 | 197 | */ |
duke@1 | 198 | public void setFoundNonPubConstructor(boolean foundNonPubConstructor) { |
duke@1 | 199 | this.foundNonPubConstructor = foundNonPubConstructor; |
duke@1 | 200 | } |
duke@1 | 201 | |
bpatel@766 | 202 | /** |
bpatel@766 | 203 | * {@inheritDoc} |
bpatel@766 | 204 | */ |
bpatel@766 | 205 | public void addSummaryLabel(Content memberTree) { |
bpatel@766 | 206 | Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, |
bpatel@766 | 207 | writer.getResource("doclet.Constructor_Summary")); |
bpatel@766 | 208 | memberTree.addContent(label); |
bpatel@243 | 209 | } |
bpatel@243 | 210 | |
bpatel@766 | 211 | /** |
bpatel@766 | 212 | * {@inheritDoc} |
bpatel@766 | 213 | */ |
bpatel@766 | 214 | public String getTableSummary() { |
bpatel@766 | 215 | return configuration().getText("doclet.Member_Table_Summary", |
bpatel@243 | 216 | configuration().getText("doclet.Constructor_Summary"), |
bpatel@766 | 217 | configuration().getText("doclet.constructors")); |
bpatel@243 | 218 | } |
bpatel@243 | 219 | |
bpatel@766 | 220 | /** |
bpatel@766 | 221 | * {@inheritDoc} |
bpatel@766 | 222 | */ |
bpatel@766 | 223 | public String getCaption() { |
bpatel@766 | 224 | return configuration().getText("doclet.Constructors"); |
bpatel@766 | 225 | } |
bpatel@766 | 226 | |
bpatel@766 | 227 | /** |
bpatel@766 | 228 | * {@inheritDoc} |
bpatel@766 | 229 | */ |
bpatel@766 | 230 | public String[] getSummaryTableHeader(ProgramElementDoc member) { |
bpatel@243 | 231 | String[] header; |
bpatel@243 | 232 | if (foundNonPubConstructor) { |
bpatel@243 | 233 | header = new String[] { |
bpatel@243 | 234 | configuration().getText("doclet.Modifier"), |
bpatel@243 | 235 | configuration().getText("doclet.0_and_1", |
bpatel@243 | 236 | configuration().getText("doclet.Constructor"), |
bpatel@243 | 237 | configuration().getText("doclet.Description")) |
bpatel@243 | 238 | }; |
bpatel@243 | 239 | } |
bpatel@243 | 240 | else { |
bpatel@243 | 241 | header = new String[] { |
bpatel@243 | 242 | configuration().getText("doclet.0_and_1", |
bpatel@243 | 243 | configuration().getText("doclet.Constructor"), |
bpatel@243 | 244 | configuration().getText("doclet.Description")) |
bpatel@243 | 245 | }; |
bpatel@243 | 246 | } |
bpatel@766 | 247 | return header; |
duke@1 | 248 | } |
duke@1 | 249 | |
bpatel@766 | 250 | /** |
bpatel@766 | 251 | * {@inheritDoc} |
bpatel@766 | 252 | */ |
bpatel@766 | 253 | public void addSummaryAnchor(ClassDoc cd, Content memberTree) { |
bpatel@766 | 254 | memberTree.addContent(writer.getMarkerAnchor("constructor_summary")); |
duke@1 | 255 | } |
duke@1 | 256 | |
bpatel@766 | 257 | /** |
bpatel@766 | 258 | * {@inheritDoc} |
bpatel@766 | 259 | */ |
bpatel@766 | 260 | public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { |
bpatel@766 | 261 | } |
duke@1 | 262 | |
bpatel@766 | 263 | /** |
bpatel@766 | 264 | * {@inheritDoc} |
bpatel@766 | 265 | */ |
bpatel@766 | 266 | public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { |
duke@1 | 267 | } |
duke@1 | 268 | |
duke@1 | 269 | public int getMemberKind() { |
duke@1 | 270 | return VisibleMemberMap.CONSTRUCTORS; |
duke@1 | 271 | } |
duke@1 | 272 | |
bpatel@766 | 273 | /** |
bpatel@766 | 274 | * {@inheritDoc} |
bpatel@766 | 275 | */ |
bpatel@766 | 276 | protected Content getNavSummaryLink(ClassDoc cd, boolean link) { |
duke@1 | 277 | if (link) { |
bpatel@766 | 278 | return writer.getHyperLink("", "constructor_summary", |
bpatel@766 | 279 | writer.getResource("doclet.navConstructor")); |
duke@1 | 280 | } else { |
bpatel@766 | 281 | return writer.getResource("doclet.navConstructor"); |
duke@1 | 282 | } |
duke@1 | 283 | } |
duke@1 | 284 | |
duke@1 | 285 | /** |
duke@1 | 286 | * {@inheritDoc} |
duke@1 | 287 | */ |
bpatel@766 | 288 | protected void addNavDetailLink(boolean link, Content liNav) { |
bpatel@766 | 289 | if (link) { |
bpatel@766 | 290 | liNav.addContent(writer.getHyperLink("", "constructor_detail", |
bpatel@766 | 291 | writer.getResource("doclet.navConstructor"))); |
bpatel@766 | 292 | } else { |
bpatel@766 | 293 | liNav.addContent(writer.getResource("doclet.navConstructor")); |
bpatel@766 | 294 | } |
bpatel@766 | 295 | } |
duke@1 | 296 | |
duke@1 | 297 | /** |
bpatel@766 | 298 | * {@inheritDoc} |
duke@1 | 299 | */ |
bpatel@766 | 300 | protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { |
bpatel@766 | 301 | if (foundNonPubConstructor) { |
bpatel@766 | 302 | Content code = new HtmlTree(HtmlTag.CODE); |
bpatel@766 | 303 | if (member.isProtected()) { |
bpatel@766 | 304 | code.addContent("protected "); |
bpatel@766 | 305 | } else if (member.isPrivate()) { |
bpatel@766 | 306 | code.addContent("private "); |
bpatel@766 | 307 | } else if (member.isPublic()) { |
bpatel@766 | 308 | code.addContent(writer.getSpace()); |
bpatel@766 | 309 | } else { |
bpatel@766 | 310 | code.addContent( |
bpatel@766 | 311 | configuration().getText("doclet.Package_private")); |
bpatel@766 | 312 | } |
bpatel@766 | 313 | tdSummaryType.addContent(code); |
bpatel@766 | 314 | } |
bpatel@766 | 315 | } |
duke@1 | 316 | } |