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