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

Sat, 08 Sep 2012 22:43:38 -0700

author
bpatel
date
Sat, 08 Sep 2012 22:43:38 -0700
changeset 1324
fa85af323d97
parent 554
9d9f26857129
child 1357
c75be5bc5283
permissions
-rw-r--r--

7180906: Javadoc tool does not apply parameter -nosince
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2001, 2008, 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.*;
    30 import java.util.*;
    32 /**
    33  * A taglet that represents the @throws tag.
    34  *
    35  * This code is not part of an API.
    36  * It is implementation that is subject to change.
    37  * Do not use it as an API
    38  *
    39  * @author Jamie Ho
    40  * @since 1.4
    41  */
    42 public class ThrowsTaglet extends BaseExecutableMemberTaglet
    43     implements InheritableTaglet {
    45     public ThrowsTaglet() {
    46         name = "throws";
    47     }
    49     /**
    50      * {@inheritDoc}
    51      */
    52     public void inherit(DocFinder.Input input, DocFinder.Output output) {
    53         ClassDoc exception;
    54         if (input.tagId == null) {
    55             ThrowsTag throwsTag = (ThrowsTag) input.tag;
    56             exception = throwsTag.exception();
    57             input.tagId = exception == null ?
    58                 throwsTag.exceptionName() :
    59                 throwsTag.exception().qualifiedName();
    60         } else {
    61             exception = input.method.containingClass().findClass(input.tagId);
    62         }
    64         ThrowsTag[] tags = input.method.throwsTags();
    65         for (int i = 0; i < tags.length; i++) {
    66             if (input.tagId.equals(tags[i].exceptionName()) ||
    67                 (tags[i].exception() != null &&
    68                     (input.tagId.equals(tags[i].exception().qualifiedName())))) {
    69                 output.holder = input.method;
    70                 output.holderTag = tags[i];
    71                 output.inlineTags = input.isFirstSentence ?
    72                     tags[i].firstSentenceTags() : tags[i].inlineTags();
    73                 output.tagList.add(tags[i]);
    74             } else if (exception != null && tags[i].exception() != null &&
    75                     tags[i].exception().subclassOf(exception)) {
    76                 output.tagList.add(tags[i]);
    77             }
    78         }
    79     }
    81     /**
    82      * Add links for exceptions that are declared but not documented.
    83      */
    84     private TagletOutput linkToUndocumentedDeclaredExceptions(
    85             Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
    86             TagletWriter writer) {
    87         TagletOutput result = writer.getOutputInstance();
    88         //Add links to the exceptions declared but not documented.
    89         for (int i = 0; i < declaredExceptionTypes.length; i++) {
    90             if (declaredExceptionTypes[i].asClassDoc() != null &&
    91                 ! alreadyDocumented.contains(
    92                         declaredExceptionTypes[i].asClassDoc().name()) &&
    93                 ! alreadyDocumented.contains(
    94                     declaredExceptionTypes[i].asClassDoc().qualifiedName())) {
    95                 if (alreadyDocumented.size() == 0) {
    96                     result.appendOutput(writer.getThrowsHeader());
    97                 }
    98                 result.appendOutput(writer.throwsTagOutput(declaredExceptionTypes[i]));
    99                 alreadyDocumented.add(declaredExceptionTypes[i].asClassDoc().name());
   100             }
   101         }
   102         return result;
   103     }
   105     /**
   106      * Inherit throws documentation for exceptions that were declared but not
   107      * documented.
   108      */
   109     private TagletOutput inheritThrowsDocumentation(Doc holder,
   110             Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
   111             TagletWriter writer) {
   112         TagletOutput result = writer.getOutputInstance();
   113         if (holder instanceof MethodDoc) {
   114             Set<Tag> declaredExceptionTags = new LinkedHashSet<Tag>();
   115             for (int j = 0; j < declaredExceptionTypes.length; j++) {
   116                 DocFinder.Output inheritedDoc =
   117                     DocFinder.search(new DocFinder.Input((MethodDoc) holder, this,
   118                         declaredExceptionTypes[j].typeName()));
   119                 if (inheritedDoc.tagList.size() == 0) {
   120                     inheritedDoc = DocFinder.search(new DocFinder.Input(
   121                         (MethodDoc) holder, this,
   122                         declaredExceptionTypes[j].qualifiedTypeName()));
   123                 }
   124                 declaredExceptionTags.addAll(inheritedDoc.tagList);
   125             }
   126             result.appendOutput(throwsTagsOutput(
   127                 declaredExceptionTags.toArray(new ThrowsTag[] {}),
   128                 writer, alreadyDocumented, false));
   129         }
   130         return result;
   131     }
   133     /**
   134      * {@inheritDoc}
   135      */
   136     public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
   137         ExecutableMemberDoc execHolder = (ExecutableMemberDoc) holder;
   138         ThrowsTag[] tags = execHolder.throwsTags();
   139         TagletOutput result = writer.getOutputInstance();
   140         HashSet<String> alreadyDocumented = new HashSet<String>();
   141         if (tags.length > 0) {
   142             result.appendOutput(throwsTagsOutput(
   143                 execHolder.throwsTags(), writer, alreadyDocumented, true));
   144         }
   145         result.appendOutput(inheritThrowsDocumentation(holder,
   146             execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
   147         result.appendOutput(linkToUndocumentedDeclaredExceptions(
   148             execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
   149         return result;
   150     }
   153     /**
   154      * Given an array of <code>Tag</code>s representing this custom
   155      * tag, return its string representation.
   156      * @param throwTags the array of <code>ThrowsTag</code>s to convert.
   157      * @param writer the TagletWriter that will write this tag.
   158      * @param alreadyDocumented the set of exceptions that have already
   159      *        been documented.
   160      * @param allowDups True if we allow duplicate throws tags to be documented.
   161      * @return the TagletOutput representation of this <code>Tag</code>.
   162      */
   163     protected TagletOutput throwsTagsOutput(ThrowsTag[] throwTags,
   164         TagletWriter writer, Set<String> alreadyDocumented, boolean allowDups) {
   165         TagletOutput result = writer.getOutputInstance();
   166         if (throwTags.length > 0) {
   167             for (int i = 0; i < throwTags.length; ++i) {
   168                 ThrowsTag tt = throwTags[i];
   169                 ClassDoc cd = tt.exception();
   170                 if ((!allowDups) && (alreadyDocumented.contains(tt.exceptionName()) ||
   171                     (cd != null && alreadyDocumented.contains(cd.qualifiedName())))) {
   172                     continue;
   173                 }
   174                 if (alreadyDocumented.size() == 0) {
   175                     result.appendOutput(writer.getThrowsHeader());
   176                 }
   177                 result.appendOutput(writer.throwsTagOutput(tt));
   178                 alreadyDocumented.add(cd != null ?
   179                     cd.qualifiedName() : tt.exceptionName());
   180             }
   181         }
   182         return result;
   183     }
   184 }

mercurial