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