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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 1
9a66ca7c79fa
child 182
47a62d8d98b4
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
duke@1 2 * Copyright 1997-2004 Sun Microsystems, Inc. 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
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun 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 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any 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.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 30 import com.sun.tools.doclets.internal.toolkit.taglets.*;
duke@1 31
duke@1 32 import java.io.*;
duke@1 33 import com.sun.javadoc.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Writes method documentation in HTML format.
duke@1 37 *
duke@1 38 * @author Robert Field
duke@1 39 * @author Atul M Dambalkar
duke@1 40 * @author Jamie Ho (rewrite)
duke@1 41 */
duke@1 42 public class MethodWriterImpl extends AbstractExecutableMemberWriter
duke@1 43 implements MethodWriter, MemberSummaryWriter {
duke@1 44
duke@1 45 private boolean printedSummaryHeader = false;
duke@1 46
duke@1 47 /**
duke@1 48 * Construct a new MethodWriterImpl.
duke@1 49 *
duke@1 50 * @param writer the writer for the class that the methods belong to.
duke@1 51 * @param classDoc the class being documented.
duke@1 52 */
duke@1 53 public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
duke@1 54 super(writer, classDoc);
duke@1 55 }
duke@1 56
duke@1 57 /**
duke@1 58 * Construct a new MethodWriterImpl.
duke@1 59 *
duke@1 60 * @param writer The writer for the class that the methods belong to.
duke@1 61 */
duke@1 62 public MethodWriterImpl(SubWriterHolderWriter writer) {
duke@1 63 super(writer);
duke@1 64 }
duke@1 65
duke@1 66 /**
duke@1 67 * Write the methods summary header for the given class.
duke@1 68 *
duke@1 69 * @param classDoc the class the summary belongs to.
duke@1 70 */
duke@1 71 public void writeMemberSummaryHeader(ClassDoc classDoc) {
duke@1 72 printedSummaryHeader = true;
duke@1 73 writer.println();
duke@1 74 writer.println("<!-- ========== METHOD SUMMARY =========== -->");
duke@1 75 writer.println();
duke@1 76 writer.printSummaryHeader(this, classDoc);
duke@1 77 }
duke@1 78
duke@1 79 /**
duke@1 80 * Write the methods summary footer for the given class.
duke@1 81 *
duke@1 82 * @param classDoc the class the summary belongs to.
duke@1 83 */
duke@1 84 public void writeMemberSummaryFooter(ClassDoc classDoc) {
duke@1 85 writer.printSummaryFooter(this, classDoc);
duke@1 86 }
duke@1 87
duke@1 88 /**
duke@1 89 * Write the inherited methods summary header for the given class.
duke@1 90 *
duke@1 91 * @param classDoc the class the summary belongs to.
duke@1 92 */
duke@1 93 public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
duke@1 94 if(! printedSummaryHeader){
duke@1 95 //We don't want inherited summary to not be under heading.
duke@1 96 writeMemberSummaryHeader(classDoc);
duke@1 97 writeMemberSummaryFooter(classDoc);
duke@1 98 printedSummaryHeader = true;
duke@1 99 }
duke@1 100 writer.printInheritedSummaryHeader(this, classDoc);
duke@1 101 }
duke@1 102
duke@1 103 /**
duke@1 104 * {@inheritDoc}
duke@1 105 */
duke@1 106 public void writeInheritedMemberSummary(ClassDoc classDoc,
duke@1 107 ProgramElementDoc method, boolean isFirst, boolean isLast) {
duke@1 108 writer.printInheritedSummaryMember(this, classDoc, method, isFirst);
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * Write the inherited methods summary footer for the given class.
duke@1 113 *
duke@1 114 * @param classDoc the class the summary belongs to.
duke@1 115 */
duke@1 116 public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
duke@1 117 writer.printInheritedSummaryFooter(this, classDoc); ;
duke@1 118 }
duke@1 119
duke@1 120 /**
duke@1 121 * Write the header for the method documentation.
duke@1 122 *
duke@1 123 * @param classDoc the class that the methods belong to.
duke@1 124 */
duke@1 125 public void writeHeader(ClassDoc classDoc, String header) {
duke@1 126 writer.println();
duke@1 127 writer.println("<!-- ============ METHOD DETAIL ========== -->");
duke@1 128 writer.println();
duke@1 129 writer.anchor("method_detail");
duke@1 130 writer.printTableHeadingBackground(header);
duke@1 131 }
duke@1 132
duke@1 133 /**
duke@1 134 * Write the method header for the given method.
duke@1 135 *
duke@1 136 * @param method the method being documented.
duke@1 137 * @param isFirst the flag to indicate whether or not the method is the
duke@1 138 * first to be documented.
duke@1 139 */
duke@1 140 public void writeMethodHeader(MethodDoc method, boolean isFirst) {
duke@1 141 if (! isFirst) {
duke@1 142 writer.printMemberHeader();
duke@1 143 }
duke@1 144 writer.println();
duke@1 145 String erasureAnchor;
duke@1 146 if ((erasureAnchor = getErasureAnchor(method)) != null) {
duke@1 147 writer.anchor(erasureAnchor);
duke@1 148 }
duke@1 149 writer.anchor(method);
duke@1 150 writer.h3();
duke@1 151 writer.print(method.name());
duke@1 152 writer.h3End();
duke@1 153 }
duke@1 154
duke@1 155 /**
duke@1 156 * Write the signature for the given method.
duke@1 157 *
duke@1 158 * @param method the method being documented.
duke@1 159 */
duke@1 160 public void writeSignature(MethodDoc method) {
duke@1 161 writer.displayLength = 0;
duke@1 162 writer.pre();
duke@1 163 writer.writeAnnotationInfo(method);
duke@1 164 printModifiers(method);
duke@1 165 writeTypeParameters(method);
duke@1 166 printReturnType(method);
duke@1 167 if (configuration().linksource) {
duke@1 168 writer.printSrcLink(method, method.name());
duke@1 169 } else {
duke@1 170 bold(method.name());
duke@1 171 }
duke@1 172 writeParameters(method);
duke@1 173 writeExceptions(method);
duke@1 174 writer.preEnd();
duke@1 175 writer.dl();
duke@1 176 }
duke@1 177
duke@1 178 /**
duke@1 179 * Write the deprecated output for the given method.
duke@1 180 *
duke@1 181 * @param method the method being documented.
duke@1 182 */
duke@1 183 public void writeDeprecated(MethodDoc method) {
duke@1 184 String output = ((TagletOutputImpl)
duke@1 185 (new DeprecatedTaglet()).getTagletOutput(method,
duke@1 186 writer.getTagletWriterInstance(false))).toString();
duke@1 187 if (output != null && output.trim().length() > 0) {
duke@1 188 writer.print(output);
duke@1 189 }
duke@1 190 }
duke@1 191
duke@1 192 /**
duke@1 193 * Write the comments for the given method.
duke@1 194 *
duke@1 195 * @param method the method being documented.
duke@1 196 */
duke@1 197 public void writeComments(Type holder, MethodDoc method) {
duke@1 198 ClassDoc holderClassDoc = holder.asClassDoc();
duke@1 199 if (method.inlineTags().length > 0) {
duke@1 200 if (holder.asClassDoc().equals(classdoc) ||
duke@1 201 (! (holderClassDoc.isPublic() ||
duke@1 202 Util.isLinkable(holderClassDoc, configuration())))) {
duke@1 203 writer.dd();
duke@1 204 writer.printInlineComment(method);
duke@1 205 } else {
duke@1 206 String classlink = writer.codeText(
duke@1 207 writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
duke@1 208 holder.asClassDoc(), method,
duke@1 209 holder.asClassDoc().isIncluded() ?
duke@1 210 holder.typeName() : holder.qualifiedTypeName(),
duke@1 211 false));
duke@1 212 writer.dd();
duke@1 213 writer.boldText(holder.asClassDoc().isClass()?
duke@1 214 "doclet.Description_From_Class":
duke@1 215 "doclet.Description_From_Interface",
duke@1 216 classlink);
duke@1 217 writer.ddEnd();
duke@1 218 writer.dd();
duke@1 219 writer.printInlineComment(method);
duke@1 220 }
duke@1 221 }
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Write the tag output for the given method.
duke@1 226 *
duke@1 227 * @param method the method being documented.
duke@1 228 */
duke@1 229 public void writeTags(MethodDoc method) {
duke@1 230 writer.printTags(method);
duke@1 231 }
duke@1 232
duke@1 233 /**
duke@1 234 * Write the method footer.
duke@1 235 */
duke@1 236 public void writeMethodFooter() {
duke@1 237 writer.ddEnd();
duke@1 238 writer.dlEnd();
duke@1 239 }
duke@1 240
duke@1 241 /**
duke@1 242 * Write the footer for the method documentation.
duke@1 243 *
duke@1 244 * @param classDoc the class that the methods belong to.
duke@1 245 */
duke@1 246 public void writeFooter(ClassDoc classDoc) {
duke@1 247 //No footer to write for method documentation
duke@1 248 }
duke@1 249
duke@1 250 /**
duke@1 251 * Close the writer.
duke@1 252 */
duke@1 253 public void close() throws IOException {
duke@1 254 writer.close();
duke@1 255 }
duke@1 256
duke@1 257 public int getMemberKind() {
duke@1 258 return VisibleMemberMap.METHODS;
duke@1 259 }
duke@1 260
duke@1 261 public void printSummaryLabel(ClassDoc cd) {
duke@1 262 writer.boldText("doclet.Method_Summary");
duke@1 263 }
duke@1 264
duke@1 265 public void printSummaryAnchor(ClassDoc cd) {
duke@1 266 writer.anchor("method_summary");
duke@1 267 }
duke@1 268
duke@1 269 public void printInheritedSummaryAnchor(ClassDoc cd) {
duke@1 270 writer.anchor("methods_inherited_from_class_" +
duke@1 271 ConfigurationImpl.getInstance().getClassName(cd));
duke@1 272 }
duke@1 273
duke@1 274 public void printInheritedSummaryLabel(ClassDoc cd) {
duke@1 275 String classlink = writer.getPreQualifiedClassLink(
duke@1 276 LinkInfoImpl.CONTEXT_MEMBER, cd, false);
duke@1 277 writer.bold();
duke@1 278 String key = cd.isClass()?
duke@1 279 "doclet.Methods_Inherited_From_Class" :
duke@1 280 "doclet.Methods_Inherited_From_Interface";
duke@1 281 writer.printText(key, classlink);
duke@1 282 writer.boldEnd();
duke@1 283 }
duke@1 284
duke@1 285 protected void printSummaryType(ProgramElementDoc member) {
duke@1 286 MethodDoc meth = (MethodDoc)member;
duke@1 287 printModifierAndType(meth, meth.returnType());
duke@1 288 }
duke@1 289
duke@1 290 protected static void printOverridden(HtmlDocletWriter writer,
duke@1 291 Type overriddenType, MethodDoc method) {
duke@1 292 if(writer.configuration.nocomment){
duke@1 293 return;
duke@1 294 }
duke@1 295 ClassDoc holderClassDoc = overriddenType.asClassDoc();
duke@1 296 if (! (holderClassDoc.isPublic() ||
duke@1 297 Util.isLinkable(holderClassDoc, writer.configuration()))) {
duke@1 298 //This is an implementation detail that should not be documented.
duke@1 299 return;
duke@1 300 }
duke@1 301 if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
duke@1 302 //The class is included but the method is not. That means that it
duke@1 303 //is not visible so don't document this.
duke@1 304 return;
duke@1 305 }
duke@1 306 String label = "doclet.Overrides";
duke@1 307 int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
duke@1 308
duke@1 309 if (method != null) {
duke@1 310 if(overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
duke@1 311 //Abstract method is implemented from abstract class,
duke@1 312 //not overridden
duke@1 313 label = "doclet.Specified_By";
duke@1 314 context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
duke@1 315 }
duke@1 316 String overriddenTypeLink = writer.codeText(
duke@1 317 writer.getLink(new LinkInfoImpl(context, overriddenType)));
duke@1 318 String name = method.name();
duke@1 319 writer.dt();
duke@1 320 writer.boldText(label);
duke@1 321 writer.dd();
duke@1 322 String methLink = writer.codeText(
duke@1 323 writer.getLink(
duke@1 324 new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
duke@1 325 overriddenType.asClassDoc(),
duke@1 326 writer.getAnchor(method), name, false)
duke@1 327 ));
duke@1 328 writer.printText("doclet.in_class", methLink, overriddenTypeLink);
duke@1 329 }
duke@1 330 }
duke@1 331
duke@1 332 /**
duke@1 333 * Parse the &lt;Code&gt; tag and return the text.
duke@1 334 */
duke@1 335 protected String parseCodeTag(String tag){
duke@1 336 if(tag == null){
duke@1 337 return "";
duke@1 338 }
duke@1 339
duke@1 340 String lc = tag.toLowerCase();
duke@1 341 int begin = lc.indexOf("<code>");
duke@1 342 int end = lc.indexOf("</code>");
duke@1 343 if(begin == -1 || end == -1 || end <= begin){
duke@1 344 return tag;
duke@1 345 } else {
duke@1 346 return tag.substring(begin + 6, end);
duke@1 347 }
duke@1 348 }
duke@1 349
duke@1 350 protected static void printImplementsInfo(HtmlDocletWriter writer,
duke@1 351 MethodDoc method) {
duke@1 352 if(writer.configuration.nocomment){
duke@1 353 return;
duke@1 354 }
duke@1 355 ImplementedMethods implementedMethodsFinder =
duke@1 356 new ImplementedMethods(method, writer.configuration);
duke@1 357 MethodDoc[] implementedMethods = implementedMethodsFinder.build();
duke@1 358 for (int i = 0; i < implementedMethods.length; i++) {
duke@1 359 MethodDoc implementedMeth = implementedMethods[i];
duke@1 360 Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
duke@1 361 String methlink = "";
duke@1 362 String intfaclink = writer.codeText(
duke@1 363 writer.getLink(new LinkInfoImpl(
duke@1 364 LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
duke@1 365 writer.dt();
duke@1 366 writer.boldText("doclet.Specified_By");
duke@1 367 writer.dd();
duke@1 368 methlink = writer.codeText(writer.getDocLink(
duke@1 369 LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
duke@1 370 implementedMeth.name(), false));
duke@1 371 writer.printText("doclet.in_interface", methlink, intfaclink);
duke@1 372 }
duke@1 373
duke@1 374 }
duke@1 375
duke@1 376 protected void printReturnType(MethodDoc method) {
duke@1 377 Type type = method.returnType();
duke@1 378 if (type != null) {
duke@1 379 writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_RETURN_TYPE,
duke@1 380 type));
duke@1 381 print(' ');
duke@1 382 }
duke@1 383 }
duke@1 384
duke@1 385 protected void printNavSummaryLink(ClassDoc cd, boolean link) {
duke@1 386 if (link) {
duke@1 387 writer.printHyperLink("", (cd == null)?
duke@1 388 "method_summary":
duke@1 389 "methods_inherited_from_class_" +
duke@1 390 ConfigurationImpl.getInstance().getClassName(cd),
duke@1 391 ConfigurationImpl.getInstance().getText("doclet.navMethod"));
duke@1 392 } else {
duke@1 393 writer.printText("doclet.navMethod");
duke@1 394 }
duke@1 395 }
duke@1 396
duke@1 397 protected void printNavDetailLink(boolean link) {
duke@1 398 if (link) {
duke@1 399 writer.printHyperLink("", "method_detail",
duke@1 400 ConfigurationImpl.getInstance().getText("doclet.navMethod"));
duke@1 401 } else {
duke@1 402 writer.printText("doclet.navMethod");
duke@1 403 }
duke@1 404 }
duke@1 405 }

mercurial