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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.taglets;
duke@1 27
duke@1 28 import com.sun.javadoc.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 30 import java.util.*;
duke@1 31
duke@1 32 /**
duke@1 33 * A taglet that represents the @throws tag.
duke@1 34 *
duke@1 35 * This code is not part of an API.
duke@1 36 * It is implementation that is subject to change.
duke@1 37 * Do not use it as an API
duke@1 38 *
duke@1 39 * @author Jamie Ho
duke@1 40 * @since 1.4
duke@1 41 */
duke@1 42 public class ThrowsTaglet extends BaseExecutableMemberTaglet
duke@1 43 implements InheritableTaglet {
duke@1 44
duke@1 45 public ThrowsTaglet() {
duke@1 46 name = "throws";
duke@1 47 }
duke@1 48
duke@1 49 /**
duke@1 50 * {@inheritDoc}
duke@1 51 */
duke@1 52 public void inherit(DocFinder.Input input, DocFinder.Output output) {
duke@1 53 ClassDoc exception;
duke@1 54 if (input.tagId == null) {
duke@1 55 ThrowsTag throwsTag = (ThrowsTag) input.tag;
duke@1 56 exception = throwsTag.exception();
duke@1 57 input.tagId = exception == null ?
duke@1 58 throwsTag.exceptionName() :
duke@1 59 throwsTag.exception().qualifiedName();
duke@1 60 } else {
duke@1 61 exception = input.method.containingClass().findClass(input.tagId);
duke@1 62 }
duke@1 63
duke@1 64 ThrowsTag[] tags = input.method.throwsTags();
duke@1 65 for (int i = 0; i < tags.length; i++) {
duke@1 66 if (input.tagId.equals(tags[i].exceptionName()) ||
duke@1 67 (tags[i].exception() != null &&
duke@1 68 (input.tagId.equals(tags[i].exception().qualifiedName())))) {
duke@1 69 output.holder = input.method;
duke@1 70 output.holderTag = tags[i];
duke@1 71 output.inlineTags = input.isFirstSentence ?
duke@1 72 tags[i].firstSentenceTags() : tags[i].inlineTags();
duke@1 73 output.tagList.add(tags[i]);
duke@1 74 } else if (exception != null && tags[i].exception() != null &&
duke@1 75 tags[i].exception().subclassOf(exception)) {
duke@1 76 output.tagList.add(tags[i]);
duke@1 77 }
duke@1 78 }
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * Add links for exceptions that are declared but not documented.
duke@1 83 */
duke@1 84 private TagletOutput linkToUndocumentedDeclaredExceptions(
jjg@74 85 Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
duke@1 86 TagletWriter writer) {
duke@1 87 TagletOutput result = writer.getOutputInstance();
duke@1 88 //Add links to the exceptions declared but not documented.
duke@1 89 for (int i = 0; i < declaredExceptionTypes.length; i++) {
duke@1 90 if (declaredExceptionTypes[i].asClassDoc() != null &&
duke@1 91 ! alreadyDocumented.contains(
duke@1 92 declaredExceptionTypes[i].asClassDoc().name()) &&
duke@1 93 ! alreadyDocumented.contains(
duke@1 94 declaredExceptionTypes[i].asClassDoc().qualifiedName())) {
duke@1 95 if (alreadyDocumented.size() == 0) {
duke@1 96 result.appendOutput(writer.getThrowsHeader());
duke@1 97 }
duke@1 98 result.appendOutput(writer.throwsTagOutput(declaredExceptionTypes[i]));
duke@1 99 alreadyDocumented.add(declaredExceptionTypes[i].asClassDoc().name());
duke@1 100 }
duke@1 101 }
duke@1 102 return result;
duke@1 103 }
duke@1 104
duke@1 105 /**
duke@1 106 * Inherit throws documentation for exceptions that were declared but not
duke@1 107 * documented.
duke@1 108 */
duke@1 109 private TagletOutput inheritThrowsDocumentation(Doc holder,
jjg@74 110 Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
duke@1 111 TagletWriter writer) {
duke@1 112 TagletOutput result = writer.getOutputInstance();
duke@1 113 if (holder instanceof MethodDoc) {
jjg@74 114 Set<Tag> declaredExceptionTags = new LinkedHashSet<Tag>();
duke@1 115 for (int j = 0; j < declaredExceptionTypes.length; j++) {
duke@1 116 DocFinder.Output inheritedDoc =
duke@1 117 DocFinder.search(new DocFinder.Input((MethodDoc) holder, this,
duke@1 118 declaredExceptionTypes[j].typeName()));
duke@1 119 if (inheritedDoc.tagList.size() == 0) {
duke@1 120 inheritedDoc = DocFinder.search(new DocFinder.Input(
duke@1 121 (MethodDoc) holder, this,
duke@1 122 declaredExceptionTypes[j].qualifiedTypeName()));
duke@1 123 }
duke@1 124 declaredExceptionTags.addAll(inheritedDoc.tagList);
duke@1 125 }
duke@1 126 result.appendOutput(throwsTagsOutput(
jjg@74 127 declaredExceptionTags.toArray(new ThrowsTag[] {}),
duke@1 128 writer, alreadyDocumented, false));
duke@1 129 }
duke@1 130 return result;
duke@1 131 }
duke@1 132
duke@1 133 /**
duke@1 134 * {@inheritDoc}
duke@1 135 */
duke@1 136 public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
duke@1 137 ExecutableMemberDoc execHolder = (ExecutableMemberDoc) holder;
duke@1 138 ThrowsTag[] tags = execHolder.throwsTags();
duke@1 139 TagletOutput result = writer.getOutputInstance();
jjg@74 140 HashSet<String> alreadyDocumented = new HashSet<String>();
duke@1 141 if (tags.length > 0) {
duke@1 142 result.appendOutput(throwsTagsOutput(
duke@1 143 execHolder.throwsTags(), writer, alreadyDocumented, true));
duke@1 144 }
duke@1 145 result.appendOutput(inheritThrowsDocumentation(holder,
duke@1 146 execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
duke@1 147 result.appendOutput(linkToUndocumentedDeclaredExceptions(
duke@1 148 execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
duke@1 149 return result;
duke@1 150 }
duke@1 151
duke@1 152
duke@1 153 /**
duke@1 154 * Given an array of <code>Tag</code>s representing this custom
duke@1 155 * tag, return its string representation.
duke@1 156 * @param throwTags the array of <code>ThrowsTag</code>s to convert.
duke@1 157 * @param writer the TagletWriter that will write this tag.
duke@1 158 * @param alreadyDocumented the set of exceptions that have already
duke@1 159 * been documented.
duke@1 160 * @param allowDups True if we allow duplicate throws tags to be documented.
duke@1 161 * @return the TagletOutput representation of this <code>Tag</code>.
duke@1 162 */
duke@1 163 protected TagletOutput throwsTagsOutput(ThrowsTag[] throwTags,
jjg@74 164 TagletWriter writer, Set<String> alreadyDocumented, boolean allowDups) {
duke@1 165 TagletOutput result = writer.getOutputInstance();
duke@1 166 if (throwTags.length > 0) {
duke@1 167 for (int i = 0; i < throwTags.length; ++i) {
duke@1 168 ThrowsTag tt = throwTags[i];
duke@1 169 ClassDoc cd = tt.exception();
duke@1 170 if ((!allowDups) && (alreadyDocumented.contains(tt.exceptionName()) ||
duke@1 171 (cd != null && alreadyDocumented.contains(cd.qualifiedName())))) {
duke@1 172 continue;
duke@1 173 }
duke@1 174 if (alreadyDocumented.size() == 0) {
duke@1 175 result.appendOutput(writer.getThrowsHeader());
duke@1 176 }
duke@1 177 result.appendOutput(writer.throwsTagOutput(tt));
duke@1 178 alreadyDocumented.add(cd != null ?
duke@1 179 cd.qualifiedName() : tt.exceptionName());
duke@1 180 }
duke@1 181 }
duke@1 182 return result;
duke@1 183 }
duke@1 184 }

mercurial