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 | |
duke@1 | 28 | import com.sun.tools.doclets.internal.toolkit.util.links.*; |
duke@1 | 29 | import com.sun.javadoc.*; |
duke@1 | 30 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 32 | |
duke@1 | 33 | /** |
duke@1 | 34 | * A factory that returns a link given the information about it. |
duke@1 | 35 | * |
duke@1 | 36 | * @author Jamie Ho |
duke@1 | 37 | * @since 1.5 |
duke@1 | 38 | */ |
duke@1 | 39 | public class LinkFactoryImpl extends LinkFactory { |
duke@1 | 40 | |
duke@1 | 41 | private HtmlDocletWriter m_writer; |
duke@1 | 42 | |
duke@1 | 43 | public LinkFactoryImpl(HtmlDocletWriter writer) { |
duke@1 | 44 | m_writer = writer; |
duke@1 | 45 | } |
duke@1 | 46 | |
duke@1 | 47 | /** |
duke@1 | 48 | * {@inheritDoc} |
duke@1 | 49 | */ |
duke@1 | 50 | protected LinkOutput getOutputInstance() { |
duke@1 | 51 | return new LinkOutputImpl(); |
duke@1 | 52 | } |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * {@inheritDoc} |
duke@1 | 56 | */ |
duke@1 | 57 | protected LinkOutput getClassLink(LinkInfo linkInfo) { |
duke@1 | 58 | LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; |
duke@1 | 59 | boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0; |
duke@1 | 60 | ClassDoc classDoc = classLinkInfo.classDoc; |
duke@1 | 61 | //Create a tool tip if we are linking to a class or interface. Don't |
duke@1 | 62 | //create one if we are linking to a member. |
duke@1 | 63 | String title = |
duke@1 | 64 | (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ? |
duke@1 | 65 | getClassToolTip(classDoc, |
duke@1 | 66 | classLinkInfo.type != null && |
duke@1 | 67 | !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) : |
duke@1 | 68 | ""; |
duke@1 | 69 | StringBuffer label = new StringBuffer( |
duke@1 | 70 | classLinkInfo.getClassLinkLabel(m_writer.configuration)); |
duke@1 | 71 | classLinkInfo.displayLength += label.length(); |
duke@1 | 72 | if (noLabel && classLinkInfo.excludeTypeParameterLinks) { |
duke@1 | 73 | label.append(getTypeParameterLinks(linkInfo).toString()); |
duke@1 | 74 | } |
duke@1 | 75 | Configuration configuration = ConfigurationImpl.getInstance(); |
duke@1 | 76 | LinkOutputImpl linkOutput = new LinkOutputImpl(); |
duke@1 | 77 | if (classDoc.isIncluded()) { |
duke@1 | 78 | if (configuration.isGeneratedDoc(classDoc)) { |
duke@1 | 79 | String filename = pathString(classLinkInfo); |
duke@1 | 80 | if (linkInfo.linkToSelf || |
duke@1 | 81 | !(linkInfo.classDoc.name() + ".html").equals(m_writer.filename)) { |
bpatel@766 | 82 | linkOutput.append(m_writer.getHyperLinkString(filename, |
duke@1 | 83 | classLinkInfo.where, label.toString(), |
bpatel@182 | 84 | classLinkInfo.isStrong, classLinkInfo.styleName, |
duke@1 | 85 | title, classLinkInfo.target)); |
duke@1 | 86 | if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
duke@1 | 87 | linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
duke@1 | 88 | } |
duke@1 | 89 | return linkOutput; |
duke@1 | 90 | } |
duke@1 | 91 | } |
duke@1 | 92 | } else { |
duke@1 | 93 | String crossLink = m_writer.getCrossClassLink( |
duke@1 | 94 | classDoc.qualifiedName(), classLinkInfo.where, |
bpatel@182 | 95 | label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName, |
duke@1 | 96 | true); |
duke@1 | 97 | if (crossLink != null) { |
duke@1 | 98 | linkOutput.append(crossLink); |
duke@1 | 99 | if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
duke@1 | 100 | linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
duke@1 | 101 | } |
duke@1 | 102 | return linkOutput; |
duke@1 | 103 | } |
duke@1 | 104 | } |
duke@1 | 105 | // Can't link so just write label. |
duke@1 | 106 | linkOutput.append(label.toString()); |
duke@1 | 107 | if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { |
duke@1 | 108 | linkOutput.append(getTypeParameterLinks(linkInfo).toString()); |
duke@1 | 109 | } |
duke@1 | 110 | return linkOutput; |
duke@1 | 111 | } |
duke@1 | 112 | |
duke@1 | 113 | /** |
duke@1 | 114 | * {@inheritDoc} |
duke@1 | 115 | */ |
duke@1 | 116 | protected LinkOutput getTypeParameterLink(LinkInfo linkInfo, |
duke@1 | 117 | Type typeParam) { |
duke@1 | 118 | LinkInfoImpl typeLinkInfo = new LinkInfoImpl(linkInfo.getContext(), |
duke@1 | 119 | typeParam); |
duke@1 | 120 | typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds; |
duke@1 | 121 | typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks; |
duke@1 | 122 | typeLinkInfo.linkToSelf = linkInfo.linkToSelf; |
duke@1 | 123 | LinkOutput output = getLinkOutput(typeLinkInfo); |
duke@1 | 124 | ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength; |
duke@1 | 125 | return output; |
duke@1 | 126 | } |
duke@1 | 127 | |
duke@1 | 128 | /** |
duke@1 | 129 | * Given a class, return the appropriate tool tip. |
duke@1 | 130 | * |
duke@1 | 131 | * @param classDoc the class to get the tool tip for. |
duke@1 | 132 | * @return the tool tip for the appropriate class. |
duke@1 | 133 | */ |
duke@1 | 134 | private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) { |
duke@1 | 135 | Configuration configuration = ConfigurationImpl.getInstance(); |
duke@1 | 136 | if (isTypeLink) { |
duke@1 | 137 | return configuration.getText("doclet.Href_Type_Param_Title", |
duke@1 | 138 | classDoc.name()); |
duke@1 | 139 | } else if (classDoc.isInterface()){ |
duke@1 | 140 | return configuration.getText("doclet.Href_Interface_Title", |
duke@1 | 141 | Util.getPackageName(classDoc.containingPackage())); |
duke@1 | 142 | } else if (classDoc.isAnnotationType()) { |
duke@1 | 143 | return configuration.getText("doclet.Href_Annotation_Title", |
duke@1 | 144 | Util.getPackageName(classDoc.containingPackage())); |
duke@1 | 145 | } else if (classDoc.isEnum()) { |
duke@1 | 146 | return configuration.getText("doclet.Href_Enum_Title", |
duke@1 | 147 | Util.getPackageName(classDoc.containingPackage())); |
duke@1 | 148 | } else { |
duke@1 | 149 | return configuration.getText("doclet.Href_Class_Title", |
duke@1 | 150 | Util.getPackageName(classDoc.containingPackage())); |
duke@1 | 151 | } |
duke@1 | 152 | } |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * Return path to the given file name in the given package. So if the name |
duke@1 | 156 | * passed is "Object.html" and the name of the package is "java.lang", and |
duke@1 | 157 | * if the relative path is "../.." then returned string will be |
duke@1 | 158 | * "../../java/lang/Object.html" |
duke@1 | 159 | * |
duke@1 | 160 | * @param linkInfo the information about the link. |
duke@1 | 161 | * @param fileName the file name, to which path string is. |
duke@1 | 162 | */ |
duke@1 | 163 | private String pathString(LinkInfoImpl linkInfo) { |
duke@1 | 164 | if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) { |
duke@1 | 165 | //Not really necessary to do this but we want to be consistent |
duke@1 | 166 | //with 1.4.2 output. |
duke@1 | 167 | return linkInfo.classDoc.name() + ".html"; |
duke@1 | 168 | } |
duke@1 | 169 | StringBuffer buf = new StringBuffer(m_writer.relativePath); |
duke@1 | 170 | buf.append(DirectoryManager.getPathToPackage( |
duke@1 | 171 | linkInfo.classDoc.containingPackage(), |
duke@1 | 172 | linkInfo.classDoc.name() + ".html")); |
duke@1 | 173 | return buf.toString(); |
duke@1 | 174 | } |
duke@1 | 175 | } |