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

Tue, 18 Jun 2013 20:56:04 -0700

author
mfang
date
Tue, 18 Jun 2013 20:56:04 -0700
changeset 1841
792c40d5185a
parent 1751
ca8808c88f94
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8015657: jdk8 l10n resource file translation update 3
Reviewed-by: yhuang

duke@1 1 /*
jjg@1724 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. 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
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle 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 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.taglets;
duke@1 27
jjg@1357 28 import java.util.*;
jjg@1357 29
duke@1 30 import com.sun.javadoc.*;
jjg@1751 31 import com.sun.tools.doclets.internal.toolkit.Content;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 33
duke@1 34 /**
duke@1 35 * A taglet that represents the @throws tag.
duke@1 36 *
jjg@1359 37 * <p><b>This is NOT part of any supported API.
jjg@1359 38 * If you write code that depends on this, you do so at your own risk.
jjg@1359 39 * This code and its internal interfaces are subject to change or
jjg@1359 40 * deletion without notice.</b>
duke@1 41 *
duke@1 42 * @author Jamie Ho
duke@1 43 * @since 1.4
duke@1 44 */
duke@1 45 public class ThrowsTaglet extends BaseExecutableMemberTaglet
duke@1 46 implements InheritableTaglet {
duke@1 47
duke@1 48 public ThrowsTaglet() {
duke@1 49 name = "throws";
duke@1 50 }
duke@1 51
duke@1 52 /**
duke@1 53 * {@inheritDoc}
duke@1 54 */
duke@1 55 public void inherit(DocFinder.Input input, DocFinder.Output output) {
duke@1 56 ClassDoc exception;
duke@1 57 if (input.tagId == null) {
duke@1 58 ThrowsTag throwsTag = (ThrowsTag) input.tag;
duke@1 59 exception = throwsTag.exception();
duke@1 60 input.tagId = exception == null ?
duke@1 61 throwsTag.exceptionName() :
duke@1 62 throwsTag.exception().qualifiedName();
duke@1 63 } else {
jjg@1724 64 exception = input.element.containingClass().findClass(input.tagId);
duke@1 65 }
duke@1 66
jjg@1724 67 ThrowsTag[] tags = ((MethodDoc)input.element).throwsTags();
duke@1 68 for (int i = 0; i < tags.length; i++) {
duke@1 69 if (input.tagId.equals(tags[i].exceptionName()) ||
duke@1 70 (tags[i].exception() != null &&
duke@1 71 (input.tagId.equals(tags[i].exception().qualifiedName())))) {
jjg@1724 72 output.holder = input.element;
duke@1 73 output.holderTag = tags[i];
duke@1 74 output.inlineTags = input.isFirstSentence ?
duke@1 75 tags[i].firstSentenceTags() : tags[i].inlineTags();
duke@1 76 output.tagList.add(tags[i]);
duke@1 77 } else if (exception != null && tags[i].exception() != null &&
duke@1 78 tags[i].exception().subclassOf(exception)) {
duke@1 79 output.tagList.add(tags[i]);
duke@1 80 }
duke@1 81 }
duke@1 82 }
duke@1 83
duke@1 84 /**
duke@1 85 * Add links for exceptions that are declared but not documented.
duke@1 86 */
jjg@1751 87 private Content linkToUndocumentedDeclaredExceptions(
jjg@74 88 Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
duke@1 89 TagletWriter writer) {
jjg@1751 90 Content result = writer.getOutputInstance();
duke@1 91 //Add links to the exceptions declared but not documented.
duke@1 92 for (int i = 0; i < declaredExceptionTypes.length; i++) {
duke@1 93 if (declaredExceptionTypes[i].asClassDoc() != null &&
duke@1 94 ! alreadyDocumented.contains(
duke@1 95 declaredExceptionTypes[i].asClassDoc().name()) &&
duke@1 96 ! alreadyDocumented.contains(
duke@1 97 declaredExceptionTypes[i].asClassDoc().qualifiedName())) {
duke@1 98 if (alreadyDocumented.size() == 0) {
jjg@1751 99 result.addContent(writer.getThrowsHeader());
duke@1 100 }
jjg@1751 101 result.addContent(writer.throwsTagOutput(declaredExceptionTypes[i]));
duke@1 102 alreadyDocumented.add(declaredExceptionTypes[i].asClassDoc().name());
duke@1 103 }
duke@1 104 }
duke@1 105 return result;
duke@1 106 }
duke@1 107
duke@1 108 /**
duke@1 109 * Inherit throws documentation for exceptions that were declared but not
duke@1 110 * documented.
duke@1 111 */
jjg@1751 112 private Content inheritThrowsDocumentation(Doc holder,
jjg@74 113 Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
duke@1 114 TagletWriter writer) {
jjg@1751 115 Content result = writer.getOutputInstance();
duke@1 116 if (holder instanceof MethodDoc) {
jjg@74 117 Set<Tag> declaredExceptionTags = new LinkedHashSet<Tag>();
duke@1 118 for (int j = 0; j < declaredExceptionTypes.length; j++) {
duke@1 119 DocFinder.Output inheritedDoc =
duke@1 120 DocFinder.search(new DocFinder.Input((MethodDoc) holder, this,
duke@1 121 declaredExceptionTypes[j].typeName()));
duke@1 122 if (inheritedDoc.tagList.size() == 0) {
duke@1 123 inheritedDoc = DocFinder.search(new DocFinder.Input(
duke@1 124 (MethodDoc) holder, this,
duke@1 125 declaredExceptionTypes[j].qualifiedTypeName()));
duke@1 126 }
duke@1 127 declaredExceptionTags.addAll(inheritedDoc.tagList);
duke@1 128 }
jjg@1751 129 result.addContent(throwsTagsOutput(
jjg@74 130 declaredExceptionTags.toArray(new ThrowsTag[] {}),
duke@1 131 writer, alreadyDocumented, false));
duke@1 132 }
duke@1 133 return result;
duke@1 134 }
duke@1 135
duke@1 136 /**
duke@1 137 * {@inheritDoc}
duke@1 138 */
jjg@1751 139 public Content getTagletOutput(Doc holder, TagletWriter writer) {
duke@1 140 ExecutableMemberDoc execHolder = (ExecutableMemberDoc) holder;
duke@1 141 ThrowsTag[] tags = execHolder.throwsTags();
jjg@1751 142 Content result = writer.getOutputInstance();
jjg@74 143 HashSet<String> alreadyDocumented = new HashSet<String>();
duke@1 144 if (tags.length > 0) {
jjg@1751 145 result.addContent(throwsTagsOutput(
duke@1 146 execHolder.throwsTags(), writer, alreadyDocumented, true));
duke@1 147 }
jjg@1751 148 result.addContent(inheritThrowsDocumentation(holder,
duke@1 149 execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
jjg@1751 150 result.addContent(linkToUndocumentedDeclaredExceptions(
duke@1 151 execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
duke@1 152 return result;
duke@1 153 }
duke@1 154
duke@1 155
duke@1 156 /**
duke@1 157 * Given an array of <code>Tag</code>s representing this custom
duke@1 158 * tag, return its string representation.
duke@1 159 * @param throwTags the array of <code>ThrowsTag</code>s to convert.
duke@1 160 * @param writer the TagletWriter that will write this tag.
duke@1 161 * @param alreadyDocumented the set of exceptions that have already
duke@1 162 * been documented.
duke@1 163 * @param allowDups True if we allow duplicate throws tags to be documented.
jjg@1751 164 * @return the Content representation of this <code>Tag</code>.
duke@1 165 */
jjg@1751 166 protected Content throwsTagsOutput(ThrowsTag[] throwTags,
jjg@74 167 TagletWriter writer, Set<String> alreadyDocumented, boolean allowDups) {
jjg@1751 168 Content result = writer.getOutputInstance();
duke@1 169 if (throwTags.length > 0) {
duke@1 170 for (int i = 0; i < throwTags.length; ++i) {
duke@1 171 ThrowsTag tt = throwTags[i];
duke@1 172 ClassDoc cd = tt.exception();
duke@1 173 if ((!allowDups) && (alreadyDocumented.contains(tt.exceptionName()) ||
duke@1 174 (cd != null && alreadyDocumented.contains(cd.qualifiedName())))) {
duke@1 175 continue;
duke@1 176 }
duke@1 177 if (alreadyDocumented.size() == 0) {
jjg@1751 178 result.addContent(writer.getThrowsHeader());
duke@1 179 }
jjg@1751 180 result.addContent(writer.throwsTagOutput(tt));
duke@1 181 alreadyDocumented.add(cd != null ?
duke@1 182 cd.qualifiedName() : tt.exceptionName());
duke@1 183 }
duke@1 184 }
duke@1 185 return result;
duke@1 186 }
duke@1 187 }

mercurial