Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2003, 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 com.sun.javadoc.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 30 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.builders.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Generate the Class Information Page. |
duke@1 | 36 | * @see com.sun.javadoc.ClassDoc |
duke@1 | 37 | * @see java.util.Collections |
duke@1 | 38 | * @see java.util.List |
duke@1 | 39 | * @see java.util.ArrayList |
duke@1 | 40 | * @see java.util.HashMap |
duke@1 | 41 | * |
duke@1 | 42 | * @author Atul M Dambalkar |
duke@1 | 43 | * @author Robert Field |
bpatel@766 | 44 | * @author Bhavesh Patel (Modified) |
duke@1 | 45 | */ |
duke@1 | 46 | public class AnnotationTypeWriterImpl extends SubWriterHolderWriter |
duke@1 | 47 | implements AnnotationTypeWriter { |
duke@1 | 48 | |
duke@1 | 49 | protected AnnotationTypeDoc annotationType; |
duke@1 | 50 | |
duke@1 | 51 | protected Type prev; |
duke@1 | 52 | |
duke@1 | 53 | protected Type next; |
duke@1 | 54 | |
duke@1 | 55 | /** |
duke@1 | 56 | * @param annotationType the annotation type being documented. |
duke@1 | 57 | * @param prevType the previous class that was documented. |
duke@1 | 58 | * @param nextType the next class being documented. |
duke@1 | 59 | */ |
duke@1 | 60 | public AnnotationTypeWriterImpl (AnnotationTypeDoc annotationType, |
duke@1 | 61 | Type prevType, Type nextType) |
duke@1 | 62 | throws Exception { |
duke@1 | 63 | super(ConfigurationImpl.getInstance(), |
duke@1 | 64 | DirectoryManager.getDirectoryPath(annotationType.containingPackage()), |
duke@1 | 65 | annotationType.name() + ".html", |
duke@1 | 66 | DirectoryManager.getRelativePath(annotationType.containingPackage().name())); |
duke@1 | 67 | this.annotationType = annotationType; |
duke@1 | 68 | configuration.currentcd = annotationType.asClassDoc(); |
duke@1 | 69 | this.prev = prevType; |
duke@1 | 70 | this.next = nextType; |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | /** |
bpatel@766 | 74 | * Get this package link. |
bpatel@766 | 75 | * |
bpatel@766 | 76 | * @return a content tree for the package link |
duke@1 | 77 | */ |
bpatel@766 | 78 | protected Content getNavLinkPackage() { |
bpatel@766 | 79 | Content linkContent = getHyperLink("package-summary.html", "", |
bpatel@766 | 80 | packageLabel); |
bpatel@766 | 81 | Content li = HtmlTree.LI(linkContent); |
bpatel@766 | 82 | return li; |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | /** |
bpatel@766 | 86 | * Get the class link. |
bpatel@766 | 87 | * |
bpatel@766 | 88 | * @return a content tree for the class link |
duke@1 | 89 | */ |
bpatel@766 | 90 | protected Content getNavLinkClass() { |
bpatel@766 | 91 | Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel); |
bpatel@766 | 92 | return li; |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | /** |
bpatel@766 | 96 | * Get the class use link. |
bpatel@766 | 97 | * |
bpatel@766 | 98 | * @return a content tree for the class use link |
duke@1 | 99 | */ |
bpatel@766 | 100 | protected Content getNavLinkClassUse() { |
bpatel@766 | 101 | Content linkContent = getHyperLink("class-use/" + filename, "", useLabel); |
bpatel@766 | 102 | Content li = HtmlTree.LI(linkContent); |
bpatel@766 | 103 | return li; |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
bpatel@766 | 107 | * Get link to previous class. |
bpatel@766 | 108 | * |
bpatel@766 | 109 | * @return a content tree for the previous class link |
duke@1 | 110 | */ |
bpatel@766 | 111 | public Content getNavLinkPrevious() { |
bpatel@766 | 112 | Content li; |
bpatel@766 | 113 | if (prev != null) { |
bpatel@766 | 114 | Content prevLink = new RawHtml(getLink(new LinkInfoImpl( |
bpatel@766 | 115 | LinkInfoImpl.CONTEXT_CLASS, prev.asClassDoc(), "", |
bpatel@766 | 116 | configuration.getText("doclet.Prev_Class"), true))); |
bpatel@766 | 117 | li = HtmlTree.LI(prevLink); |
duke@1 | 118 | } |
bpatel@766 | 119 | else |
bpatel@766 | 120 | li = HtmlTree.LI(prevclassLabel); |
bpatel@766 | 121 | return li; |
duke@1 | 122 | } |
duke@1 | 123 | |
duke@1 | 124 | /** |
bpatel@766 | 125 | * Get link to next class. |
bpatel@766 | 126 | * |
bpatel@766 | 127 | * @return a content tree for the next class link |
duke@1 | 128 | */ |
bpatel@766 | 129 | public Content getNavLinkNext() { |
bpatel@766 | 130 | Content li; |
bpatel@766 | 131 | if (next != null) { |
bpatel@766 | 132 | Content nextLink = new RawHtml(getLink(new LinkInfoImpl( |
bpatel@766 | 133 | LinkInfoImpl.CONTEXT_CLASS, next.asClassDoc(), "", |
bpatel@766 | 134 | configuration.getText("doclet.Next_Class"), true))); |
bpatel@766 | 135 | li = HtmlTree.LI(nextLink); |
duke@1 | 136 | } |
bpatel@766 | 137 | else |
bpatel@766 | 138 | li = HtmlTree.LI(nextclassLabel); |
bpatel@766 | 139 | return li; |
duke@1 | 140 | } |
duke@1 | 141 | |
duke@1 | 142 | /** |
duke@1 | 143 | * {@inheritDoc} |
duke@1 | 144 | */ |
bpatel@766 | 145 | public Content getHeader(String header) { |
duke@1 | 146 | String pkgname = (annotationType.containingPackage() != null)? |
duke@1 | 147 | annotationType.containingPackage().name(): ""; |
duke@1 | 148 | String clname = annotationType.name(); |
bpatel@766 | 149 | Content bodyTree = getBody(true, getWindowTitle(clname)); |
bpatel@766 | 150 | addTop(bodyTree); |
bpatel@766 | 151 | addNavLinks(true, bodyTree); |
bpatel@766 | 152 | bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA); |
bpatel@766 | 153 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 154 | div.addStyle(HtmlStyle.header); |
duke@1 | 155 | if (pkgname.length() > 0) { |
bpatel@766 | 156 | Content pkgNameContent = new StringContent(pkgname); |
bpatel@766 | 157 | Content pkgNamePara = HtmlTree.P(HtmlStyle.subTitle, pkgNameContent); |
bpatel@766 | 158 | div.addContent(pkgNamePara); |
duke@1 | 159 | } |
bpatel@766 | 160 | LinkInfoImpl linkInfo = new LinkInfoImpl( |
bpatel@766 | 161 | LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false); |
bpatel@766 | 162 | Content headerContent = new StringContent(header); |
bpatel@766 | 163 | Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true, |
bpatel@766 | 164 | HtmlStyle.title, headerContent); |
bpatel@766 | 165 | heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo))); |
bpatel@766 | 166 | div.addContent(heading); |
bpatel@766 | 167 | bodyTree.addContent(div); |
bpatel@766 | 168 | return bodyTree; |
duke@1 | 169 | } |
duke@1 | 170 | |
duke@1 | 171 | /** |
duke@1 | 172 | * {@inheritDoc} |
duke@1 | 173 | */ |
bpatel@766 | 174 | public Content getAnnotationContentHeader() { |
bpatel@766 | 175 | return getContentHeader(); |
duke@1 | 176 | } |
duke@1 | 177 | |
duke@1 | 178 | /** |
duke@1 | 179 | * {@inheritDoc} |
duke@1 | 180 | */ |
bpatel@766 | 181 | public void addFooter(Content contentTree) { |
bpatel@766 | 182 | contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA); |
bpatel@766 | 183 | addNavLinks(false, contentTree); |
bpatel@766 | 184 | addBottom(contentTree); |
duke@1 | 185 | } |
duke@1 | 186 | |
duke@1 | 187 | /** |
duke@1 | 188 | * {@inheritDoc} |
duke@1 | 189 | */ |
bpatel@766 | 190 | public void printDocument(Content contentTree) { |
bpatel@766 | 191 | printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType), |
bpatel@766 | 192 | true, contentTree); |
bpatel@766 | 193 | } |
bpatel@766 | 194 | |
bpatel@766 | 195 | /** |
bpatel@766 | 196 | * {@inheritDoc} |
bpatel@766 | 197 | */ |
bpatel@766 | 198 | public Content getAnnotationInfoTreeHeader() { |
bpatel@766 | 199 | return getMemberTreeHeader(); |
bpatel@766 | 200 | } |
bpatel@766 | 201 | |
bpatel@766 | 202 | /** |
bpatel@766 | 203 | * {@inheritDoc} |
bpatel@766 | 204 | */ |
bpatel@766 | 205 | public Content getAnnotationInfo(Content annotationInfoTree) { |
bpatel@766 | 206 | return getMemberTree(HtmlStyle.description, annotationInfoTree); |
bpatel@766 | 207 | } |
bpatel@766 | 208 | |
bpatel@766 | 209 | /** |
bpatel@766 | 210 | * {@inheritDoc} |
bpatel@766 | 211 | */ |
bpatel@766 | 212 | public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) { |
bpatel@766 | 213 | annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR)); |
bpatel@766 | 214 | Content pre = new HtmlTree(HtmlTag.PRE); |
bpatel@766 | 215 | addAnnotationInfo(annotationType, pre); |
bpatel@766 | 216 | pre.addContent(modifiers); |
bpatel@766 | 217 | LinkInfoImpl linkInfo = new LinkInfoImpl( |
bpatel@766 | 218 | LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false); |
bpatel@766 | 219 | Content name = new RawHtml (annotationType.name() + |
bpatel@766 | 220 | getTypeParameterLinks(linkInfo)); |
bpatel@766 | 221 | if (configuration().linksource) { |
bpatel@766 | 222 | addSrcLink(annotationType, name, pre); |
bpatel@766 | 223 | } else { |
bpatel@766 | 224 | pre.addContent(HtmlTree.STRONG(name)); |
bpatel@766 | 225 | } |
bpatel@766 | 226 | annotationInfoTree.addContent(pre); |
bpatel@766 | 227 | } |
bpatel@766 | 228 | |
bpatel@766 | 229 | /** |
bpatel@766 | 230 | * {@inheritDoc} |
bpatel@766 | 231 | */ |
bpatel@766 | 232 | public void addAnnotationTypeDescription(Content annotationInfoTree) { |
duke@1 | 233 | if(!configuration.nocomment) { |
duke@1 | 234 | if (annotationType.inlineTags().length > 0) { |
bpatel@766 | 235 | addInlineComment(annotationType, annotationInfoTree); |
duke@1 | 236 | } |
duke@1 | 237 | } |
duke@1 | 238 | } |
duke@1 | 239 | |
duke@1 | 240 | /** |
duke@1 | 241 | * {@inheritDoc} |
duke@1 | 242 | */ |
bpatel@766 | 243 | public void addAnnotationTypeTagInfo(Content annotationInfoTree) { |
duke@1 | 244 | if(!configuration.nocomment) { |
bpatel@766 | 245 | addTagsInfo(annotationType, annotationInfoTree); |
duke@1 | 246 | } |
duke@1 | 247 | } |
duke@1 | 248 | |
duke@1 | 249 | /** |
duke@1 | 250 | * {@inheritDoc} |
duke@1 | 251 | */ |
bpatel@766 | 252 | public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) { |
bpatel@766 | 253 | Content hr = new HtmlTree(HtmlTag.HR); |
bpatel@766 | 254 | annotationInfoTree.addContent(hr); |
duke@1 | 255 | Tag[] deprs = annotationType.tags("deprecated"); |
duke@1 | 256 | if (Util.isDeprecated(annotationType)) { |
bpatel@766 | 257 | Content strong = HtmlTree.STRONG(deprecatedPhrase); |
bpatel@766 | 258 | Content div = HtmlTree.DIV(HtmlStyle.block, strong); |
duke@1 | 259 | if (deprs.length > 0) { |
duke@1 | 260 | Tag[] commentTags = deprs[0].inlineTags(); |
duke@1 | 261 | if (commentTags.length > 0) { |
bpatel@766 | 262 | div.addContent(getSpace()); |
bpatel@766 | 263 | addInlineDeprecatedComment(annotationType, deprs[0], div); |
duke@1 | 264 | } |
duke@1 | 265 | } |
bpatel@766 | 266 | annotationInfoTree.addContent(div); |
duke@1 | 267 | } |
duke@1 | 268 | } |
duke@1 | 269 | |
bpatel@766 | 270 | /** |
bpatel@766 | 271 | * {@inheritDoc} |
bpatel@766 | 272 | */ |
bpatel@766 | 273 | public void addAnnotationDetailsMarker(Content memberDetails) { |
bpatel@766 | 274 | memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS); |
duke@1 | 275 | } |
duke@1 | 276 | |
bpatel@766 | 277 | /** |
bpatel@766 | 278 | * {@inheritDoc} |
bpatel@766 | 279 | */ |
bpatel@766 | 280 | protected Content getNavLinkTree() { |
bpatel@766 | 281 | Content treeLinkContent = getHyperLink("package-tree.html", |
bpatel@766 | 282 | "", treeLabel, "", ""); |
bpatel@766 | 283 | Content li = HtmlTree.LI(treeLinkContent); |
bpatel@766 | 284 | return li; |
bpatel@766 | 285 | } |
bpatel@766 | 286 | |
bpatel@766 | 287 | /** |
bpatel@766 | 288 | * Add summary details to the navigation bar. |
bpatel@766 | 289 | * |
bpatel@766 | 290 | * @param subDiv the content tree to which the summary detail links will be added |
bpatel@766 | 291 | */ |
bpatel@766 | 292 | protected void addSummaryDetailLinks(Content subDiv) { |
duke@1 | 293 | try { |
bpatel@766 | 294 | Content div = HtmlTree.DIV(getNavSummaryLinks()); |
bpatel@766 | 295 | div.addContent(getNavDetailLinks()); |
bpatel@766 | 296 | subDiv.addContent(div); |
duke@1 | 297 | } catch (Exception e) { |
duke@1 | 298 | e.printStackTrace(); |
duke@1 | 299 | throw new DocletAbortException(); |
duke@1 | 300 | } |
duke@1 | 301 | } |
duke@1 | 302 | |
bpatel@766 | 303 | /** |
bpatel@766 | 304 | * Get summary links for navigation bar. |
bpatel@766 | 305 | * |
bpatel@766 | 306 | * @return the content tree for the navigation summary links |
bpatel@766 | 307 | */ |
bpatel@766 | 308 | protected Content getNavSummaryLinks() throws Exception { |
bpatel@766 | 309 | Content li = HtmlTree.LI(summaryLabel); |
bpatel@766 | 310 | li.addContent(getSpace()); |
bpatel@766 | 311 | Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); |
duke@1 | 312 | MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) |
bpatel@766 | 313 | configuration.getBuilderFactory().getMemberSummaryBuilder(this); |
bpatel@766 | 314 | Content liNavReq = new HtmlTree(HtmlTag.LI); |
bpatel@766 | 315 | addNavSummaryLink(memberSummaryBuilder, |
bpatel@766 | 316 | "doclet.navAnnotationTypeRequiredMember", |
bpatel@766 | 317 | VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq); |
bpatel@766 | 318 | addNavGap(liNavReq); |
bpatel@766 | 319 | ulNav.addContent(liNavReq); |
bpatel@766 | 320 | Content liNavOpt = new HtmlTree(HtmlTag.LI); |
bpatel@766 | 321 | addNavSummaryLink(memberSummaryBuilder, |
bpatel@766 | 322 | "doclet.navAnnotationTypeOptionalMember", |
bpatel@766 | 323 | VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt); |
bpatel@766 | 324 | ulNav.addContent(liNavOpt); |
bpatel@766 | 325 | return ulNav; |
duke@1 | 326 | } |
duke@1 | 327 | |
bpatel@766 | 328 | /** |
bpatel@766 | 329 | * Add the navigation summary link. |
bpatel@766 | 330 | * |
bpatel@766 | 331 | * @param builder builder for the member to be documented |
bpatel@766 | 332 | * @param label the label for the navigation |
bpatel@766 | 333 | * @param type type to be documented |
bpatel@766 | 334 | * @param liNav the content tree to which the navigation summary link will be added |
bpatel@766 | 335 | */ |
bpatel@766 | 336 | protected void addNavSummaryLink(MemberSummaryBuilder builder, |
bpatel@766 | 337 | String label, int type, Content liNav) { |
duke@1 | 338 | AbstractMemberWriter writer = ((AbstractMemberWriter) builder. |
bpatel@766 | 339 | getMemberSummaryWriter(type)); |
duke@1 | 340 | if (writer == null) { |
bpatel@766 | 341 | liNav.addContent(getResource(label)); |
duke@1 | 342 | } else { |
bpatel@766 | 343 | liNav.addContent(writer.getNavSummaryLink(null, |
bpatel@766 | 344 | ! builder.getVisibleMemberMap(type).noVisibleMembers())); |
duke@1 | 345 | } |
duke@1 | 346 | } |
duke@1 | 347 | |
duke@1 | 348 | /** |
bpatel@766 | 349 | * Get detail links for the navigation bar. |
duke@1 | 350 | * |
bpatel@766 | 351 | * @return the content tree for the detail links |
duke@1 | 352 | */ |
bpatel@766 | 353 | protected Content getNavDetailLinks() throws Exception { |
bpatel@766 | 354 | Content li = HtmlTree.LI(detailLabel); |
bpatel@766 | 355 | li.addContent(getSpace()); |
bpatel@766 | 356 | Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); |
duke@1 | 357 | MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) |
bpatel@766 | 358 | configuration.getBuilderFactory().getMemberSummaryBuilder(this); |
duke@1 | 359 | AbstractMemberWriter writerOptional = |
bpatel@766 | 360 | ((AbstractMemberWriter) memberSummaryBuilder. |
duke@1 | 361 | getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL)); |
duke@1 | 362 | AbstractMemberWriter writerRequired = |
bpatel@766 | 363 | ((AbstractMemberWriter) memberSummaryBuilder. |
duke@1 | 364 | getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED)); |
duke@1 | 365 | if (writerOptional != null){ |
bpatel@766 | 366 | Content liNavOpt = new HtmlTree(HtmlTag.LI); |
bpatel@766 | 367 | writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt); |
bpatel@766 | 368 | ulNav.addContent(liNavOpt); |
duke@1 | 369 | } else if (writerRequired != null){ |
bpatel@766 | 370 | Content liNavReq = new HtmlTree(HtmlTag.LI); |
bpatel@766 | 371 | writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq); |
bpatel@766 | 372 | ulNav.addContent(liNavReq); |
duke@1 | 373 | } else { |
bpatel@766 | 374 | Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember")); |
bpatel@766 | 375 | ulNav.addContent(liNav); |
duke@1 | 376 | } |
bpatel@766 | 377 | return ulNav; |
duke@1 | 378 | } |
duke@1 | 379 | |
duke@1 | 380 | /** |
bpatel@766 | 381 | * Add gap between navigation bar elements. |
bpatel@766 | 382 | * |
bpatel@766 | 383 | * @param liNav the content tree to which the gap will be added |
duke@1 | 384 | */ |
bpatel@766 | 385 | protected void addNavGap(Content liNav) { |
bpatel@766 | 386 | liNav.addContent(getSpace()); |
bpatel@766 | 387 | liNav.addContent("|"); |
bpatel@766 | 388 | liNav.addContent(getSpace()); |
duke@1 | 389 | } |
duke@1 | 390 | |
duke@1 | 391 | /** |
duke@1 | 392 | * {@inheritDoc} |
duke@1 | 393 | */ |
duke@1 | 394 | public AnnotationTypeDoc getAnnotationTypeDoc() { |
duke@1 | 395 | return annotationType; |
duke@1 | 396 | } |
duke@1 | 397 | } |