src/share/classes/com/sun/tools/doclets/formats/html/AbstractExecutableMemberWriter.java

Thu, 15 Nov 2012 19:54:20 -0800

author
jjg
date
Thu, 15 Nov 2012 19:54:20 -0800
changeset 1412
400a4e8accd3
parent 1410
bfec2a1cc869
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy

duke@1 1 /*
jjg@1358 2 * Copyright (c) 1997, 2012, 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,
duke@1 65 LinkInfoImpl.CONTEXT_MEMBER_TYPE_PARAMS, member, false);
duke@1 66 String typeParameters = writer.getTypeParameterLinks(linkInfo);
duke@1 67 if (linkInfo.displayLength > 0) {
bpatel@766 68 Content linkContent = new RawHtml(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;
bpatel@766 81 return writer.getDocLink(LinkInfoImpl.CONTEXT_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 */
bpatel@766 93 protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
bpatel@766 94 Content tdSummary) {
duke@1 95 ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
bpatel@766 96 String name = emd.name();
bpatel@766 97 Content strong = HtmlTree.STRONG(new RawHtml(
bpatel@766 98 writer.getDocLink(context, cd, (MemberDoc) emd,
bpatel@766 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) {
bpatel@766 115 linksTree.addContent(new RawHtml(
bpatel@766 116 writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc) member,
bpatel@766 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,
bpatel@766 129 boolean isVarArg, Content tree) {
duke@1 130 if (param.type() != null) {
bpatel@766 131 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(
jjg@1410 132 configuration, LinkInfoImpl.CONTEXT_EXECUTABLE_MEMBER_PARAM,
jjg@1410 133 param.type(), 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@766 142 /**
bpatel@766 143 * Add all the parameters for the executable member.
bpatel@766 144 *
bpatel@766 145 * @param member the member to write parameters for.
jjg@1358 146 * @param htmltree the content tree to which the parameters information will be added.
bpatel@766 147 */
bpatel@766 148 protected void addParameters(ExecutableMemberDoc member, Content htmltree) {
bpatel@766 149 addParameters(member, true, htmltree);
duke@1 150 }
duke@1 151
bpatel@766 152 /**
bpatel@766 153 * Add all the parameters for the executable member.
bpatel@766 154 *
bpatel@766 155 * @param member the member to write parameters for.
bpatel@766 156 * @param includeAnnotations true if annotation information needs to be added.
jjg@1358 157 * @param htmltree the content tree to which the parameters information will be added.
bpatel@766 158 */
bpatel@766 159 protected void addParameters(ExecutableMemberDoc member,
bpatel@766 160 boolean includeAnnotations, Content htmltree) {
bpatel@766 161 htmltree.addContent("(");
duke@1 162 Parameter[] params = member.parameters();
duke@1 163 String indent = makeSpace(writer.displayLength);
jjg@1410 164 if (configuration.linksource) {
duke@1 165 //add spaces to offset indentation changes caused by link.
duke@1 166 indent+= makeSpace(member.name().length());
duke@1 167 }
duke@1 168 int paramstart;
duke@1 169 for (paramstart = 0; paramstart < params.length; paramstart++) {
duke@1 170 Parameter param = params[paramstart];
duke@1 171 if (!param.name().startsWith("this$")) {
duke@1 172 if (includeAnnotations) {
bpatel@766 173 boolean foundAnnotations =
bpatel@766 174 writer.addAnnotationInfo(indent.length(),
bpatel@766 175 member, param, htmltree);
bpatel@766 176 if (foundAnnotations) {
bpatel@766 177 htmltree.addContent(DocletConstants.NL);
bpatel@766 178 htmltree.addContent(indent);
duke@1 179 }
duke@1 180 }
bpatel@766 181 addParam(member, param,
bpatel@766 182 (paramstart == params.length - 1) && member.isVarArgs(), htmltree);
duke@1 183 break;
duke@1 184 }
duke@1 185 }
duke@1 186
duke@1 187 for (int i = paramstart + 1; i < params.length; i++) {
bpatel@766 188 htmltree.addContent(",");
bpatel@766 189 htmltree.addContent(DocletConstants.NL);
bpatel@766 190 htmltree.addContent(indent);
duke@1 191 if (includeAnnotations) {
duke@1 192 boolean foundAnnotations =
bpatel@766 193 writer.addAnnotationInfo(indent.length(), member, params[i],
bpatel@766 194 htmltree);
duke@1 195 if (foundAnnotations) {
bpatel@766 196 htmltree.addContent(DocletConstants.NL);
bpatel@766 197 htmltree.addContent(indent);
duke@1 198 }
duke@1 199 }
bpatel@766 200 addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(),
bpatel@766 201 htmltree);
duke@1 202 }
bpatel@766 203 htmltree.addContent(")");
duke@1 204 }
duke@1 205
bpatel@766 206 /**
bpatel@766 207 * Add exceptions for the executable member.
bpatel@766 208 *
bpatel@766 209 * @param member the member to write exceptions for.
bpatel@766 210 * @param htmltree the content tree to which the exceptions information will be added.
bpatel@766 211 */
bpatel@766 212 protected void addExceptions(ExecutableMemberDoc member, Content htmltree) {
duke@1 213 Type[] exceptions = member.thrownExceptionTypes();
duke@1 214 if(exceptions.length > 0) {
jjg@1410 215 LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration,
bpatel@766 216 LinkInfoImpl.CONTEXT_MEMBER, member, false);
duke@1 217 int retlen = getReturnTypeLength(member);
duke@1 218 writer.getTypeParameterLinks(memberTypeParam);
duke@1 219 retlen += memberTypeParam.displayLength == 0 ?
duke@1 220 0 : memberTypeParam.displayLength + 1;
duke@1 221 String indent = makeSpace(modifierString(member).length() +
bpatel@766 222 member.name().length() + retlen - 4);
bpatel@766 223 htmltree.addContent(DocletConstants.NL);
bpatel@766 224 htmltree.addContent(indent);
bpatel@766 225 htmltree.addContent("throws ");
duke@1 226 indent += " ";
jjg@1410 227 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(configuration,
bpatel@766 228 LinkInfoImpl.CONTEXT_MEMBER, exceptions[0])));
bpatel@766 229 htmltree.addContent(link);
duke@1 230 for(int i = 1; i < exceptions.length; i++) {
bpatel@766 231 htmltree.addContent(",");
bpatel@766 232 htmltree.addContent(DocletConstants.NL);
bpatel@766 233 htmltree.addContent(indent);
bpatel@766 234 Content exceptionLink = new RawHtml(writer.getLink(new LinkInfoImpl(
jjg@1410 235 configuration, LinkInfoImpl.CONTEXT_MEMBER, exceptions[i])));
bpatel@766 236 htmltree.addContent(exceptionLink);
duke@1 237 }
duke@1 238 }
duke@1 239 }
duke@1 240
duke@1 241 protected int getReturnTypeLength(ExecutableMemberDoc member) {
duke@1 242 if (member instanceof MethodDoc) {
duke@1 243 MethodDoc method = (MethodDoc)member;
duke@1 244 Type rettype = method.returnType();
duke@1 245 if (rettype.isPrimitive()) {
duke@1 246 return rettype.typeName().length() +
duke@1 247 rettype.dimension().length();
duke@1 248 } else {
jjg@1410 249 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
duke@1 250 LinkInfoImpl.CONTEXT_MEMBER, rettype);
duke@1 251 writer.getLink(linkInfo);
duke@1 252 return linkInfo.displayLength;
duke@1 253 }
duke@1 254 } else { // it's a constructordoc
duke@1 255 return -1;
duke@1 256 }
duke@1 257 }
duke@1 258
duke@1 259 protected ClassDoc implementsMethodInIntfac(MethodDoc method,
duke@1 260 ClassDoc[] intfacs) {
duke@1 261 for (int i = 0; i < intfacs.length; i++) {
duke@1 262 MethodDoc[] methods = intfacs[i].methods();
duke@1 263 if (methods.length > 0) {
duke@1 264 for (int j = 0; j < methods.length; j++) {
duke@1 265 if (methods[j].name().equals(method.name()) &&
duke@1 266 methods[j].signature().equals(method.signature())) {
duke@1 267 return intfacs[i];
duke@1 268 }
duke@1 269 }
duke@1 270 }
duke@1 271 }
duke@1 272 return null;
duke@1 273 }
duke@1 274
duke@1 275 /**
duke@1 276 * For backward compatibility, include an anchor using the erasures of the
duke@1 277 * parameters. NOTE: We won't need this method anymore after we fix
duke@1 278 * see tags so that they use the type instead of the erasure.
duke@1 279 *
duke@1 280 * @param emd the ExecutableMemberDoc to anchor to.
duke@1 281 * @return the 1.4.x style anchor for the ExecutableMemberDoc.
duke@1 282 */
duke@1 283 protected String getErasureAnchor(ExecutableMemberDoc emd) {
jjg@1362 284 StringBuilder buf = new StringBuilder(emd.name() + "(");
duke@1 285 Parameter[] params = emd.parameters();
duke@1 286 boolean foundTypeVariable = false;
duke@1 287 for (int i = 0; i < params.length; i++) {
duke@1 288 if (i > 0) {
duke@1 289 buf.append(",");
duke@1 290 }
duke@1 291 Type t = params[i].type();
duke@1 292 foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null;
duke@1 293 buf.append(t.isPrimitive() ?
duke@1 294 t.typeName() : t.asClassDoc().qualifiedName());
duke@1 295 buf.append(t.dimension());
duke@1 296 }
duke@1 297 buf.append(")");
duke@1 298 return foundTypeVariable ? buf.toString() : null;
duke@1 299 }
duke@1 300 }

mercurial