src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ReturnTaglet.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ReturnTaglet.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 + * Copyright 2001-2003 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.internal.toolkit.taglets;
    1.30 +
    1.31 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.32 +import com.sun.javadoc.*;
    1.33 +
    1.34 +/**
    1.35 + * A taglet that represents the @return tag.
    1.36 + *
    1.37 + * This code is not part of an API.
    1.38 + * It is implementation that is subject to change.
    1.39 + * Do not use it as an API
    1.40 + *
    1.41 + * @author Jamie Ho
    1.42 + * @since 1.4
    1.43 + */
    1.44 +public class ReturnTaglet extends BaseExecutableMemberTaglet
    1.45 +        implements InheritableTaglet {
    1.46 +
    1.47 +    public ReturnTaglet() {
    1.48 +        name = "return";
    1.49 +    }
    1.50 +
    1.51 +    /**
    1.52 +     * {@inheritDoc}
    1.53 +     */
    1.54 +    public void inherit(DocFinder.Input input, DocFinder.Output output) {
    1.55 +       Tag[] tags = input.method.tags("return");
    1.56 +        if (tags.length > 0) {
    1.57 +            output.holder = input.method;
    1.58 +            output.holderTag = tags[0];
    1.59 +            output.inlineTags = input.isFirstSentence ?
    1.60 +                tags[0].firstSentenceTags() : tags[0].inlineTags();
    1.61 +        }
    1.62 +    }
    1.63 +
    1.64 +    /**
    1.65 +     * Return true if this <code>Taglet</code>
    1.66 +     * is used in constructor documentation.
    1.67 +     * @return true if this <code>Taglet</code>
    1.68 +     * is used in constructor documentation and false
    1.69 +     * otherwise.
    1.70 +     */
    1.71 +    public boolean inConstructor() {
    1.72 +        return false;
    1.73 +    }
    1.74 +
    1.75 +    /**
    1.76 +     * {@inheritDoc}
    1.77 +     */
    1.78 +    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
    1.79 +        Type returnType = ((MethodDoc) holder).returnType();
    1.80 +        Tag[] tags = holder.tags(name);
    1.81 +
    1.82 +        //Make sure we are not using @return tag on method with void return type.
    1.83 +        if (returnType.isPrimitive() && returnType.typeName().equals("void")) {
    1.84 +            if (tags.length > 0) {
    1.85 +                writer.getMsgRetriever().warning(holder.position(),
    1.86 +                    "doclet.Return_tag_on_void_method");
    1.87 +            }
    1.88 +            return null;
    1.89 +        }
    1.90 +        //Inherit @return tag if necessary.
    1.91 +        if (tags.length == 0) {
    1.92 +            DocFinder.Output inheritedDoc =
    1.93 +                DocFinder.search(new DocFinder.Input((MethodDoc) holder, this));
    1.94 +            tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag};
    1.95 +        }
    1.96 +        return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null;
    1.97 +    }
    1.98 +}

mercurial