MethodWriterImpl.java revision 232
0N/A/*
0N/A * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.doclets.formats.html;
0N/A
232N/Aimport java.io.*;
232N/A
232N/Aimport com.sun.javadoc.*;
0N/Aimport com.sun.tools.doclets.internal.toolkit.*;
0N/Aimport com.sun.tools.doclets.internal.toolkit.util.*;
0N/Aimport com.sun.tools.doclets.internal.toolkit.taglets.*;
0N/A
0N/A/**
0N/A * Writes method documentation in HTML format.
0N/A *
0N/A * @author Robert Field
0N/A * @author Atul M Dambalkar
0N/A * @author Jamie Ho (rewrite)
0N/A */
0N/Apublic class MethodWriterImpl extends AbstractExecutableMemberWriter
0N/A implements MethodWriter, MemberSummaryWriter {
0N/A
0N/A private boolean printedSummaryHeader = false;
0N/A
0N/A /**
0N/A * Construct a new MethodWriterImpl.
0N/A *
0N/A * @param writer the writer for the class that the methods belong to.
0N/A * @param classDoc the class being documented.
0N/A */
0N/A public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
0N/A super(writer, classDoc);
0N/A }
0N/A
0N/A /**
0N/A * Construct a new MethodWriterImpl.
0N/A *
0N/A * @param writer The writer for the class that the methods belong to.
0N/A */
0N/A public MethodWriterImpl(SubWriterHolderWriter writer) {
0N/A super(writer);
0N/A }
0N/A
0N/A /**
0N/A * Write the methods summary header for the given class.
0N/A *
0N/A * @param classDoc the class the summary belongs to.
0N/A */
0N/A public void writeMemberSummaryHeader(ClassDoc classDoc) {
0N/A printedSummaryHeader = true;
0N/A writer.println();
0N/A writer.println("<!-- ========== METHOD SUMMARY =========== -->");
0N/A writer.println();
0N/A writer.printSummaryHeader(this, classDoc);
0N/A }
0N/A
0N/A /**
0N/A * Write the methods summary footer for the given class.
0N/A *
0N/A * @param classDoc the class the summary belongs to.
0N/A */
0N/A public void writeMemberSummaryFooter(ClassDoc classDoc) {
0N/A writer.printSummaryFooter(this, classDoc);
0N/A }
0N/A
0N/A /**
0N/A * Write the inherited methods summary header for the given class.
0N/A *
0N/A * @param classDoc the class the summary belongs to.
0N/A */
0N/A public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
0N/A if(! printedSummaryHeader){
0N/A //We don't want inherited summary to not be under heading.
0N/A writeMemberSummaryHeader(classDoc);
0N/A writeMemberSummaryFooter(classDoc);
0N/A printedSummaryHeader = true;
0N/A }
0N/A writer.printInheritedSummaryHeader(this, classDoc);
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A public void writeInheritedMemberSummary(ClassDoc classDoc,
0N/A ProgramElementDoc method, boolean isFirst, boolean isLast) {
0N/A writer.printInheritedSummaryMember(this, classDoc, method, isFirst);
0N/A }
0N/A
0N/A /**
0N/A * Write the inherited methods summary footer for the given class.
0N/A *
0N/A * @param classDoc the class the summary belongs to.
0N/A */
0N/A public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
0N/A writer.printInheritedSummaryFooter(this, classDoc); ;
0N/A }
0N/A
0N/A /**
0N/A * Write the header for the method documentation.
0N/A *
0N/A * @param classDoc the class that the methods belong to.
0N/A */
0N/A public void writeHeader(ClassDoc classDoc, String header) {
0N/A writer.println();
0N/A writer.println("<!-- ============ METHOD DETAIL ========== -->");
0N/A writer.println();
0N/A writer.anchor("method_detail");
0N/A writer.printTableHeadingBackground(header);
0N/A }
0N/A
0N/A /**
0N/A * Write the method header for the given method.
0N/A *
0N/A * @param method the method being documented.
0N/A * @param isFirst the flag to indicate whether or not the method is the
0N/A * first to be documented.
0N/A */
0N/A public void writeMethodHeader(MethodDoc method, boolean isFirst) {
0N/A if (! isFirst) {
0N/A writer.printMemberHeader();
0N/A }
0N/A writer.println();
0N/A String erasureAnchor;
0N/A if ((erasureAnchor = getErasureAnchor(method)) != null) {
0N/A writer.anchor(erasureAnchor);
0N/A }
0N/A writer.anchor(method);
0N/A writer.h3();
0N/A writer.print(method.name());
0N/A writer.h3End();
0N/A }
0N/A
0N/A /**
0N/A * Write the signature for the given method.
0N/A *
0N/A * @param method the method being documented.
0N/A */
0N/A public void writeSignature(MethodDoc method) {
0N/A writer.displayLength = 0;
0N/A writer.pre();
0N/A writer.writeAnnotationInfo(method);
0N/A printModifiers(method);
0N/A writeTypeParameters(method);
0N/A printReturnType(method);
0N/A if (configuration().linksource) {
0N/A writer.printSrcLink(method, method.name());
0N/A } else {
181N/A strong(method.name());
0N/A }
0N/A writeParameters(method);
0N/A writeExceptions(method);
0N/A writer.preEnd();
232N/A assert !writer.getMemberDetailsListPrinted();
0N/A }
0N/A
0N/A /**
0N/A * Write the deprecated output for the given method.
0N/A *
0N/A * @param method the method being documented.
0N/A */
0N/A public void writeDeprecated(MethodDoc method) {
232N/A printDeprecated(method);
0N/A }
0N/A
0N/A /**
0N/A * Write the comments for the given method.
0N/A *
0N/A * @param method the method being documented.
0N/A */
0N/A public void writeComments(Type holder, MethodDoc method) {
0N/A ClassDoc holderClassDoc = holder.asClassDoc();
0N/A if (method.inlineTags().length > 0) {
232N/A writer.printMemberDetailsListStartTag();
0N/A if (holder.asClassDoc().equals(classdoc) ||
0N/A (! (holderClassDoc.isPublic() ||
0N/A Util.isLinkable(holderClassDoc, configuration())))) {
0N/A writer.dd();
0N/A writer.printInlineComment(method);
232N/A writer.ddEnd();
0N/A } else {
0N/A String classlink = writer.codeText(
0N/A writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
0N/A holder.asClassDoc(), method,
0N/A holder.asClassDoc().isIncluded() ?
0N/A holder.typeName() : holder.qualifiedTypeName(),
0N/A false));
0N/A writer.dd();
181N/A writer.strongText(holder.asClassDoc().isClass()?
0N/A "doclet.Description_From_Class":
0N/A "doclet.Description_From_Interface",
0N/A classlink);
0N/A writer.ddEnd();
0N/A writer.dd();
0N/A writer.printInlineComment(method);
232N/A writer.ddEnd();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Write the tag output for the given method.
0N/A *
0N/A * @param method the method being documented.
0N/A */
0N/A public void writeTags(MethodDoc method) {
0N/A writer.printTags(method);
0N/A }
0N/A
0N/A /**
0N/A * Write the method footer.
0N/A */
0N/A public void writeMethodFooter() {
232N/A printMemberFooter();
0N/A }
0N/A
0N/A /**
0N/A * Write the footer for the method documentation.
0N/A *
0N/A * @param classDoc the class that the methods belong to.
0N/A */
0N/A public void writeFooter(ClassDoc classDoc) {
0N/A //No footer to write for method documentation
0N/A }
0N/A
0N/A /**
0N/A * Close the writer.
0N/A */
0N/A public void close() throws IOException {
0N/A writer.close();
0N/A }
0N/A
0N/A public int getMemberKind() {
0N/A return VisibleMemberMap.METHODS;
0N/A }
0N/A
0N/A public void printSummaryLabel(ClassDoc cd) {
181N/A writer.strongText("doclet.Method_Summary");
0N/A }
0N/A
0N/A public void printSummaryAnchor(ClassDoc cd) {
0N/A writer.anchor("method_summary");
0N/A }
0N/A
0N/A public void printInheritedSummaryAnchor(ClassDoc cd) {
0N/A writer.anchor("methods_inherited_from_class_" +
0N/A ConfigurationImpl.getInstance().getClassName(cd));
0N/A }
0N/A
0N/A public void printInheritedSummaryLabel(ClassDoc cd) {
0N/A String classlink = writer.getPreQualifiedClassLink(
0N/A LinkInfoImpl.CONTEXT_MEMBER, cd, false);
181N/A writer.strong();
0N/A String key = cd.isClass()?
0N/A "doclet.Methods_Inherited_From_Class" :
0N/A "doclet.Methods_Inherited_From_Interface";
0N/A writer.printText(key, classlink);
181N/A writer.strongEnd();
0N/A }
0N/A
0N/A protected void printSummaryType(ProgramElementDoc member) {
0N/A MethodDoc meth = (MethodDoc)member;
0N/A printModifierAndType(meth, meth.returnType());
0N/A }
0N/A
0N/A protected static void printOverridden(HtmlDocletWriter writer,
0N/A Type overriddenType, MethodDoc method) {
0N/A if(writer.configuration.nocomment){
0N/A return;
0N/A }
0N/A ClassDoc holderClassDoc = overriddenType.asClassDoc();
0N/A if (! (holderClassDoc.isPublic() ||
0N/A Util.isLinkable(holderClassDoc, writer.configuration()))) {
0N/A //This is an implementation detail that should not be documented.
0N/A return;
0N/A }
0N/A if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
0N/A //The class is included but the method is not. That means that it
0N/A //is not visible so don't document this.
0N/A return;
0N/A }
0N/A String label = "doclet.Overrides";
0N/A int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
0N/A
0N/A if (method != null) {
0N/A if(overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
0N/A //Abstract method is implemented from abstract class,
0N/A //not overridden
0N/A label = "doclet.Specified_By";
0N/A context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
0N/A }
0N/A String overriddenTypeLink = writer.codeText(
0N/A writer.getLink(new LinkInfoImpl(context, overriddenType)));
0N/A String name = method.name();
0N/A writer.dt();
181N/A writer.strongText(label);
232N/A writer.dtEnd();
0N/A writer.dd();
0N/A String methLink = writer.codeText(
0N/A writer.getLink(
0N/A new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
0N/A overriddenType.asClassDoc(),
0N/A writer.getAnchor(method), name, false)
0N/A ));
0N/A writer.printText("doclet.in_class", methLink, overriddenTypeLink);
232N/A writer.ddEnd();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Parse the &lt;Code&gt; tag and return the text.
0N/A */
0N/A protected String parseCodeTag(String tag){
0N/A if(tag == null){
0N/A return "";
0N/A }
0N/A
0N/A String lc = tag.toLowerCase();
0N/A int begin = lc.indexOf("<code>");
0N/A int end = lc.indexOf("</code>");
0N/A if(begin == -1 || end == -1 || end <= begin){
0N/A return tag;
0N/A } else {
0N/A return tag.substring(begin + 6, end);
0N/A }
0N/A }
0N/A
0N/A protected static void printImplementsInfo(HtmlDocletWriter writer,
0N/A MethodDoc method) {
0N/A if(writer.configuration.nocomment){
0N/A return;
0N/A }
0N/A ImplementedMethods implementedMethodsFinder =
0N/A new ImplementedMethods(method, writer.configuration);
0N/A MethodDoc[] implementedMethods = implementedMethodsFinder.build();
0N/A for (int i = 0; i < implementedMethods.length; i++) {
0N/A MethodDoc implementedMeth = implementedMethods[i];
0N/A Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
0N/A String methlink = "";
0N/A String intfaclink = writer.codeText(
0N/A writer.getLink(new LinkInfoImpl(
0N/A LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
0N/A writer.dt();
181N/A writer.strongText("doclet.Specified_By");
232N/A writer.dtEnd();
0N/A writer.dd();
0N/A methlink = writer.codeText(writer.getDocLink(
0N/A LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
0N/A implementedMeth.name(), false));
0N/A writer.printText("doclet.in_interface", methlink, intfaclink);
232N/A writer.ddEnd();
0N/A }
0N/A
0N/A }
0N/A
0N/A protected void printReturnType(MethodDoc method) {
0N/A Type type = method.returnType();
0N/A if (type != null) {
0N/A writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_RETURN_TYPE,
0N/A type));
0N/A print(' ');
0N/A }
0N/A }
0N/A
0N/A protected void printNavSummaryLink(ClassDoc cd, boolean link) {
0N/A if (link) {
0N/A writer.printHyperLink("", (cd == null)?
0N/A "method_summary":
0N/A "methods_inherited_from_class_" +
0N/A ConfigurationImpl.getInstance().getClassName(cd),
0N/A ConfigurationImpl.getInstance().getText("doclet.navMethod"));
0N/A } else {
0N/A writer.printText("doclet.navMethod");
0N/A }
0N/A }
0N/A
0N/A protected void printNavDetailLink(boolean link) {
0N/A if (link) {
0N/A writer.printHyperLink("", "method_detail",
0N/A ConfigurationImpl.getInstance().getText("doclet.navMethod"));
0N/A } else {
0N/A writer.printText("doclet.navMethod");
0N/A }
0N/A }
0N/A}