Tue, 14 May 2013 10:14:53 -0700
8011668: Allow HTMLWriter.getResource to take Content args
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 | */ |
bpatel@766 | 63 | protected int addTypeParameters(ExecutableMemberDoc member, Content htmltree) { |
jjg@1410 | 64 | LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, |
jjg@1738 | 65 | LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS, member); |
jjg@1736 | 66 | Content typeParameters = writer.getTypeParameterLinks(linkInfo); |
duke@1 | 67 | if (linkInfo.displayLength > 0) { |
jjg@1736 | 68 | Content linkContent = typeParameters; |
bpatel@766 | 69 | htmltree.addContent(linkContent); |
bpatel@766 | 70 | htmltree.addContent(writer.getSpace()); |
duke@1 | 71 | writer.displayLength += linkInfo.displayLength + 1; |
duke@1 | 72 | } |
duke@1 | 73 | return linkInfo.displayLength; |
duke@1 | 74 | } |
duke@1 | 75 | |
bpatel@766 | 76 | /** |
bpatel@766 | 77 | * {@inheritDoc} |
bpatel@766 | 78 | */ |
bpatel@766 | 79 | protected Content getDeprecatedLink(ProgramElementDoc member) { |
bpatel@766 | 80 | ExecutableMemberDoc emd = (ExecutableMemberDoc)member; |
jjg@1735 | 81 | return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, (MemberDoc) emd, |
bpatel@766 | 82 | emd.qualifiedName() + emd.flatSignature()); |
duke@1 | 83 | } |
duke@1 | 84 | |
bpatel@766 | 85 | /** |
bpatel@766 | 86 | * Add the summary link for the member. |
bpatel@766 | 87 | * |
bpatel@766 | 88 | * @param context the id of the context where the link will be printed |
jjg@1358 | 89 | * @param cd the classDoc that we should link to |
bpatel@766 | 90 | * @param member the member being linked to |
bpatel@766 | 91 | * @param tdSummary the content tree to which the link will be added |
bpatel@766 | 92 | */ |
jjg@1735 | 93 | protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, |
bpatel@766 | 94 | Content tdSummary) { |
duke@1 | 95 | ExecutableMemberDoc emd = (ExecutableMemberDoc)member; |
bpatel@766 | 96 | String name = emd.name(); |
jjg@1736 | 97 | Content strong = HtmlTree.STRONG( |
bpatel@766 | 98 | writer.getDocLink(context, cd, (MemberDoc) emd, |
jjg@1736 | 99 | name, false)); |
bpatel@766 | 100 | Content code = HtmlTree.CODE(strong); |
bpatel@766 | 101 | writer.displayLength = name.length(); |
bpatel@766 | 102 | addParameters(emd, false, code); |
bpatel@766 | 103 | tdSummary.addContent(code); |
duke@1 | 104 | } |
duke@1 | 105 | |
bpatel@766 | 106 | /** |
bpatel@766 | 107 | * Add the inherited summary link for the member. |
bpatel@766 | 108 | * |
jjg@1358 | 109 | * @param cd the classDoc that we should link to |
bpatel@766 | 110 | * @param member the member being linked to |
bpatel@766 | 111 | * @param linksTree the content tree to which the link will be added |
bpatel@766 | 112 | */ |
bpatel@766 | 113 | protected void addInheritedSummaryLink(ClassDoc cd, |
bpatel@766 | 114 | ProgramElementDoc member, Content linksTree) { |
jjg@1736 | 115 | linksTree.addContent( |
jjg@1735 | 116 | writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc) member, |
jjg@1736 | 117 | member.name(), false)); |
duke@1 | 118 | } |
duke@1 | 119 | |
bpatel@766 | 120 | /** |
bpatel@766 | 121 | * Add the parameter for the executable member. |
bpatel@766 | 122 | * |
bpatel@766 | 123 | * @param member the member to write parameter for. |
bpatel@766 | 124 | * @param param the parameter that needs to be written. |
bpatel@766 | 125 | * @param isVarArg true if this is a link to var arg. |
bpatel@766 | 126 | * @param tree the content tree to which the parameter information will be added. |
bpatel@766 | 127 | */ |
bpatel@766 | 128 | protected void addParam(ExecutableMemberDoc member, Parameter param, |
jjg@1737 | 129 | boolean isVarArg, Content tree) { |
duke@1 | 130 | if (param.type() != null) { |
jjg@1736 | 131 | Content link = writer.getLink(new LinkInfoImpl( |
jjg@1735 | 132 | configuration, LinkInfoImpl.Kind.EXECUTABLE_MEMBER_PARAM, |
jjg@1738 | 133 | param.type()).varargs(isVarArg)); |
bpatel@766 | 134 | tree.addContent(link); |
duke@1 | 135 | } |
duke@1 | 136 | if(param.name().length() > 0) { |
bpatel@766 | 137 | tree.addContent(writer.getSpace()); |
bpatel@766 | 138 | tree.addContent(param.name()); |
duke@1 | 139 | } |
duke@1 | 140 | } |
duke@1 | 141 | |
bpatel@1686 | 142 | /** |
bpatel@1686 | 143 | * Add the receiver annotations information. |
bpatel@1686 | 144 | * |
bpatel@1686 | 145 | * @param member the member to write receiver annotations for. |
bpatel@1686 | 146 | * @param rcvrType the receiver type. |
bpatel@1686 | 147 | * @param descList list of annotation description. |
bpatel@1686 | 148 | * @param tree the content tree to which the information will be added. |
bpatel@1686 | 149 | */ |
bpatel@1686 | 150 | protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType, |
bpatel@1686 | 151 | AnnotationDesc[] descList, Content tree) { |
bpatel@1686 | 152 | writer.addReceiverAnnotationInfo(member, descList, tree); |
bpatel@1686 | 153 | tree.addContent(writer.getSpace()); |
bpatel@1686 | 154 | tree.addContent(rcvrType.typeName()); |
bpatel@1686 | 155 | LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, |
jjg@1735 | 156 | LinkInfoImpl.Kind.CLASS_SIGNATURE, rcvrType); |
jjg@1736 | 157 | tree.addContent(writer.getTypeParameterLinks(linkInfo)); |
bpatel@1686 | 158 | tree.addContent(writer.getSpace()); |
bpatel@1686 | 159 | tree.addContent("this"); |
jjg@1521 | 160 | } |
jjg@1521 | 161 | |
jjg@1521 | 162 | |
bpatel@766 | 163 | /** |
bpatel@766 | 164 | * Add all the parameters for the executable member. |
bpatel@766 | 165 | * |
bpatel@766 | 166 | * @param member the member to write parameters for. |
jjg@1358 | 167 | * @param htmltree the content tree to which the parameters information will be added. |
bpatel@766 | 168 | */ |
bpatel@766 | 169 | protected void addParameters(ExecutableMemberDoc member, Content htmltree) { |
bpatel@766 | 170 | addParameters(member, true, htmltree); |
duke@1 | 171 | } |
duke@1 | 172 | |
bpatel@766 | 173 | /** |
bpatel@766 | 174 | * Add all the parameters for the executable member. |
bpatel@766 | 175 | * |
bpatel@766 | 176 | * @param member the member to write parameters for. |
bpatel@766 | 177 | * @param includeAnnotations true if annotation information needs to be added. |
jjg@1358 | 178 | * @param htmltree the content tree to which the parameters information will be added. |
bpatel@766 | 179 | */ |
bpatel@766 | 180 | protected void addParameters(ExecutableMemberDoc member, |
bpatel@766 | 181 | boolean includeAnnotations, Content htmltree) { |
bpatel@766 | 182 | htmltree.addContent("("); |
bpatel@1686 | 183 | String sep = ""; |
duke@1 | 184 | Parameter[] params = member.parameters(); |
duke@1 | 185 | String indent = makeSpace(writer.displayLength); |
jjg@1410 | 186 | if (configuration.linksource) { |
duke@1 | 187 | //add spaces to offset indentation changes caused by link. |
duke@1 | 188 | indent+= makeSpace(member.name().length()); |
duke@1 | 189 | } |
bpatel@1686 | 190 | Type rcvrType = member.receiverType(); |
bpatel@1686 | 191 | if (includeAnnotations && rcvrType instanceof AnnotatedType) { |
bpatel@1686 | 192 | AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations(); |
bpatel@1686 | 193 | if (descList.length > 0) { |
bpatel@1686 | 194 | addReceiverAnnotations(member, rcvrType, descList, htmltree); |
bpatel@1686 | 195 | sep = "," + DocletConstants.NL + indent; |
bpatel@1686 | 196 | } |
bpatel@1686 | 197 | } |
duke@1 | 198 | int paramstart; |
duke@1 | 199 | for (paramstart = 0; paramstart < params.length; paramstart++) { |
bpatel@1686 | 200 | htmltree.addContent(sep); |
duke@1 | 201 | Parameter param = params[paramstart]; |
duke@1 | 202 | if (!param.name().startsWith("this$")) { |
duke@1 | 203 | if (includeAnnotations) { |
bpatel@766 | 204 | boolean foundAnnotations = |
bpatel@766 | 205 | writer.addAnnotationInfo(indent.length(), |
bpatel@766 | 206 | member, param, htmltree); |
bpatel@766 | 207 | if (foundAnnotations) { |
bpatel@766 | 208 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 209 | htmltree.addContent(indent); |
duke@1 | 210 | } |
duke@1 | 211 | } |
bpatel@766 | 212 | addParam(member, param, |
bpatel@766 | 213 | (paramstart == params.length - 1) && member.isVarArgs(), htmltree); |
duke@1 | 214 | break; |
duke@1 | 215 | } |
duke@1 | 216 | } |
duke@1 | 217 | |
duke@1 | 218 | for (int i = paramstart + 1; i < params.length; i++) { |
bpatel@766 | 219 | htmltree.addContent(","); |
bpatel@766 | 220 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 221 | htmltree.addContent(indent); |
duke@1 | 222 | if (includeAnnotations) { |
duke@1 | 223 | boolean foundAnnotations = |
bpatel@766 | 224 | writer.addAnnotationInfo(indent.length(), member, params[i], |
bpatel@766 | 225 | htmltree); |
duke@1 | 226 | if (foundAnnotations) { |
bpatel@766 | 227 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 228 | htmltree.addContent(indent); |
duke@1 | 229 | } |
duke@1 | 230 | } |
bpatel@766 | 231 | addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(), |
bpatel@766 | 232 | htmltree); |
duke@1 | 233 | } |
bpatel@766 | 234 | htmltree.addContent(")"); |
duke@1 | 235 | } |
duke@1 | 236 | |
bpatel@766 | 237 | /** |
bpatel@766 | 238 | * Add exceptions for the executable member. |
bpatel@766 | 239 | * |
bpatel@766 | 240 | * @param member the member to write exceptions for. |
bpatel@766 | 241 | * @param htmltree the content tree to which the exceptions information will be added. |
bpatel@766 | 242 | */ |
bpatel@766 | 243 | protected void addExceptions(ExecutableMemberDoc member, Content htmltree) { |
duke@1 | 244 | Type[] exceptions = member.thrownExceptionTypes(); |
duke@1 | 245 | if(exceptions.length > 0) { |
jjg@1410 | 246 | LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration, |
jjg@1738 | 247 | LinkInfoImpl.Kind.MEMBER, member); |
duke@1 | 248 | int retlen = getReturnTypeLength(member); |
duke@1 | 249 | writer.getTypeParameterLinks(memberTypeParam); |
duke@1 | 250 | retlen += memberTypeParam.displayLength == 0 ? |
duke@1 | 251 | 0 : memberTypeParam.displayLength + 1; |
duke@1 | 252 | String indent = makeSpace(modifierString(member).length() + |
bpatel@766 | 253 | member.name().length() + retlen - 4); |
bpatel@766 | 254 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 255 | htmltree.addContent(indent); |
bpatel@766 | 256 | htmltree.addContent("throws "); |
duke@1 | 257 | indent += " "; |
jjg@1736 | 258 | Content link = writer.getLink(new LinkInfoImpl(configuration, |
jjg@1736 | 259 | LinkInfoImpl.Kind.MEMBER, exceptions[0])); |
bpatel@766 | 260 | htmltree.addContent(link); |
duke@1 | 261 | for(int i = 1; i < exceptions.length; i++) { |
bpatel@766 | 262 | htmltree.addContent(","); |
bpatel@766 | 263 | htmltree.addContent(DocletConstants.NL); |
bpatel@766 | 264 | htmltree.addContent(indent); |
jjg@1736 | 265 | Content exceptionLink = writer.getLink(new LinkInfoImpl( |
jjg@1736 | 266 | configuration, LinkInfoImpl.Kind.MEMBER, exceptions[i])); |
bpatel@766 | 267 | htmltree.addContent(exceptionLink); |
duke@1 | 268 | } |
duke@1 | 269 | } |
duke@1 | 270 | } |
duke@1 | 271 | |
duke@1 | 272 | protected int getReturnTypeLength(ExecutableMemberDoc member) { |
duke@1 | 273 | if (member instanceof MethodDoc) { |
duke@1 | 274 | MethodDoc method = (MethodDoc)member; |
duke@1 | 275 | Type rettype = method.returnType(); |
duke@1 | 276 | if (rettype.isPrimitive()) { |
duke@1 | 277 | return rettype.typeName().length() + |
duke@1 | 278 | rettype.dimension().length(); |
duke@1 | 279 | } else { |
jjg@1410 | 280 | LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, |
jjg@1735 | 281 | LinkInfoImpl.Kind.MEMBER, rettype); |
duke@1 | 282 | writer.getLink(linkInfo); |
duke@1 | 283 | return linkInfo.displayLength; |
duke@1 | 284 | } |
duke@1 | 285 | } else { // it's a constructordoc |
duke@1 | 286 | return -1; |
duke@1 | 287 | } |
duke@1 | 288 | } |
duke@1 | 289 | |
duke@1 | 290 | protected ClassDoc implementsMethodInIntfac(MethodDoc method, |
duke@1 | 291 | ClassDoc[] intfacs) { |
duke@1 | 292 | for (int i = 0; i < intfacs.length; i++) { |
duke@1 | 293 | MethodDoc[] methods = intfacs[i].methods(); |
duke@1 | 294 | if (methods.length > 0) { |
duke@1 | 295 | for (int j = 0; j < methods.length; j++) { |
duke@1 | 296 | if (methods[j].name().equals(method.name()) && |
duke@1 | 297 | methods[j].signature().equals(method.signature())) { |
duke@1 | 298 | return intfacs[i]; |
duke@1 | 299 | } |
duke@1 | 300 | } |
duke@1 | 301 | } |
duke@1 | 302 | } |
duke@1 | 303 | return null; |
duke@1 | 304 | } |
duke@1 | 305 | |
duke@1 | 306 | /** |
duke@1 | 307 | * For backward compatibility, include an anchor using the erasures of the |
duke@1 | 308 | * parameters. NOTE: We won't need this method anymore after we fix |
duke@1 | 309 | * see tags so that they use the type instead of the erasure. |
duke@1 | 310 | * |
duke@1 | 311 | * @param emd the ExecutableMemberDoc to anchor to. |
duke@1 | 312 | * @return the 1.4.x style anchor for the ExecutableMemberDoc. |
duke@1 | 313 | */ |
duke@1 | 314 | protected String getErasureAnchor(ExecutableMemberDoc emd) { |
jjg@1362 | 315 | StringBuilder buf = new StringBuilder(emd.name() + "("); |
duke@1 | 316 | Parameter[] params = emd.parameters(); |
duke@1 | 317 | boolean foundTypeVariable = false; |
duke@1 | 318 | for (int i = 0; i < params.length; i++) { |
duke@1 | 319 | if (i > 0) { |
duke@1 | 320 | buf.append(","); |
duke@1 | 321 | } |
duke@1 | 322 | Type t = params[i].type(); |
duke@1 | 323 | foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; |
duke@1 | 324 | buf.append(t.isPrimitive() ? |
duke@1 | 325 | t.typeName() : t.asClassDoc().qualifiedName()); |
duke@1 | 326 | buf.append(t.dimension()); |
duke@1 | 327 | } |
duke@1 | 328 | buf.append(")"); |
duke@1 | 329 | return foundTypeVariable ? buf.toString() : null; |
duke@1 | 330 | } |
duke@1 | 331 | } |