Tue, 14 May 2013 10:14:54 -0700
8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1521 | 2 | * Copyright (c) 1997, 2013, 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.javadoc.*; |
bpatel@766 | 29 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 30 | import com.sun.tools.doclets.internal.toolkit.*; |
bpatel@766 | 31 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 32 | |
duke@1 | 33 | /** |
duke@1 | 34 | * Print method and constructor info. |
duke@1 | 35 | * |
jjg@1359 | 36 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 37 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 38 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 39 | * deletion without notice.</b> |
jjg@1359 | 40 | * |
duke@1 | 41 | * @author Robert Field |
duke@1 | 42 | * @author Atul M Dambalkar |
bpatel@766 | 43 | * @author Bhavesh Patel (Modified) |
duke@1 | 44 | */ |
duke@1 | 45 | public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter { |
duke@1 | 46 | |
duke@1 | 47 | public AbstractExecutableMemberWriter(SubWriterHolderWriter writer, |
jjg@1410 | 48 | ClassDoc classdoc) { |
duke@1 | 49 | super(writer, classdoc); |
duke@1 | 50 | } |
duke@1 | 51 | |
duke@1 | 52 | public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { |
duke@1 | 53 | super(writer); |
duke@1 | 54 | } |
duke@1 | 55 | |
duke@1 | 56 | /** |
bpatel@766 | 57 | * Add the type parameters for the executable member. |
duke@1 | 58 | * |
duke@1 | 59 | * @param member the member to write type parameters for. |
bpatel@766 | 60 | * @param htmltree the content tree to which the parameters will be added. |
duke@1 | 61 | * @return the display length required to write this information. |
duke@1 | 62 | */ |
jjg@1741 | 63 | protected void addTypeParameters(ExecutableMemberDoc member, Content htmltree) { |
jjg@1741 | 64 | Content typeParameters = getTypeParameters(member); |
jjg@1741 | 65 | if (!typeParameters.isEmpty()) { |
jjg@1741 | 66 | htmltree.addContent(typeParameters); |
jjg@1741 | 67 | htmltree.addContent(writer.getSpace()); |
jjg@1741 | 68 | } |
jjg@1741 | 69 | } |
jjg@1741 | 70 | |
jjg@1741 | 71 | /** |
jjg@1741 | 72 | * Get the type parameters for the executable member. |
jjg@1741 | 73 | * |
jjg@1741 | 74 | * @param member the member for which to get the type parameters. |
jjg@1741 | 75 | * @return the type parameters. |
jjg@1741 | 76 | */ |
jjg@1741 | 77 | protected Content getTypeParameters(ExecutableMemberDoc member) { |
jjg@1410 | 78 | LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, |
jjg@1738 | 79 | LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS, member); |
jjg@1741 | 80 | return writer.getTypeParameterLinks(linkInfo); |
duke@1 | 81 | } |
duke@1 | 82 | |
bpatel@766 | 83 | /** |
bpatel@766 | 84 | * {@inheritDoc} |
bpatel@766 | 85 | */ |
bpatel@766 | 86 | protected Content getDeprecatedLink(ProgramElementDoc member) { |
bpatel@766 | 87 | ExecutableMemberDoc emd = (ExecutableMemberDoc)member; |
jjg@1735 | 88 | return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, (MemberDoc) emd, |
bpatel@766 | 89 | emd.qualifiedName() + emd.flatSignature()); |
duke@1 | 90 | } |
duke@1 | 91 | |
bpatel@766 | 92 | /** |
bpatel@766 | 93 | * Add the summary link for the member. |
bpatel@766 | 94 | * |
bpatel@766 | 95 | * @param context the id of the context where the link will be printed |
jjg@1358 | 96 | * @param cd the classDoc that we should link to |
bpatel@766 | 97 | * @param member the member being linked to |
bpatel@766 | 98 | * @param tdSummary the content tree to which the link will be added |
bpatel@766 | 99 | */ |
jjg@1735 | 100 | protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, |
bpatel@766 | 101 | Content tdSummary) { |
duke@1 | 102 | ExecutableMemberDoc emd = (ExecutableMemberDoc)member; |
bpatel@766 | 103 | String name = emd.name(); |
jjg@1736 | 104 | Content strong = HtmlTree.STRONG( |
bpatel@766 | 105 | writer.getDocLink(context, cd, (MemberDoc) emd, |
jjg@1736 | 106 | name, false)); |
bpatel@766 | 107 | Content code = HtmlTree.CODE(strong); |
jjg@1741 | 108 | addParameters(emd, false, code, name.length() - 1); |
bpatel@766 | 109 | tdSummary.addContent(code); |
duke@1 | 110 | } |
duke@1 | 111 | |
bpatel@766 | 112 | /** |
bpatel@766 | 113 | * Add the inherited summary link for the member. |
bpatel@766 | 114 | * |
jjg@1358 | 115 | * @param cd the classDoc that we should link to |
bpatel@766 | 116 | * @param member the member being linked to |
bpatel@766 | 117 | * @param linksTree the content tree to which the link will be added |
bpatel@766 | 118 | */ |
bpatel@766 | 119 | protected void addInheritedSummaryLink(ClassDoc cd, |
bpatel@766 | 120 | ProgramElementDoc member, Content linksTree) { |
jjg@1736 | 121 | linksTree.addContent( |
jjg@1735 | 122 | writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc) member, |
jjg@1736 | 123 | member.name(), false)); |
duke@1 | 124 | } |
duke@1 | 125 | |
bpatel@766 | 126 | /** |
bpatel@766 | 127 | * Add the parameter for the executable member. |
bpatel@766 | 128 | * |
bpatel@766 | 129 | * @param member the member to write parameter for. |
bpatel@766 | 130 | * @param param the parameter that needs to be written. |
bpatel@766 | 131 | * @param isVarArg true if this is a link to var arg. |
bpatel@766 | 132 | * @param tree the content tree to which the parameter information will be added. |
bpatel@766 | 133 | */ |
bpatel@766 | 134 | protected void addParam(ExecutableMemberDoc member, Parameter param, |
jjg@1737 | 135 | boolean isVarArg, Content tree) { |
duke@1 | 136 | if (param.type() != null) { |
jjg@1736 | 137 | Content link = writer.getLink(new LinkInfoImpl( |
jjg@1735 | 138 | configuration, LinkInfoImpl.Kind.EXECUTABLE_MEMBER_PARAM, |
jjg@1738 | 139 | param.type()).varargs(isVarArg)); |
bpatel@766 | 140 | tree.addContent(link); |
duke@1 | 141 | } |
duke@1 | 142 | if(param.name().length() > 0) { |
bpatel@766 | 143 | tree.addContent(writer.getSpace()); |
bpatel@766 | 144 | tree.addContent(param.name()); |
duke@1 | 145 | } |
duke@1 | 146 | } |
duke@1 | 147 | |
bpatel@1686 | 148 | /** |
bpatel@1686 | 149 | * Add the receiver annotations information. |
bpatel@1686 | 150 | * |
bpatel@1686 | 151 | * @param member the member to write receiver annotations for. |
bpatel@1686 | 152 | * @param rcvrType the receiver type. |
bpatel@1686 | 153 | * @param descList list of annotation description. |
bpatel@1686 | 154 | * @param tree the content tree to which the information will be added. |
bpatel@1686 | 155 | */ |
bpatel@1686 | 156 | protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType, |
bpatel@1686 | 157 | AnnotationDesc[] descList, Content tree) { |
bpatel@1686 | 158 | writer.addReceiverAnnotationInfo(member, descList, tree); |
bpatel@1686 | 159 | tree.addContent(writer.getSpace()); |
bpatel@1686 | 160 | tree.addContent(rcvrType.typeName()); |
bpatel@1686 | 161 | LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, |
jjg@1735 | 162 | LinkInfoImpl.Kind.CLASS_SIGNATURE, rcvrType); |
jjg@1736 | 163 | tree.addContent(writer.getTypeParameterLinks(linkInfo)); |
bpatel@1686 | 164 | tree.addContent(writer.getSpace()); |
bpatel@1686 | 165 | tree.addContent("this"); |
jjg@1521 | 166 | } |
jjg@1521 | 167 | |
jjg@1521 | 168 | |
bpatel@766 | 169 | /** |
bpatel@766 | 170 | * Add all the parameters for the executable member. |
bpatel@766 | 171 | * |
bpatel@766 | 172 | * @param member the member to write parameters for. |
jjg@1358 | 173 | * @param htmltree the content tree to which the parameters information will be added. |
bpatel@766 | 174 | */ |
jjg@1741 | 175 | protected void addParameters(ExecutableMemberDoc member, Content htmltree, int indentSize) { |
jjg@1741 | 176 | addParameters(member, true, htmltree, indentSize); |
duke@1 | 177 | } |
duke@1 | 178 | |
bpatel@766 | 179 | /** |
bpatel@766 | 180 | * Add all the parameters for the executable member. |
bpatel@766 | 181 | * |
bpatel@766 | 182 | * @param member the member to write parameters for. |
bpatel@766 | 183 | * @param includeAnnotations true if annotation information needs to be added. |
jjg@1358 | 184 | * @param htmltree the content tree to which the parameters information will be added. |
bpatel@766 | 185 | */ |
bpatel@766 | 186 | protected void addParameters(ExecutableMemberDoc member, |
jjg@1741 | 187 | boolean includeAnnotations, Content htmltree, int indentSize) { |
bpatel@766 | 188 | htmltree.addContent("("); |
bpatel@1686 | 189 | String sep = ""; |
duke@1 | 190 | Parameter[] params = member.parameters(); |
jjg@1741 | 191 | String indent = makeSpace(indentSize + 1); |
bpatel@1686 | 192 | Type rcvrType = member.receiverType(); |
bpatel@1686 | 193 | if (includeAnnotations && rcvrType instanceof AnnotatedType) { |
bpatel@1686 | 194 | AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations(); |
bpatel@1686 | 195 | if (descList.length > 0) { |
bpatel@1686 | 196 | addReceiverAnnotations(member, rcvrType, descList, htmltree); |
bpatel@1686 | 197 | sep = "," + DocletConstants.NL + indent; |
bpatel@1686 | 198 | } |
bpatel@1686 | 199 | } |
duke@1 | 200 | int paramstart; |
duke@1 | 201 | for (paramstart = 0; paramstart < params.length; paramstart++) { |
bpatel@1686 | 202 | htmltree.addContent(sep); |
duke@1 | 203 | Parameter param = params[paramstart]; |
duke@1 | 204 | if (!param.name().startsWith("this$")) { |
duke@1 | 205 | if (includeAnnotations) { |
bpatel@766 | 206 | boolean foundAnnotations = |
bpatel@766 | 207 | writer.addAnnotationInfo(indent.length(), |
bpatel@766 | 208 | member, param, htmltree); |
bpatel@766 | 209 | if (foundAnnotations) { |
bpatel@766 | 210 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 211 | htmltree.addContent(indent); |
duke@1 | 212 | } |
duke@1 | 213 | } |
bpatel@766 | 214 | addParam(member, param, |
bpatel@766 | 215 | (paramstart == params.length - 1) && member.isVarArgs(), htmltree); |
duke@1 | 216 | break; |
duke@1 | 217 | } |
duke@1 | 218 | } |
duke@1 | 219 | |
duke@1 | 220 | for (int i = paramstart + 1; i < params.length; i++) { |
bpatel@766 | 221 | htmltree.addContent(","); |
bpatel@766 | 222 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 223 | htmltree.addContent(indent); |
duke@1 | 224 | if (includeAnnotations) { |
duke@1 | 225 | boolean foundAnnotations = |
bpatel@766 | 226 | writer.addAnnotationInfo(indent.length(), member, params[i], |
bpatel@766 | 227 | htmltree); |
duke@1 | 228 | if (foundAnnotations) { |
bpatel@766 | 229 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 230 | htmltree.addContent(indent); |
duke@1 | 231 | } |
duke@1 | 232 | } |
bpatel@766 | 233 | addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(), |
bpatel@766 | 234 | htmltree); |
duke@1 | 235 | } |
bpatel@766 | 236 | htmltree.addContent(")"); |
duke@1 | 237 | } |
duke@1 | 238 | |
bpatel@766 | 239 | /** |
bpatel@766 | 240 | * Add exceptions for the executable member. |
bpatel@766 | 241 | * |
bpatel@766 | 242 | * @param member the member to write exceptions for. |
bpatel@766 | 243 | * @param htmltree the content tree to which the exceptions information will be added. |
bpatel@766 | 244 | */ |
jjg@1741 | 245 | protected void addExceptions(ExecutableMemberDoc member, Content htmltree, int indentSize) { |
duke@1 | 246 | Type[] exceptions = member.thrownExceptionTypes(); |
jjg@1741 | 247 | if (exceptions.length > 0) { |
jjg@1410 | 248 | LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration, |
jjg@1738 | 249 | LinkInfoImpl.Kind.MEMBER, member); |
jjg@1741 | 250 | String indent = makeSpace(indentSize + 1 - 7); |
bpatel@766 | 251 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 252 | htmltree.addContent(indent); |
bpatel@766 | 253 | htmltree.addContent("throws "); |
jjg@1741 | 254 | indent = makeSpace(indentSize + 1); |
jjg@1736 | 255 | Content link = writer.getLink(new LinkInfoImpl(configuration, |
jjg@1736 | 256 | LinkInfoImpl.Kind.MEMBER, exceptions[0])); |
bpatel@766 | 257 | htmltree.addContent(link); |
duke@1 | 258 | for(int i = 1; i < exceptions.length; i++) { |
bpatel@766 | 259 | htmltree.addContent(","); |
bpatel@766 | 260 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 261 | htmltree.addContent(indent); |
jjg@1736 | 262 | Content exceptionLink = writer.getLink(new LinkInfoImpl( |
jjg@1736 | 263 | configuration, LinkInfoImpl.Kind.MEMBER, exceptions[i])); |
bpatel@766 | 264 | htmltree.addContent(exceptionLink); |
duke@1 | 265 | } |
duke@1 | 266 | } |
duke@1 | 267 | } |
duke@1 | 268 | |
duke@1 | 269 | protected ClassDoc implementsMethodInIntfac(MethodDoc method, |
duke@1 | 270 | ClassDoc[] intfacs) { |
duke@1 | 271 | for (int i = 0; i < intfacs.length; i++) { |
duke@1 | 272 | MethodDoc[] methods = intfacs[i].methods(); |
duke@1 | 273 | if (methods.length > 0) { |
duke@1 | 274 | for (int j = 0; j < methods.length; j++) { |
duke@1 | 275 | if (methods[j].name().equals(method.name()) && |
duke@1 | 276 | methods[j].signature().equals(method.signature())) { |
duke@1 | 277 | return intfacs[i]; |
duke@1 | 278 | } |
duke@1 | 279 | } |
duke@1 | 280 | } |
duke@1 | 281 | } |
duke@1 | 282 | return null; |
duke@1 | 283 | } |
duke@1 | 284 | |
duke@1 | 285 | /** |
duke@1 | 286 | * For backward compatibility, include an anchor using the erasures of the |
duke@1 | 287 | * parameters. NOTE: We won't need this method anymore after we fix |
duke@1 | 288 | * see tags so that they use the type instead of the erasure. |
duke@1 | 289 | * |
duke@1 | 290 | * @param emd the ExecutableMemberDoc to anchor to. |
duke@1 | 291 | * @return the 1.4.x style anchor for the ExecutableMemberDoc. |
duke@1 | 292 | */ |
duke@1 | 293 | protected String getErasureAnchor(ExecutableMemberDoc emd) { |
jjg@1362 | 294 | StringBuilder buf = new StringBuilder(emd.name() + "("); |
duke@1 | 295 | Parameter[] params = emd.parameters(); |
duke@1 | 296 | boolean foundTypeVariable = false; |
duke@1 | 297 | for (int i = 0; i < params.length; i++) { |
duke@1 | 298 | if (i > 0) { |
duke@1 | 299 | buf.append(","); |
duke@1 | 300 | } |
duke@1 | 301 | Type t = params[i].type(); |
duke@1 | 302 | foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; |
duke@1 | 303 | buf.append(t.isPrimitive() ? |
duke@1 | 304 | t.typeName() : t.asClassDoc().qualifiedName()); |
duke@1 | 305 | buf.append(t.dimension()); |
duke@1 | 306 | } |
duke@1 | 307 | buf.append(")"); |
duke@1 | 308 | return foundTypeVariable ? buf.toString() : null; |
duke@1 | 309 | } |
duke@1 | 310 | } |