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

Sun, 11 Apr 2010 23:24:24 -0700

author
yhuang
date
Sun, 11 Apr 2010 23:24:24 -0700
changeset 539
06e06ec0d6f2
parent 243
edd944553131
child 554
9d9f26857129
permissions
-rw-r--r--

6875904: Java 7 message synchronization 1
Reviewed-by: ogino, faryad

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

mercurial