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

Fri, 27 Feb 2009 18:57:17 -0800

author
bpatel
date
Fri, 27 Feb 2009 18:57:17 -0800
changeset 233
5240b1120530
parent 182
47a62d8d98b4
child 243
edd944553131
permissions
-rw-r--r--

6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
Reviewed-by: jjg

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)
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 {
bpatel@182 170 strong(method.name());
duke@1 171 }
duke@1 172 writeParameters(method);
duke@1 173 writeExceptions(method);
duke@1 174 writer.preEnd();
bpatel@233 175 assert !writer.getMemberDetailsListPrinted();
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) {
bpatel@233 184 printDeprecated(method);
duke@1 185 }
duke@1 186
duke@1 187 /**
duke@1 188 * Write the comments for the given method.
duke@1 189 *
duke@1 190 * @param method the method being documented.
duke@1 191 */
duke@1 192 public void writeComments(Type holder, MethodDoc method) {
duke@1 193 ClassDoc holderClassDoc = holder.asClassDoc();
duke@1 194 if (method.inlineTags().length > 0) {
bpatel@233 195 writer.printMemberDetailsListStartTag();
duke@1 196 if (holder.asClassDoc().equals(classdoc) ||
duke@1 197 (! (holderClassDoc.isPublic() ||
duke@1 198 Util.isLinkable(holderClassDoc, configuration())))) {
duke@1 199 writer.dd();
duke@1 200 writer.printInlineComment(method);
bpatel@233 201 writer.ddEnd();
duke@1 202 } else {
duke@1 203 String classlink = writer.codeText(
duke@1 204 writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
duke@1 205 holder.asClassDoc(), method,
duke@1 206 holder.asClassDoc().isIncluded() ?
duke@1 207 holder.typeName() : holder.qualifiedTypeName(),
duke@1 208 false));
duke@1 209 writer.dd();
bpatel@182 210 writer.strongText(holder.asClassDoc().isClass()?
duke@1 211 "doclet.Description_From_Class":
duke@1 212 "doclet.Description_From_Interface",
duke@1 213 classlink);
duke@1 214 writer.ddEnd();
duke@1 215 writer.dd();
duke@1 216 writer.printInlineComment(method);
bpatel@233 217 writer.ddEnd();
duke@1 218 }
duke@1 219 }
duke@1 220 }
duke@1 221
duke@1 222 /**
duke@1 223 * Write the tag output for the given method.
duke@1 224 *
duke@1 225 * @param method the method being documented.
duke@1 226 */
duke@1 227 public void writeTags(MethodDoc method) {
duke@1 228 writer.printTags(method);
duke@1 229 }
duke@1 230
duke@1 231 /**
duke@1 232 * Write the method footer.
duke@1 233 */
duke@1 234 public void writeMethodFooter() {
bpatel@233 235 printMemberFooter();
duke@1 236 }
duke@1 237
duke@1 238 /**
duke@1 239 * Write the footer for the method documentation.
duke@1 240 *
duke@1 241 * @param classDoc the class that the methods belong to.
duke@1 242 */
duke@1 243 public void writeFooter(ClassDoc classDoc) {
duke@1 244 //No footer to write for method documentation
duke@1 245 }
duke@1 246
duke@1 247 /**
duke@1 248 * Close the writer.
duke@1 249 */
duke@1 250 public void close() throws IOException {
duke@1 251 writer.close();
duke@1 252 }
duke@1 253
duke@1 254 public int getMemberKind() {
duke@1 255 return VisibleMemberMap.METHODS;
duke@1 256 }
duke@1 257
duke@1 258 public void printSummaryLabel(ClassDoc cd) {
bpatel@182 259 writer.strongText("doclet.Method_Summary");
duke@1 260 }
duke@1 261
duke@1 262 public void printSummaryAnchor(ClassDoc cd) {
duke@1 263 writer.anchor("method_summary");
duke@1 264 }
duke@1 265
duke@1 266 public void printInheritedSummaryAnchor(ClassDoc cd) {
duke@1 267 writer.anchor("methods_inherited_from_class_" +
duke@1 268 ConfigurationImpl.getInstance().getClassName(cd));
duke@1 269 }
duke@1 270
duke@1 271 public void printInheritedSummaryLabel(ClassDoc cd) {
duke@1 272 String classlink = writer.getPreQualifiedClassLink(
duke@1 273 LinkInfoImpl.CONTEXT_MEMBER, cd, false);
bpatel@182 274 writer.strong();
duke@1 275 String key = cd.isClass()?
duke@1 276 "doclet.Methods_Inherited_From_Class" :
duke@1 277 "doclet.Methods_Inherited_From_Interface";
duke@1 278 writer.printText(key, classlink);
bpatel@182 279 writer.strongEnd();
duke@1 280 }
duke@1 281
duke@1 282 protected void printSummaryType(ProgramElementDoc member) {
duke@1 283 MethodDoc meth = (MethodDoc)member;
duke@1 284 printModifierAndType(meth, meth.returnType());
duke@1 285 }
duke@1 286
duke@1 287 protected static void printOverridden(HtmlDocletWriter writer,
duke@1 288 Type overriddenType, MethodDoc method) {
duke@1 289 if(writer.configuration.nocomment){
duke@1 290 return;
duke@1 291 }
duke@1 292 ClassDoc holderClassDoc = overriddenType.asClassDoc();
duke@1 293 if (! (holderClassDoc.isPublic() ||
duke@1 294 Util.isLinkable(holderClassDoc, writer.configuration()))) {
duke@1 295 //This is an implementation detail that should not be documented.
duke@1 296 return;
duke@1 297 }
duke@1 298 if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
duke@1 299 //The class is included but the method is not. That means that it
duke@1 300 //is not visible so don't document this.
duke@1 301 return;
duke@1 302 }
duke@1 303 String label = "doclet.Overrides";
duke@1 304 int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
duke@1 305
duke@1 306 if (method != null) {
duke@1 307 if(overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
duke@1 308 //Abstract method is implemented from abstract class,
duke@1 309 //not overridden
duke@1 310 label = "doclet.Specified_By";
duke@1 311 context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
duke@1 312 }
duke@1 313 String overriddenTypeLink = writer.codeText(
duke@1 314 writer.getLink(new LinkInfoImpl(context, overriddenType)));
duke@1 315 String name = method.name();
duke@1 316 writer.dt();
bpatel@182 317 writer.strongText(label);
bpatel@233 318 writer.dtEnd();
duke@1 319 writer.dd();
duke@1 320 String methLink = writer.codeText(
duke@1 321 writer.getLink(
duke@1 322 new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
duke@1 323 overriddenType.asClassDoc(),
duke@1 324 writer.getAnchor(method), name, false)
duke@1 325 ));
duke@1 326 writer.printText("doclet.in_class", methLink, overriddenTypeLink);
bpatel@233 327 writer.ddEnd();
duke@1 328 }
duke@1 329 }
duke@1 330
duke@1 331 /**
duke@1 332 * Parse the &lt;Code&gt; tag and return the text.
duke@1 333 */
duke@1 334 protected String parseCodeTag(String tag){
duke@1 335 if(tag == null){
duke@1 336 return "";
duke@1 337 }
duke@1 338
duke@1 339 String lc = tag.toLowerCase();
duke@1 340 int begin = lc.indexOf("<code>");
duke@1 341 int end = lc.indexOf("</code>");
duke@1 342 if(begin == -1 || end == -1 || end <= begin){
duke@1 343 return tag;
duke@1 344 } else {
duke@1 345 return tag.substring(begin + 6, end);
duke@1 346 }
duke@1 347 }
duke@1 348
duke@1 349 protected static void printImplementsInfo(HtmlDocletWriter writer,
duke@1 350 MethodDoc method) {
duke@1 351 if(writer.configuration.nocomment){
duke@1 352 return;
duke@1 353 }
duke@1 354 ImplementedMethods implementedMethodsFinder =
duke@1 355 new ImplementedMethods(method, writer.configuration);
duke@1 356 MethodDoc[] implementedMethods = implementedMethodsFinder.build();
duke@1 357 for (int i = 0; i < implementedMethods.length; i++) {
duke@1 358 MethodDoc implementedMeth = implementedMethods[i];
duke@1 359 Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
duke@1 360 String methlink = "";
duke@1 361 String intfaclink = writer.codeText(
duke@1 362 writer.getLink(new LinkInfoImpl(
duke@1 363 LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
duke@1 364 writer.dt();
bpatel@182 365 writer.strongText("doclet.Specified_By");
bpatel@233 366 writer.dtEnd();
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);
bpatel@233 372 writer.ddEnd();
duke@1 373 }
duke@1 374
duke@1 375 }
duke@1 376
duke@1 377 protected void printReturnType(MethodDoc method) {
duke@1 378 Type type = method.returnType();
duke@1 379 if (type != null) {
duke@1 380 writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_RETURN_TYPE,
duke@1 381 type));
duke@1 382 print(' ');
duke@1 383 }
duke@1 384 }
duke@1 385
duke@1 386 protected void printNavSummaryLink(ClassDoc cd, boolean link) {
duke@1 387 if (link) {
duke@1 388 writer.printHyperLink("", (cd == null)?
duke@1 389 "method_summary":
duke@1 390 "methods_inherited_from_class_" +
duke@1 391 ConfigurationImpl.getInstance().getClassName(cd),
duke@1 392 ConfigurationImpl.getInstance().getText("doclet.navMethod"));
duke@1 393 } else {
duke@1 394 writer.printText("doclet.navMethod");
duke@1 395 }
duke@1 396 }
duke@1 397
duke@1 398 protected void printNavDetailLink(boolean link) {
duke@1 399 if (link) {
duke@1 400 writer.printHyperLink("", "method_detail",
duke@1 401 ConfigurationImpl.getInstance().getText("doclet.navMethod"));
duke@1 402 } else {
duke@1 403 writer.printText("doclet.navMethod");
duke@1 404 }
duke@1 405 }
duke@1 406 }

mercurial