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

Fri, 04 Mar 2011 19:53:03 -0800

author
jjg
date
Fri, 04 Mar 2011 19:53:03 -0800
changeset 910
ebf7c13df6c0
parent 798
4868a36f6fd8
child 1358
fc123bdeddb8
permissions
-rw-r--r--

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
Reviewed-by: bpatel

duke@1 1 /*
ohair@798 2 * Copyright (c) 1997, 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.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 *
duke@1 36 * @author Robert Field
duke@1 37 * @author Atul M Dambalkar
bpatel@766 38 * @author Bhavesh Patel (Modified)
duke@1 39 */
duke@1 40 public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter {
duke@1 41
duke@1 42 public AbstractExecutableMemberWriter(SubWriterHolderWriter writer,
duke@1 43 ClassDoc classdoc) {
duke@1 44 super(writer, classdoc);
duke@1 45 }
duke@1 46
duke@1 47 public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) {
duke@1 48 super(writer);
duke@1 49 }
duke@1 50
duke@1 51 /**
bpatel@766 52 * Add the type parameters for the executable member.
duke@1 53 *
duke@1 54 * @param member the member to write type parameters for.
bpatel@766 55 * @param htmltree the content tree to which the parameters will be added.
duke@1 56 * @return the display length required to write this information.
duke@1 57 */
bpatel@766 58 protected int addTypeParameters(ExecutableMemberDoc member, Content htmltree) {
duke@1 59 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 60 LinkInfoImpl.CONTEXT_MEMBER_TYPE_PARAMS, member, false);
duke@1 61 String typeParameters = writer.getTypeParameterLinks(linkInfo);
duke@1 62 if (linkInfo.displayLength > 0) {
bpatel@766 63 Content linkContent = new RawHtml(typeParameters);
bpatel@766 64 htmltree.addContent(linkContent);
bpatel@766 65 htmltree.addContent(writer.getSpace());
duke@1 66 writer.displayLength += linkInfo.displayLength + 1;
duke@1 67 }
duke@1 68 return linkInfo.displayLength;
duke@1 69 }
duke@1 70
bpatel@766 71 /**
bpatel@766 72 * {@inheritDoc}
bpatel@766 73 */
bpatel@766 74 protected Content getDeprecatedLink(ProgramElementDoc member) {
bpatel@766 75 ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
bpatel@766 76 return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, (MemberDoc) emd,
bpatel@766 77 emd.qualifiedName() + emd.flatSignature());
duke@1 78 }
duke@1 79
bpatel@766 80 /**
bpatel@766 81 * Add the summary link for the member.
bpatel@766 82 *
bpatel@766 83 * @param context the id of the context where the link will be printed
bpatel@766 84 * @param classDoc the classDoc that we should link to
bpatel@766 85 * @param member the member being linked to
bpatel@766 86 * @param tdSummary the content tree to which the link will be added
bpatel@766 87 */
bpatel@766 88 protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
bpatel@766 89 Content tdSummary) {
duke@1 90 ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
bpatel@766 91 String name = emd.name();
bpatel@766 92 Content strong = HtmlTree.STRONG(new RawHtml(
bpatel@766 93 writer.getDocLink(context, cd, (MemberDoc) emd,
bpatel@766 94 name, false)));
bpatel@766 95 Content code = HtmlTree.CODE(strong);
bpatel@766 96 writer.displayLength = name.length();
bpatel@766 97 addParameters(emd, false, code);
bpatel@766 98 tdSummary.addContent(code);
duke@1 99 }
duke@1 100
bpatel@766 101 /**
bpatel@766 102 * Add the inherited summary link for the member.
bpatel@766 103 *
bpatel@766 104 * @param classDoc the classDoc that we should link to
bpatel@766 105 * @param member the member being linked to
bpatel@766 106 * @param linksTree the content tree to which the link will be added
bpatel@766 107 */
bpatel@766 108 protected void addInheritedSummaryLink(ClassDoc cd,
bpatel@766 109 ProgramElementDoc member, Content linksTree) {
bpatel@766 110 linksTree.addContent(new RawHtml(
bpatel@766 111 writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc) member,
bpatel@766 112 member.name(), false)));
duke@1 113 }
duke@1 114
bpatel@766 115 /**
bpatel@766 116 * Add the parameter for the executable member.
bpatel@766 117 *
bpatel@766 118 * @param member the member to write parameter for.
bpatel@766 119 * @param param the parameter that needs to be written.
bpatel@766 120 * @param isVarArg true if this is a link to var arg.
bpatel@766 121 * @param tree the content tree to which the parameter information will be added.
bpatel@766 122 */
bpatel@766 123 protected void addParam(ExecutableMemberDoc member, Parameter param,
bpatel@766 124 boolean isVarArg, Content tree) {
duke@1 125 if (param.type() != null) {
bpatel@766 126 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(
bpatel@766 127 LinkInfoImpl.CONTEXT_EXECUTABLE_MEMBER_PARAM, param.type(),
bpatel@766 128 isVarArg)));
bpatel@766 129 tree.addContent(link);
duke@1 130 }
duke@1 131 if(param.name().length() > 0) {
bpatel@766 132 tree.addContent(writer.getSpace());
bpatel@766 133 tree.addContent(param.name());
duke@1 134 }
duke@1 135 }
duke@1 136
bpatel@766 137 /**
bpatel@766 138 * Add all the parameters for the executable member.
bpatel@766 139 *
bpatel@766 140 * @param member the member to write parameters for.
bpatel@766 141 * @param tree the content tree to which the parameters information will be added.
bpatel@766 142 */
bpatel@766 143 protected void addParameters(ExecutableMemberDoc member, Content htmltree) {
bpatel@766 144 addParameters(member, true, htmltree);
duke@1 145 }
duke@1 146
bpatel@766 147 /**
bpatel@766 148 * Add all the parameters for the executable member.
bpatel@766 149 *
bpatel@766 150 * @param member the member to write parameters for.
bpatel@766 151 * @param includeAnnotations true if annotation information needs to be added.
bpatel@766 152 * @param tree the content tree to which the parameters information will be added.
bpatel@766 153 */
bpatel@766 154 protected void addParameters(ExecutableMemberDoc member,
bpatel@766 155 boolean includeAnnotations, Content htmltree) {
bpatel@766 156 htmltree.addContent("(");
duke@1 157 Parameter[] params = member.parameters();
duke@1 158 String indent = makeSpace(writer.displayLength);
duke@1 159 if (configuration().linksource) {
duke@1 160 //add spaces to offset indentation changes caused by link.
duke@1 161 indent+= makeSpace(member.name().length());
duke@1 162 }
duke@1 163 int paramstart;
duke@1 164 for (paramstart = 0; paramstart < params.length; paramstart++) {
duke@1 165 Parameter param = params[paramstart];
duke@1 166 if (!param.name().startsWith("this$")) {
duke@1 167 if (includeAnnotations) {
bpatel@766 168 boolean foundAnnotations =
bpatel@766 169 writer.addAnnotationInfo(indent.length(),
bpatel@766 170 member, param, htmltree);
bpatel@766 171 if (foundAnnotations) {
bpatel@766 172 htmltree.addContent(DocletConstants.NL);
bpatel@766 173 htmltree.addContent(indent);
duke@1 174 }
duke@1 175 }
bpatel@766 176 addParam(member, param,
bpatel@766 177 (paramstart == params.length - 1) && member.isVarArgs(), htmltree);
duke@1 178 break;
duke@1 179 }
duke@1 180 }
duke@1 181
duke@1 182 for (int i = paramstart + 1; i < params.length; i++) {
bpatel@766 183 htmltree.addContent(",");
bpatel@766 184 htmltree.addContent(DocletConstants.NL);
bpatel@766 185 htmltree.addContent(indent);
duke@1 186 if (includeAnnotations) {
duke@1 187 boolean foundAnnotations =
bpatel@766 188 writer.addAnnotationInfo(indent.length(), member, params[i],
bpatel@766 189 htmltree);
duke@1 190 if (foundAnnotations) {
bpatel@766 191 htmltree.addContent(DocletConstants.NL);
bpatel@766 192 htmltree.addContent(indent);
duke@1 193 }
duke@1 194 }
bpatel@766 195 addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(),
bpatel@766 196 htmltree);
duke@1 197 }
bpatel@766 198 htmltree.addContent(")");
duke@1 199 }
duke@1 200
bpatel@766 201 /**
bpatel@766 202 * Add exceptions for the executable member.
bpatel@766 203 *
bpatel@766 204 * @param member the member to write exceptions for.
bpatel@766 205 * @param htmltree the content tree to which the exceptions information will be added.
bpatel@766 206 */
bpatel@766 207 protected void addExceptions(ExecutableMemberDoc member, Content htmltree) {
duke@1 208 Type[] exceptions = member.thrownExceptionTypes();
duke@1 209 if(exceptions.length > 0) {
duke@1 210 LinkInfoImpl memberTypeParam = new LinkInfoImpl(
bpatel@766 211 LinkInfoImpl.CONTEXT_MEMBER, member, false);
duke@1 212 int retlen = getReturnTypeLength(member);
duke@1 213 writer.getTypeParameterLinks(memberTypeParam);
duke@1 214 retlen += memberTypeParam.displayLength == 0 ?
duke@1 215 0 : memberTypeParam.displayLength + 1;
duke@1 216 String indent = makeSpace(modifierString(member).length() +
bpatel@766 217 member.name().length() + retlen - 4);
bpatel@766 218 htmltree.addContent(DocletConstants.NL);
bpatel@766 219 htmltree.addContent(indent);
bpatel@766 220 htmltree.addContent("throws ");
duke@1 221 indent += " ";
bpatel@766 222 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(
bpatel@766 223 LinkInfoImpl.CONTEXT_MEMBER, exceptions[0])));
bpatel@766 224 htmltree.addContent(link);
duke@1 225 for(int i = 1; i < exceptions.length; i++) {
bpatel@766 226 htmltree.addContent(",");
bpatel@766 227 htmltree.addContent(DocletConstants.NL);
bpatel@766 228 htmltree.addContent(indent);
bpatel@766 229 Content exceptionLink = new RawHtml(writer.getLink(new LinkInfoImpl(
bpatel@766 230 LinkInfoImpl.CONTEXT_MEMBER, exceptions[i])));
bpatel@766 231 htmltree.addContent(exceptionLink);
duke@1 232 }
duke@1 233 }
duke@1 234 }
duke@1 235
duke@1 236 protected int getReturnTypeLength(ExecutableMemberDoc member) {
duke@1 237 if (member instanceof MethodDoc) {
duke@1 238 MethodDoc method = (MethodDoc)member;
duke@1 239 Type rettype = method.returnType();
duke@1 240 if (rettype.isPrimitive()) {
duke@1 241 return rettype.typeName().length() +
duke@1 242 rettype.dimension().length();
duke@1 243 } else {
duke@1 244 LinkInfoImpl linkInfo = new LinkInfoImpl(
duke@1 245 LinkInfoImpl.CONTEXT_MEMBER, rettype);
duke@1 246 writer.getLink(linkInfo);
duke@1 247 return linkInfo.displayLength;
duke@1 248 }
duke@1 249 } else { // it's a constructordoc
duke@1 250 return -1;
duke@1 251 }
duke@1 252 }
duke@1 253
duke@1 254 protected ClassDoc implementsMethodInIntfac(MethodDoc method,
duke@1 255 ClassDoc[] intfacs) {
duke@1 256 for (int i = 0; i < intfacs.length; i++) {
duke@1 257 MethodDoc[] methods = intfacs[i].methods();
duke@1 258 if (methods.length > 0) {
duke@1 259 for (int j = 0; j < methods.length; j++) {
duke@1 260 if (methods[j].name().equals(method.name()) &&
duke@1 261 methods[j].signature().equals(method.signature())) {
duke@1 262 return intfacs[i];
duke@1 263 }
duke@1 264 }
duke@1 265 }
duke@1 266 }
duke@1 267 return null;
duke@1 268 }
duke@1 269
duke@1 270 /**
duke@1 271 * For backward compatibility, include an anchor using the erasures of the
duke@1 272 * parameters. NOTE: We won't need this method anymore after we fix
duke@1 273 * see tags so that they use the type instead of the erasure.
duke@1 274 *
duke@1 275 * @param emd the ExecutableMemberDoc to anchor to.
duke@1 276 * @return the 1.4.x style anchor for the ExecutableMemberDoc.
duke@1 277 */
duke@1 278 protected String getErasureAnchor(ExecutableMemberDoc emd) {
duke@1 279 StringBuffer buf = new StringBuffer(emd.name() + "(");
duke@1 280 Parameter[] params = emd.parameters();
duke@1 281 boolean foundTypeVariable = false;
duke@1 282 for (int i = 0; i < params.length; i++) {
duke@1 283 if (i > 0) {
duke@1 284 buf.append(",");
duke@1 285 }
duke@1 286 Type t = params[i].type();
duke@1 287 foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null;
duke@1 288 buf.append(t.isPrimitive() ?
duke@1 289 t.typeName() : t.asClassDoc().qualifiedName());
duke@1 290 buf.append(t.dimension());
duke@1 291 }
duke@1 292 buf.append(")");
duke@1 293 return foundTypeVariable ? buf.toString() : null;
duke@1 294 }
duke@1 295 }

mercurial