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