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

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 1
9a66ca7c79fa
child 1359
25e14ad23cef
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit.taglets;
    28 import com.sun.javadoc.*;
    29 import com.sun.tools.doclets.internal.toolkit.util.*;
    31 /**
    32  * An inline Taglet representing the <b>inheritDoc</b> tag. This tag should only
    33  * be used with a method.  It is used to inherit documentation from overriden
    34  * and implemented methods.
    35  *
    36  * This code is not part of an API.
    37  * It is implementation that is subject to change.
    38  * Do not use it as an API
    39  *
    40  * @author Jamie Ho
    41  * @since 1.4
    42  */
    44 public class InheritDocTaglet extends BaseInlineTaglet {
    46     /**
    47      * The inline tag that would appear in the documentation if
    48      * the writer wanted documentation to be inherited.
    49      */
    50     public static final String INHERIT_DOC_INLINE_TAG = "{@inheritDoc}";
    52     /**
    53      * Construct a new InheritDocTaglet.
    54      */
    55     public InheritDocTaglet () {
    56         name = "inheritDoc";
    57     }
    59     /**
    60      * Will return false because this inline tag may
    61      * only appear in Methods.
    62      * @return false since this is not a method.
    63      */
    64     public boolean inField() {
    65         return false;
    66     }
    68     /**
    69      * Will return false because this inline tag may
    70      * only appear in Methods.
    71      * @return false since this is not a method.
    72      */
    73     public boolean inConstructor() {
    74         return false;
    75     }
    77     /**
    78      * Will return false because this inline tag may
    79      * only appear in Methods.
    80      * @return false since this is not a method.
    81      */
    82     public boolean inOverview() {
    83         return false;
    84     }
    86     /**
    87      * Will return false because this inline tag may
    88      * only appear in Methods.
    89      * @return false since this is not a method.
    90      */
    91     public boolean inPackage() {
    92         return false;
    93     }
    95     /**
    96      * Will return false because this inline tag may
    97      * only appear in Methods.
    98      * @return false since this is not a method.
    99      */
   100     public boolean inType() {
   101         return false;
   102     }
   104     /**
   105      * Given a <code>MethodDoc</code> item, a <code>Tag</code> in the
   106      * <code>MethodDoc</code> item and a String, replace all occurances
   107      * of @inheritDoc with documentation from it's superclass or superinterface.
   108      *
   109      * @param writer the writer that is writing the output.
   110      * @param md the {@link MethodDoc} that we are documenting.
   111      * @param holderTag the tag that holds the inheritDoc tag.
   112      * @param isFirstSentence true if we only want to inherit the first sentence.
   113      */
   114     private TagletOutput retrieveInheritedDocumentation(TagletWriter writer,
   115             MethodDoc md, Tag holderTag, boolean isFirstSentence) {
   116         TagletOutput replacement = writer.getTagletOutputInstance();
   118         Taglet inheritableTaglet = holderTag == null ?
   119             null : writer.configuration().tagletManager.getTaglet(holderTag.name());
   120         if (inheritableTaglet != null &&
   121             !(inheritableTaglet instanceof InheritableTaglet)) {
   122                 //This tag does not support inheritence.
   123                 writer.configuration().message.warning(md.position(),
   124                 "doclet.noInheritedDoc", md.name() + md.flatSignature());
   125          }
   126         DocFinder.Output inheritedDoc =
   127             DocFinder.search(new DocFinder.Input(md,
   128                 (InheritableTaglet) inheritableTaglet, holderTag,
   129                 isFirstSentence, true));
   130         if (inheritedDoc.isValidInheritDocTag == false) {
   131             writer.configuration().message.warning(md.position(),
   132                 "doclet.noInheritedDoc", md.name() + md.flatSignature());
   133         } else if (inheritedDoc.inlineTags.length > 0) {
   134             replacement = writer.commentTagsToOutput(inheritedDoc.holderTag,
   135                 inheritedDoc.holder, inheritedDoc.inlineTags, isFirstSentence);
   136         }
   137         return replacement;
   138     }
   140     /**
   141      * Given the <code>Tag</code> representation of this custom
   142      * tag, return its string representation, which is output
   143      * to the generated page.
   144      * @param tag the <code>Tag</code> representation of this custom tag.
   145      * @param tagletWriter the taglet writer for output.
   146      * @return the TagletOutput representation of this <code>Tag</code>.
   147      */
   148     public TagletOutput getTagletOutput(Tag tag, TagletWriter tagletWriter) {
   149         if (! (tag.holder() instanceof MethodDoc)) {
   150             return tagletWriter.getOutputInstance();
   151         }
   152         return tag.name().equals("@inheritDoc") ?
   153                 retrieveInheritedDocumentation(tagletWriter, (MethodDoc) tag.holder(), null, tagletWriter.isFirstSentence) :
   154                 retrieveInheritedDocumentation(tagletWriter, (MethodDoc) tag.holder(), tag, tagletWriter.isFirstSentence);
   155     }
   156 }

mercurial