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

changeset 1
9a66ca7c79fa
child 182
47a62d8d98b4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,405 @@
     1.4 +/*
     1.5 + * Copyright 1997-2004 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.formats.html;
    1.30 +
    1.31 +import com.sun.tools.doclets.internal.toolkit.*;
    1.32 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.33 +import com.sun.tools.doclets.internal.toolkit.taglets.*;
    1.34 +
    1.35 +import java.io.*;
    1.36 +import com.sun.javadoc.*;
    1.37 +
    1.38 +/**
    1.39 + * Writes method documentation in HTML format.
    1.40 + *
    1.41 + * @author Robert Field
    1.42 + * @author Atul M Dambalkar
    1.43 + * @author Jamie Ho (rewrite)
    1.44 + */
    1.45 +public class MethodWriterImpl extends AbstractExecutableMemberWriter
    1.46 +        implements MethodWriter, MemberSummaryWriter {
    1.47 +
    1.48 +    private boolean printedSummaryHeader = false;
    1.49 +
    1.50 +    /**
    1.51 +     * Construct a new MethodWriterImpl.
    1.52 +     *
    1.53 +     * @param writer the writer for the class that the methods belong to.
    1.54 +     * @param classDoc the class being documented.
    1.55 +     */
    1.56 +    public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
    1.57 +        super(writer, classDoc);
    1.58 +    }
    1.59 +
    1.60 +    /**
    1.61 +     * Construct a new MethodWriterImpl.
    1.62 +     *
    1.63 +     * @param writer The writer for the class that the methods belong to.
    1.64 +     */
    1.65 +    public MethodWriterImpl(SubWriterHolderWriter writer) {
    1.66 +        super(writer);
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Write the methods summary header for the given class.
    1.71 +     *
    1.72 +     * @param classDoc the class the summary belongs to.
    1.73 +     */
    1.74 +    public void writeMemberSummaryHeader(ClassDoc classDoc) {
    1.75 +        printedSummaryHeader = true;
    1.76 +        writer.println();
    1.77 +        writer.println("<!-- ========== METHOD SUMMARY =========== -->");
    1.78 +        writer.println();
    1.79 +        writer.printSummaryHeader(this, classDoc);
    1.80 +    }
    1.81 +
    1.82 +    /**
    1.83 +     * Write the methods summary footer for the given class.
    1.84 +     *
    1.85 +     * @param classDoc the class the summary belongs to.
    1.86 +     */
    1.87 +    public void writeMemberSummaryFooter(ClassDoc classDoc) {
    1.88 +        writer.printSummaryFooter(this, classDoc);
    1.89 +    }
    1.90 +
    1.91 +    /**
    1.92 +     * Write the inherited methods summary header for the given class.
    1.93 +     *
    1.94 +     * @param classDoc the class the summary belongs to.
    1.95 +     */
    1.96 +    public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
    1.97 +        if(! printedSummaryHeader){
    1.98 +            //We don't want inherited summary to not be under heading.
    1.99 +            writeMemberSummaryHeader(classDoc);
   1.100 +            writeMemberSummaryFooter(classDoc);
   1.101 +            printedSummaryHeader = true;
   1.102 +        }
   1.103 +        writer.printInheritedSummaryHeader(this, classDoc);
   1.104 +    }
   1.105 +
   1.106 +    /**
   1.107 +     * {@inheritDoc}
   1.108 +     */
   1.109 +    public void writeInheritedMemberSummary(ClassDoc classDoc,
   1.110 +        ProgramElementDoc method, boolean isFirst, boolean isLast) {
   1.111 +        writer.printInheritedSummaryMember(this, classDoc, method, isFirst);
   1.112 +    }
   1.113 +
   1.114 +    /**
   1.115 +     * Write the inherited methods summary footer for the given class.
   1.116 +     *
   1.117 +     * @param classDoc the class the summary belongs to.
   1.118 +     */
   1.119 +    public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
   1.120 +        writer.printInheritedSummaryFooter(this, classDoc);        ;
   1.121 +    }
   1.122 +
   1.123 +    /**
   1.124 +     * Write the header for the method documentation.
   1.125 +     *
   1.126 +     * @param classDoc the class that the methods belong to.
   1.127 +     */
   1.128 +    public void writeHeader(ClassDoc classDoc, String header) {
   1.129 +        writer.println();
   1.130 +        writer.println("<!-- ============ METHOD DETAIL ========== -->");
   1.131 +        writer.println();
   1.132 +        writer.anchor("method_detail");
   1.133 +        writer.printTableHeadingBackground(header);
   1.134 +    }
   1.135 +
   1.136 +    /**
   1.137 +     * Write the method header for the given method.
   1.138 +     *
   1.139 +     * @param method the method being documented.
   1.140 +     * @param isFirst the flag to indicate whether or not the method is the
   1.141 +     *        first to be documented.
   1.142 +     */
   1.143 +    public void writeMethodHeader(MethodDoc method, boolean isFirst) {
   1.144 +        if (! isFirst) {
   1.145 +            writer.printMemberHeader();
   1.146 +        }
   1.147 +        writer.println();
   1.148 +        String erasureAnchor;
   1.149 +        if ((erasureAnchor = getErasureAnchor(method)) != null) {
   1.150 +            writer.anchor(erasureAnchor);
   1.151 +        }
   1.152 +        writer.anchor(method);
   1.153 +        writer.h3();
   1.154 +        writer.print(method.name());
   1.155 +        writer.h3End();
   1.156 +    }
   1.157 +
   1.158 +    /**
   1.159 +     * Write the signature for the given method.
   1.160 +     *
   1.161 +     * @param method the method being documented.
   1.162 +     */
   1.163 +    public void writeSignature(MethodDoc method) {
   1.164 +        writer.displayLength = 0;
   1.165 +        writer.pre();
   1.166 +        writer.writeAnnotationInfo(method);
   1.167 +        printModifiers(method);
   1.168 +        writeTypeParameters(method);
   1.169 +        printReturnType(method);
   1.170 +        if (configuration().linksource) {
   1.171 +            writer.printSrcLink(method, method.name());
   1.172 +        } else {
   1.173 +            bold(method.name());
   1.174 +        }
   1.175 +        writeParameters(method);
   1.176 +        writeExceptions(method);
   1.177 +        writer.preEnd();
   1.178 +        writer.dl();
   1.179 +    }
   1.180 +
   1.181 +    /**
   1.182 +     * Write the deprecated output for the given method.
   1.183 +     *
   1.184 +     * @param method the method being documented.
   1.185 +     */
   1.186 +    public void writeDeprecated(MethodDoc method) {
   1.187 +        String output = ((TagletOutputImpl)
   1.188 +            (new DeprecatedTaglet()).getTagletOutput(method,
   1.189 +            writer.getTagletWriterInstance(false))).toString();
   1.190 +        if (output != null && output.trim().length() > 0) {
   1.191 +            writer.print(output);
   1.192 +        }
   1.193 +    }
   1.194 +
   1.195 +    /**
   1.196 +     * Write the comments for the given method.
   1.197 +     *
   1.198 +     * @param method the method being documented.
   1.199 +     */
   1.200 +    public void writeComments(Type holder, MethodDoc method) {
   1.201 +        ClassDoc holderClassDoc = holder.asClassDoc();
   1.202 +        if (method.inlineTags().length > 0) {
   1.203 +            if (holder.asClassDoc().equals(classdoc) ||
   1.204 +                (! (holderClassDoc.isPublic() ||
   1.205 +                    Util.isLinkable(holderClassDoc, configuration())))) {
   1.206 +                writer.dd();
   1.207 +                writer.printInlineComment(method);
   1.208 +            } else {
   1.209 +                String classlink = writer.codeText(
   1.210 +                    writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
   1.211 +                        holder.asClassDoc(), method,
   1.212 +                        holder.asClassDoc().isIncluded() ?
   1.213 +                            holder.typeName() : holder.qualifiedTypeName(),
   1.214 +                        false));
   1.215 +                writer.dd();
   1.216 +                writer.boldText(holder.asClassDoc().isClass()?
   1.217 +                        "doclet.Description_From_Class":
   1.218 +                        "doclet.Description_From_Interface",
   1.219 +                    classlink);
   1.220 +                writer.ddEnd();
   1.221 +                writer.dd();
   1.222 +                writer.printInlineComment(method);
   1.223 +            }
   1.224 +        }
   1.225 +    }
   1.226 +
   1.227 +    /**
   1.228 +     * Write the tag output for the given method.
   1.229 +     *
   1.230 +     * @param method the method being documented.
   1.231 +     */
   1.232 +    public void writeTags(MethodDoc method) {
   1.233 +        writer.printTags(method);
   1.234 +    }
   1.235 +
   1.236 +    /**
   1.237 +     * Write the method footer.
   1.238 +     */
   1.239 +    public void writeMethodFooter() {
   1.240 +        writer.ddEnd();
   1.241 +        writer.dlEnd();
   1.242 +    }
   1.243 +
   1.244 +    /**
   1.245 +     * Write the footer for the method documentation.
   1.246 +     *
   1.247 +     * @param classDoc the class that the methods belong to.
   1.248 +     */
   1.249 +    public void writeFooter(ClassDoc classDoc) {
   1.250 +        //No footer to write for method documentation
   1.251 +    }
   1.252 +
   1.253 +    /**
   1.254 +     * Close the writer.
   1.255 +     */
   1.256 +    public void close() throws IOException {
   1.257 +        writer.close();
   1.258 +    }
   1.259 +
   1.260 +    public int getMemberKind() {
   1.261 +        return VisibleMemberMap.METHODS;
   1.262 +    }
   1.263 +
   1.264 +    public void printSummaryLabel(ClassDoc cd) {
   1.265 +        writer.boldText("doclet.Method_Summary");
   1.266 +    }
   1.267 +
   1.268 +    public void printSummaryAnchor(ClassDoc cd) {
   1.269 +        writer.anchor("method_summary");
   1.270 +    }
   1.271 +
   1.272 +    public void printInheritedSummaryAnchor(ClassDoc cd) {
   1.273 +        writer.anchor("methods_inherited_from_class_" +
   1.274 +            ConfigurationImpl.getInstance().getClassName(cd));
   1.275 +    }
   1.276 +
   1.277 +    public void printInheritedSummaryLabel(ClassDoc cd) {
   1.278 +        String classlink = writer.getPreQualifiedClassLink(
   1.279 +            LinkInfoImpl.CONTEXT_MEMBER, cd, false);
   1.280 +        writer.bold();
   1.281 +        String key = cd.isClass()?
   1.282 +            "doclet.Methods_Inherited_From_Class" :
   1.283 +            "doclet.Methods_Inherited_From_Interface";
   1.284 +        writer.printText(key, classlink);
   1.285 +        writer.boldEnd();
   1.286 +    }
   1.287 +
   1.288 +    protected void printSummaryType(ProgramElementDoc member) {
   1.289 +        MethodDoc meth = (MethodDoc)member;
   1.290 +        printModifierAndType(meth, meth.returnType());
   1.291 +    }
   1.292 +
   1.293 +    protected static void printOverridden(HtmlDocletWriter writer,
   1.294 +            Type overriddenType, MethodDoc method) {
   1.295 +        if(writer.configuration.nocomment){
   1.296 +            return;
   1.297 +        }
   1.298 +        ClassDoc holderClassDoc = overriddenType.asClassDoc();
   1.299 +        if (! (holderClassDoc.isPublic() ||
   1.300 +            Util.isLinkable(holderClassDoc, writer.configuration()))) {
   1.301 +            //This is an implementation detail that should not be documented.
   1.302 +            return;
   1.303 +        }
   1.304 +        if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
   1.305 +            //The class is included but the method is not.  That means that it
   1.306 +            //is not visible so don't document this.
   1.307 +            return;
   1.308 +        }
   1.309 +        String label = "doclet.Overrides";
   1.310 +        int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
   1.311 +
   1.312 +        if (method != null) {
   1.313 +            if(overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
   1.314 +                //Abstract method is implemented from abstract class,
   1.315 +                //not overridden
   1.316 +                label = "doclet.Specified_By";
   1.317 +                context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
   1.318 +            }
   1.319 +            String overriddenTypeLink = writer.codeText(
   1.320 +                writer.getLink(new LinkInfoImpl(context, overriddenType)));
   1.321 +            String name = method.name();
   1.322 +            writer.dt();
   1.323 +            writer.boldText(label);
   1.324 +            writer.dd();
   1.325 +            String methLink = writer.codeText(
   1.326 +                writer.getLink(
   1.327 +                    new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
   1.328 +                        overriddenType.asClassDoc(),
   1.329 +                        writer.getAnchor(method), name, false)
   1.330 +                ));
   1.331 +            writer.printText("doclet.in_class", methLink, overriddenTypeLink);
   1.332 +        }
   1.333 +    }
   1.334 +
   1.335 +    /**
   1.336 +     * Parse the &lt;Code&gt; tag and return the text.
   1.337 +     */
   1.338 +    protected String parseCodeTag(String tag){
   1.339 +        if(tag == null){
   1.340 +            return "";
   1.341 +        }
   1.342 +
   1.343 +        String lc = tag.toLowerCase();
   1.344 +        int begin = lc.indexOf("<code>");
   1.345 +        int end = lc.indexOf("</code>");
   1.346 +        if(begin == -1 || end == -1 || end <= begin){
   1.347 +            return tag;
   1.348 +        } else {
   1.349 +            return tag.substring(begin + 6, end);
   1.350 +        }
   1.351 +    }
   1.352 +
   1.353 +    protected static void printImplementsInfo(HtmlDocletWriter writer,
   1.354 +            MethodDoc method) {
   1.355 +        if(writer.configuration.nocomment){
   1.356 +            return;
   1.357 +        }
   1.358 +        ImplementedMethods implementedMethodsFinder =
   1.359 +            new ImplementedMethods(method, writer.configuration);
   1.360 +        MethodDoc[] implementedMethods = implementedMethodsFinder.build();
   1.361 +        for (int i = 0; i < implementedMethods.length; i++) {
   1.362 +            MethodDoc implementedMeth = implementedMethods[i];
   1.363 +            Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
   1.364 +            String methlink = "";
   1.365 +            String intfaclink = writer.codeText(
   1.366 +                writer.getLink(new LinkInfoImpl(
   1.367 +                    LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
   1.368 +            writer.dt();
   1.369 +            writer.boldText("doclet.Specified_By");
   1.370 +            writer.dd();
   1.371 +            methlink = writer.codeText(writer.getDocLink(
   1.372 +                LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
   1.373 +                implementedMeth.name(), false));
   1.374 +            writer.printText("doclet.in_interface", methlink, intfaclink);
   1.375 +        }
   1.376 +
   1.377 +    }
   1.378 +
   1.379 +    protected void printReturnType(MethodDoc method) {
   1.380 +        Type type = method.returnType();
   1.381 +        if (type != null) {
   1.382 +            writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_RETURN_TYPE,
   1.383 +                type));
   1.384 +            print(' ');
   1.385 +        }
   1.386 +    }
   1.387 +
   1.388 +    protected void printNavSummaryLink(ClassDoc cd, boolean link) {
   1.389 +        if (link) {
   1.390 +            writer.printHyperLink("", (cd == null)?
   1.391 +                "method_summary":
   1.392 +                "methods_inherited_from_class_" +
   1.393 +                ConfigurationImpl.getInstance().getClassName(cd),
   1.394 +                ConfigurationImpl.getInstance().getText("doclet.navMethod"));
   1.395 +        } else {
   1.396 +            writer.printText("doclet.navMethod");
   1.397 +        }
   1.398 +    }
   1.399 +
   1.400 +    protected void printNavDetailLink(boolean link) {
   1.401 +        if (link) {
   1.402 +            writer.printHyperLink("", "method_detail",
   1.403 +                ConfigurationImpl.getInstance().getText("doclet.navMethod"));
   1.404 +        } else {
   1.405 +            writer.printText("doclet.navMethod");
   1.406 +        }
   1.407 +    }
   1.408 +}

mercurial