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

Wed, 23 Jan 2013 13:27:24 -0800

author
jjg
date
Wed, 23 Jan 2013 13:27:24 -0800
changeset 1521
71f35e4b93a5
parent 1410
bfec2a1cc869
child 1686
eb134c8e931d
permissions
-rw-r--r--

8006775: JSR 308: Compiler changes in JDK8
Reviewed-by: jjg
Contributed-by: mernst@cs.washington.edu, wmdietl@cs.washington.edu, mpapi@csail.mit.edu, mahmood@notnoop.com

duke@1 1 /*
jjg@1521 2 * Copyright (c) 1997, 2013, 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
bpatel@233 28 import java.io.*;
bpatel@233 29
bpatel@233 30 import com.sun.javadoc.*;
bpatel@766 31 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 33 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Writes method documentation in HTML format.
duke@1 37 *
jjg@1359 38 * <p><b>This is NOT part of any supported API.
jjg@1359 39 * If you write code that depends on this, you do so at your own risk.
jjg@1359 40 * This code and its internal interfaces are subject to change or
jjg@1359 41 * deletion without notice.</b>
jjg@1359 42 *
duke@1 43 * @author Robert Field
duke@1 44 * @author Atul M Dambalkar
duke@1 45 * @author Jamie Ho (rewrite)
bpatel@243 46 * @author Bhavesh Patel (Modified)
duke@1 47 */
duke@1 48 public class MethodWriterImpl extends AbstractExecutableMemberWriter
duke@1 49 implements MethodWriter, MemberSummaryWriter {
duke@1 50
duke@1 51 /**
duke@1 52 * Construct a new MethodWriterImpl.
duke@1 53 *
duke@1 54 * @param writer the writer for the class that the methods belong to.
duke@1 55 * @param classDoc the class being documented.
duke@1 56 */
duke@1 57 public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
duke@1 58 super(writer, classDoc);
duke@1 59 }
duke@1 60
duke@1 61 /**
duke@1 62 * Construct a new MethodWriterImpl.
duke@1 63 *
duke@1 64 * @param writer The writer for the class that the methods belong to.
duke@1 65 */
duke@1 66 public MethodWriterImpl(SubWriterHolderWriter writer) {
duke@1 67 super(writer);
duke@1 68 }
duke@1 69
duke@1 70 /**
bpatel@766 71 * {@inheritDoc}
duke@1 72 */
bpatel@766 73 public Content getMemberSummaryHeader(ClassDoc classDoc,
bpatel@766 74 Content memberSummaryTree) {
bpatel@766 75 memberSummaryTree.addContent(HtmlConstants.START_OF_METHOD_SUMMARY);
bpatel@766 76 Content memberTree = writer.getMemberTreeHeader();
bpatel@766 77 writer.addSummaryHeader(this, classDoc, memberTree);
bpatel@766 78 return memberTree;
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * {@inheritDoc}
duke@1 83 */
bpatel@766 84 public Content getMethodDetailsTreeHeader(ClassDoc classDoc,
bpatel@766 85 Content memberDetailsTree) {
bpatel@766 86 memberDetailsTree.addContent(HtmlConstants.START_OF_METHOD_DETAILS);
bpatel@766 87 Content methodDetailsTree = writer.getMemberTreeHeader();
bpatel@766 88 methodDetailsTree.addContent(writer.getMarkerAnchor("method_detail"));
bpatel@766 89 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
bpatel@766 90 writer.methodDetailsLabel);
bpatel@766 91 methodDetailsTree.addContent(heading);
bpatel@766 92 return methodDetailsTree;
duke@1 93 }
duke@1 94
duke@1 95 /**
bpatel@766 96 * {@inheritDoc}
duke@1 97 */
bpatel@766 98 public Content getMethodDocTreeHeader(MethodDoc method,
bpatel@766 99 Content methodDetailsTree) {
bpatel@766 100 String erasureAnchor;
bpatel@766 101 if ((erasureAnchor = getErasureAnchor(method)) != null) {
bpatel@766 102 methodDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
bpatel@766 103 }
bpatel@766 104 methodDetailsTree.addContent(
bpatel@766 105 writer.getMarkerAnchor(writer.getAnchor(method)));
bpatel@766 106 Content methodDocTree = writer.getMemberTreeHeader();
bpatel@766 107 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
bpatel@766 108 heading.addContent(method.name());
bpatel@766 109 methodDocTree.addContent(heading);
bpatel@766 110 return methodDocTree;
duke@1 111 }
duke@1 112
duke@1 113 /**
bpatel@766 114 * Get the signature for the given method.
duke@1 115 *
bpatel@766 116 * @param method the method being documented.
bpatel@766 117 * @return a content object for the signature
duke@1 118 */
bpatel@766 119 public Content getSignature(MethodDoc method) {
bpatel@766 120 writer.displayLength = 0;
bpatel@766 121 Content pre = new HtmlTree(HtmlTag.PRE);
bpatel@766 122 writer.addAnnotationInfo(method, pre);
bpatel@766 123 addModifiers(method, pre);
bpatel@766 124 addTypeParameters(method, pre);
bpatel@766 125 addReturnType(method, pre);
jjg@1410 126 if (configuration.linksource) {
bpatel@766 127 Content methodName = new StringContent(method.name());
bpatel@766 128 writer.addSrcLink(method, methodName, pre);
bpatel@766 129 } else {
bpatel@766 130 addName(method.name(), pre);
bpatel@766 131 }
bpatel@766 132 addParameters(method, pre);
jjg@1521 133 addReceiverAnnotations(method, pre);
bpatel@766 134 addExceptions(method, pre);
bpatel@766 135 return pre;
duke@1 136 }
duke@1 137
duke@1 138 /**
bpatel@766 139 * {@inheritDoc}
duke@1 140 */
bpatel@766 141 public void addDeprecated(MethodDoc method, Content methodDocTree) {
bpatel@766 142 addDeprecatedInfo(method, methodDocTree);
duke@1 143 }
duke@1 144
duke@1 145 /**
bpatel@766 146 * {@inheritDoc}
duke@1 147 */
bpatel@766 148 public void addComments(Type holder, MethodDoc method, Content methodDocTree) {
duke@1 149 ClassDoc holderClassDoc = holder.asClassDoc();
duke@1 150 if (method.inlineTags().length > 0) {
duke@1 151 if (holder.asClassDoc().equals(classdoc) ||
bpatel@766 152 (! (holderClassDoc.isPublic() ||
jjg@1410 153 Util.isLinkable(holderClassDoc, configuration)))) {
bpatel@766 154 writer.addInlineComment(method, methodDocTree);
duke@1 155 } else {
bpatel@766 156 Content link = new RawHtml(
bpatel@766 157 writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
duke@1 158 holder.asClassDoc(), method,
duke@1 159 holder.asClassDoc().isIncluded() ?
duke@1 160 holder.typeName() : holder.qualifiedTypeName(),
bpatel@766 161 false));
bpatel@766 162 Content codelLink = HtmlTree.CODE(link);
bpatel@766 163 Content strong = HtmlTree.STRONG(holder.asClassDoc().isClass()?
bpatel@766 164 writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
bpatel@766 165 strong.addContent(writer.getSpace());
bpatel@766 166 strong.addContent(codelLink);
bpatel@766 167 methodDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, strong));
bpatel@766 168 writer.addInlineComment(method, methodDocTree);
duke@1 169 }
duke@1 170 }
duke@1 171 }
duke@1 172
duke@1 173 /**
bpatel@766 174 * {@inheritDoc}
duke@1 175 */
bpatel@766 176 public void addTags(MethodDoc method, Content methodDocTree) {
bpatel@766 177 writer.addTagsInfo(method, methodDocTree);
duke@1 178 }
duke@1 179
duke@1 180 /**
bpatel@766 181 * {@inheritDoc}
duke@1 182 */
bpatel@766 183 public Content getMethodDetails(Content methodDetailsTree) {
bpatel@766 184 return getMemberTree(methodDetailsTree);
duke@1 185 }
duke@1 186
duke@1 187 /**
bpatel@766 188 * {@inheritDoc}
duke@1 189 */
bpatel@766 190 public Content getMethodDoc(Content methodDocTree,
bpatel@766 191 boolean isLastContent) {
bpatel@766 192 return getMemberTree(methodDocTree, isLastContent);
duke@1 193 }
duke@1 194
duke@1 195 /**
duke@1 196 * Close the writer.
duke@1 197 */
duke@1 198 public void close() throws IOException {
duke@1 199 writer.close();
duke@1 200 }
duke@1 201
duke@1 202 public int getMemberKind() {
duke@1 203 return VisibleMemberMap.METHODS;
duke@1 204 }
duke@1 205
bpatel@766 206 /**
bpatel@766 207 * {@inheritDoc}
bpatel@766 208 */
bpatel@766 209 public void addSummaryLabel(Content memberTree) {
bpatel@766 210 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
bpatel@766 211 writer.getResource("doclet.Method_Summary"));
bpatel@766 212 memberTree.addContent(label);
bpatel@243 213 }
bpatel@243 214
bpatel@766 215 /**
bpatel@766 216 * {@inheritDoc}
bpatel@766 217 */
bpatel@766 218 public String getTableSummary() {
jjg@1410 219 return configuration.getText("doclet.Member_Table_Summary",
jjg@1410 220 configuration.getText("doclet.Method_Summary"),
jjg@1410 221 configuration.getText("doclet.methods"));
bpatel@243 222 }
bpatel@243 223
bpatel@766 224 /**
bpatel@766 225 * {@inheritDoc}
bpatel@766 226 */
bpatel@766 227 public String getCaption() {
jjg@1410 228 return configuration.getText("doclet.Methods");
bpatel@766 229 }
bpatel@766 230
bpatel@766 231 /**
bpatel@766 232 * {@inheritDoc}
bpatel@766 233 */
bpatel@766 234 public String[] getSummaryTableHeader(ProgramElementDoc member) {
bpatel@243 235 String[] header = new String[] {
bpatel@243 236 writer.getModifierTypeHeader(),
jjg@1410 237 configuration.getText("doclet.0_and_1",
jjg@1410 238 configuration.getText("doclet.Method"),
jjg@1410 239 configuration.getText("doclet.Description"))
bpatel@243 240 };
bpatel@766 241 return header;
duke@1 242 }
duke@1 243
bpatel@766 244 /**
bpatel@766 245 * {@inheritDoc}
bpatel@766 246 */
bpatel@766 247 public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
bpatel@766 248 memberTree.addContent(writer.getMarkerAnchor("method_summary"));
duke@1 249 }
duke@1 250
bpatel@766 251 /**
bpatel@766 252 * {@inheritDoc}
bpatel@766 253 */
bpatel@766 254 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
bpatel@766 255 inheritedTree.addContent(writer.getMarkerAnchor(
bpatel@766 256 "methods_inherited_from_class_" +
jjg@1410 257 configuration.getClassName(cd)));
duke@1 258 }
duke@1 259
bpatel@766 260 /**
bpatel@766 261 * {@inheritDoc}
bpatel@766 262 */
bpatel@766 263 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
bpatel@766 264 Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
bpatel@766 265 LinkInfoImpl.CONTEXT_MEMBER, cd, false));
bpatel@766 266 Content label = new StringContent(cd.isClass() ?
jjg@1410 267 configuration.getText("doclet.Methods_Inherited_From_Class") :
jjg@1410 268 configuration.getText("doclet.Methods_Inherited_From_Interface"));
bpatel@766 269 Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING,
bpatel@766 270 label);
bpatel@766 271 labelHeading.addContent(writer.getSpace());
bpatel@766 272 labelHeading.addContent(classLink);
bpatel@766 273 inheritedTree.addContent(labelHeading);
duke@1 274 }
duke@1 275
bpatel@766 276 /**
bpatel@766 277 * {@inheritDoc}
bpatel@766 278 */
bpatel@766 279 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
duke@1 280 MethodDoc meth = (MethodDoc)member;
bpatel@766 281 addModifierAndType(meth, meth.returnType(), tdSummaryType);
duke@1 282 }
duke@1 283
bpatel@766 284 /**
bpatel@766 285 * {@inheritDoc}
bpatel@766 286 */
bpatel@766 287 protected static void addOverridden(HtmlDocletWriter writer,
bpatel@766 288 Type overriddenType, MethodDoc method, Content dl) {
jjg@1410 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() ||
jjg@1410 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 }
bpatel@766 303 Content label = writer.overridesLabel;
duke@1 304 int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
duke@1 305
duke@1 306 if (method != null) {
jjg@1410 307 if (overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
duke@1 308 //Abstract method is implemented from abstract class,
duke@1 309 //not overridden
bpatel@766 310 label = writer.specifiedByLabel;
duke@1 311 context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
duke@1 312 }
bpatel@766 313 Content dt = HtmlTree.DT(HtmlTree.STRONG(label));
bpatel@766 314 dl.addContent(dt);
bpatel@766 315 Content overriddenTypeLink = new RawHtml(
jjg@1410 316 writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType)));
bpatel@766 317 Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink);
duke@1 318 String name = method.name();
bpatel@766 319 Content methlink = new RawHtml(writer.getLink(
jjg@1410 320 new LinkInfoImpl(writer.configuration, LinkInfoImpl.CONTEXT_MEMBER,
bpatel@766 321 overriddenType.asClassDoc(),
bpatel@766 322 writer.getAnchor(method), name, false)));
bpatel@766 323 Content codeMethLink = HtmlTree.CODE(methlink);
bpatel@766 324 Content dd = HtmlTree.DD(codeMethLink);
bpatel@766 325 dd.addContent(writer.getSpace());
bpatel@766 326 dd.addContent(writer.getResource("doclet.in_class"));
bpatel@766 327 dd.addContent(writer.getSpace());
bpatel@766 328 dd.addContent(codeOverridenTypeLink);
bpatel@766 329 dl.addContent(dd);
duke@1 330 }
duke@1 331 }
duke@1 332
duke@1 333 /**
duke@1 334 * Parse the &lt;Code&gt; tag and return the text.
duke@1 335 */
duke@1 336 protected String parseCodeTag(String tag){
duke@1 337 if(tag == null){
duke@1 338 return "";
duke@1 339 }
duke@1 340
duke@1 341 String lc = tag.toLowerCase();
duke@1 342 int begin = lc.indexOf("<code>");
duke@1 343 int end = lc.indexOf("</code>");
duke@1 344 if(begin == -1 || end == -1 || end <= begin){
duke@1 345 return tag;
duke@1 346 } else {
duke@1 347 return tag.substring(begin + 6, end);
duke@1 348 }
duke@1 349 }
duke@1 350
bpatel@766 351 /**
bpatel@766 352 * {@inheritDoc}
bpatel@766 353 */
bpatel@766 354 protected static void addImplementsInfo(HtmlDocletWriter writer,
bpatel@766 355 MethodDoc method, Content dl) {
duke@1 356 if(writer.configuration.nocomment){
duke@1 357 return;
duke@1 358 }
duke@1 359 ImplementedMethods implementedMethodsFinder =
bpatel@766 360 new ImplementedMethods(method, writer.configuration);
duke@1 361 MethodDoc[] implementedMethods = implementedMethodsFinder.build();
duke@1 362 for (int i = 0; i < implementedMethods.length; i++) {
duke@1 363 MethodDoc implementedMeth = implementedMethods[i];
duke@1 364 Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
bpatel@766 365 Content intfaclink = new RawHtml(writer.getLink(new LinkInfoImpl(
jjg@1410 366 writer.configuration, LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
bpatel@766 367 Content codeIntfacLink = HtmlTree.CODE(intfaclink);
bpatel@766 368 Content dt = HtmlTree.DT(HtmlTree.STRONG(writer.specifiedByLabel));
bpatel@766 369 dl.addContent(dt);
bpatel@766 370 Content methlink = new RawHtml(writer.getDocLink(
bpatel@766 371 LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
bpatel@766 372 implementedMeth.name(), false));
bpatel@766 373 Content codeMethLink = HtmlTree.CODE(methlink);
bpatel@766 374 Content dd = HtmlTree.DD(codeMethLink);
bpatel@766 375 dd.addContent(writer.getSpace());
bpatel@766 376 dd.addContent(writer.getResource("doclet.in_interface"));
bpatel@766 377 dd.addContent(writer.getSpace());
bpatel@766 378 dd.addContent(codeIntfacLink);
bpatel@766 379 dl.addContent(dd);
duke@1 380 }
duke@1 381 }
duke@1 382
bpatel@766 383 /**
bpatel@766 384 * Add the return type.
bpatel@766 385 *
bpatel@766 386 * @param method the method being documented.
bpatel@766 387 * @param htmltree the content tree to which the return type will be added
bpatel@766 388 */
bpatel@766 389 protected void addReturnType(MethodDoc method, Content htmltree) {
bpatel@766 390 Type type = method.returnType();
bpatel@766 391 if (type != null) {
bpatel@766 392 Content linkContent = new RawHtml(writer.getLink(
jjg@1410 393 new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_RETURN_TYPE, type)));
bpatel@766 394 htmltree.addContent(linkContent);
bpatel@766 395 htmltree.addContent(writer.getSpace());
duke@1 396 }
duke@1 397 }
duke@1 398
bpatel@766 399 /**
bpatel@766 400 * {@inheritDoc}
bpatel@766 401 */
bpatel@766 402 protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
duke@1 403 if (link) {
jjg@1372 404 return writer.getHyperLink((cd == null)?
bpatel@766 405 "method_summary":
bpatel@766 406 "methods_inherited_from_class_" +
jjg@1410 407 configuration.getClassName(cd),
bpatel@766 408 writer.getResource("doclet.navMethod"));
duke@1 409 } else {
bpatel@766 410 return writer.getResource("doclet.navMethod");
bpatel@766 411 }
bpatel@766 412 }
bpatel@766 413
bpatel@766 414 /**
bpatel@766 415 * {@inheritDoc}
bpatel@766 416 */
bpatel@766 417 protected void addNavDetailLink(boolean link, Content liNav) {
bpatel@766 418 if (link) {
jjg@1372 419 liNav.addContent(writer.getHyperLink("method_detail",
bpatel@766 420 writer.getResource("doclet.navMethod")));
bpatel@766 421 } else {
bpatel@766 422 liNav.addContent(writer.getResource("doclet.navMethod"));
duke@1 423 }
duke@1 424 }
duke@1 425 }

mercurial