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

Tue, 14 May 2013 10:14:54 -0700

author
jjg
date
Tue, 14 May 2013 10:14:54 -0700
changeset 1743
6a5288a298fd
parent 1724
d918b63a5509
child 1751
ca8808c88f94
permissions
-rw-r--r--

8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy

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

mercurial