Mon, 02 May 2011 02:13:02 -0700
6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2003, 2008, 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.util; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.taglets.*; |
duke@1 | 30 | import java.util.*; |
duke@1 | 31 | |
duke@1 | 32 | /** |
duke@1 | 33 | * Search for the requested documentation. Inherit documentation if necessary. |
duke@1 | 34 | * |
duke@1 | 35 | * @author Jamie Ho |
duke@1 | 36 | * @since 1.5 |
duke@1 | 37 | */ |
duke@1 | 38 | public class DocFinder { |
duke@1 | 39 | |
duke@1 | 40 | /** |
duke@1 | 41 | * The class that encapsulates the input. |
duke@1 | 42 | */ |
duke@1 | 43 | public static class Input { |
duke@1 | 44 | /** |
duke@1 | 45 | * The method to search documentation from. |
duke@1 | 46 | */ |
duke@1 | 47 | public MethodDoc method = null; |
duke@1 | 48 | /** |
duke@1 | 49 | * The taglet to search for documentation on behalf of. Null if we want |
duke@1 | 50 | * to search for overall documentation. |
duke@1 | 51 | */ |
duke@1 | 52 | public InheritableTaglet taglet = null; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * The id of the tag to retrieve documentation for. |
duke@1 | 56 | */ |
duke@1 | 57 | public String tagId = null; |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * The tag to retrieve documentation for. This is only used for the |
duke@1 | 61 | * inheritDoc tag. |
duke@1 | 62 | */ |
duke@1 | 63 | public Tag tag = null; |
duke@1 | 64 | |
duke@1 | 65 | /** |
duke@1 | 66 | * True if we only want to search for the first sentence. |
duke@1 | 67 | */ |
duke@1 | 68 | public boolean isFirstSentence = false; |
duke@1 | 69 | |
duke@1 | 70 | /** |
duke@1 | 71 | * True if we are looking for documentation to replace the inheritDocTag. |
duke@1 | 72 | */ |
duke@1 | 73 | public boolean isInheritDocTag = false; |
duke@1 | 74 | |
duke@1 | 75 | /** |
duke@1 | 76 | * Used to distinguish between type variable param tags and regular |
duke@1 | 77 | * param tags. |
duke@1 | 78 | */ |
duke@1 | 79 | public boolean isTypeVariableParamTag = false; |
duke@1 | 80 | |
duke@1 | 81 | public Input() {} |
duke@1 | 82 | |
duke@1 | 83 | public Input(MethodDoc method, InheritableTaglet taglet, Tag tag, |
duke@1 | 84 | boolean isFirstSentence, boolean isInheritDocTag) { |
duke@1 | 85 | this.method = method; |
duke@1 | 86 | this.taglet = taglet; |
duke@1 | 87 | this.tag = tag; |
duke@1 | 88 | this.isFirstSentence = isFirstSentence; |
duke@1 | 89 | this.isInheritDocTag = isInheritDocTag; |
duke@1 | 90 | } |
duke@1 | 91 | |
duke@1 | 92 | public Input(MethodDoc method, InheritableTaglet taglet, String tagId) { |
duke@1 | 93 | this.method = method; |
duke@1 | 94 | this.taglet = taglet; |
duke@1 | 95 | this.tagId = tagId; |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | public Input(MethodDoc method, InheritableTaglet taglet, String tagId, |
duke@1 | 99 | boolean isTypeVariableParamTag) { |
duke@1 | 100 | this.method = method; |
duke@1 | 101 | this.taglet = taglet; |
duke@1 | 102 | this.tagId = tagId; |
duke@1 | 103 | this.isTypeVariableParamTag = isTypeVariableParamTag; |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | public Input(MethodDoc method, InheritableTaglet taglet) { |
duke@1 | 107 | this.method = method; |
duke@1 | 108 | this.taglet = taglet; |
duke@1 | 109 | } |
duke@1 | 110 | |
duke@1 | 111 | public Input(MethodDoc method) { |
duke@1 | 112 | this.method = method; |
duke@1 | 113 | } |
duke@1 | 114 | |
duke@1 | 115 | public Input(MethodDoc method, boolean isFirstSentence) { |
duke@1 | 116 | this.method = method; |
duke@1 | 117 | this.isFirstSentence = isFirstSentence; |
duke@1 | 118 | } |
duke@1 | 119 | |
duke@1 | 120 | public Input copy() { |
duke@1 | 121 | Input clone = new Input(); |
duke@1 | 122 | clone.method = this.method; |
duke@1 | 123 | clone.taglet = this.taglet; |
duke@1 | 124 | clone.tagId = this.tagId; |
duke@1 | 125 | clone.tag = this.tag; |
duke@1 | 126 | clone.isFirstSentence = this.isFirstSentence; |
duke@1 | 127 | clone.isInheritDocTag = this.isInheritDocTag; |
duke@1 | 128 | clone.isTypeVariableParamTag = this.isTypeVariableParamTag; |
duke@1 | 129 | return clone; |
duke@1 | 130 | |
duke@1 | 131 | } |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /** |
duke@1 | 135 | * The class that encapsulates the output. |
duke@1 | 136 | */ |
duke@1 | 137 | public static class Output { |
duke@1 | 138 | /** |
duke@1 | 139 | * The tag that holds the documentation. Null if documentation |
duke@1 | 140 | * is not held by a tag. |
duke@1 | 141 | */ |
duke@1 | 142 | public Tag holderTag; |
duke@1 | 143 | |
duke@1 | 144 | /** |
duke@1 | 145 | * The Doc object that holds the documentation. |
duke@1 | 146 | */ |
duke@1 | 147 | public Doc holder; |
duke@1 | 148 | |
duke@1 | 149 | /** |
duke@1 | 150 | * The inherited documentation. |
duke@1 | 151 | */ |
duke@1 | 152 | public Tag[] inlineTags = new Tag[] {}; |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * False if documentation could not be inherited. |
duke@1 | 156 | */ |
duke@1 | 157 | public boolean isValidInheritDocTag = true; |
duke@1 | 158 | |
duke@1 | 159 | /** |
duke@1 | 160 | * When automatically inheriting throws tags, you sometime must inherit |
duke@1 | 161 | * more than one tag. For example if the method declares that it throws |
duke@1 | 162 | * IOException and the overidden method has throws tags for IOException and |
duke@1 | 163 | * ZipException, both tags would be inherited because ZipException is a |
duke@1 | 164 | * subclass of IOException. This subclass of DocFinder.Output allows |
duke@1 | 165 | * multiple tag inheritence. |
duke@1 | 166 | */ |
jjg@74 | 167 | public List<Tag> tagList = new ArrayList<Tag>(); |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | /** |
duke@1 | 171 | * Search for the requested comments in the given method. If it does not |
duke@1 | 172 | * have comments, return documentation from the overriden method if possible. |
duke@1 | 173 | * If the overriden method does not exist or does not have documentation to |
duke@1 | 174 | * inherit, search for documentation to inherit from implemented methods. |
duke@1 | 175 | * |
duke@1 | 176 | * @param input the input object used to perform the search. |
duke@1 | 177 | * |
duke@1 | 178 | * @return an Output object representing the documentation that was found. |
duke@1 | 179 | */ |
duke@1 | 180 | public static Output search(Input input) { |
duke@1 | 181 | Output output = new Output(); |
duke@1 | 182 | if (input.isInheritDocTag) { |
duke@1 | 183 | //Do nothing because "method" does not have any documentation. |
duke@1 | 184 | //All it has it {@inheritDoc}. |
duke@1 | 185 | } else if (input.taglet == null) { |
duke@1 | 186 | //We want overall documentation. |
duke@1 | 187 | output.inlineTags = input.isFirstSentence ? |
duke@1 | 188 | input.method.firstSentenceTags() : |
duke@1 | 189 | input.method.inlineTags(); |
duke@1 | 190 | output.holder = input.method; |
duke@1 | 191 | } else { |
duke@1 | 192 | input.taglet.inherit(input, output); |
duke@1 | 193 | } |
duke@1 | 194 | |
duke@1 | 195 | if (output.inlineTags != null && output.inlineTags.length > 0) { |
duke@1 | 196 | return output; |
duke@1 | 197 | } |
duke@1 | 198 | output.isValidInheritDocTag = false; |
duke@1 | 199 | Input inheritedSearchInput = input.copy(); |
duke@1 | 200 | inheritedSearchInput.isInheritDocTag = false; |
duke@1 | 201 | if (input.method.overriddenMethod() != null) { |
duke@1 | 202 | inheritedSearchInput.method = input.method.overriddenMethod(); |
duke@1 | 203 | output = search(inheritedSearchInput); |
duke@1 | 204 | output.isValidInheritDocTag = true; |
duke@1 | 205 | if (output != null && output.inlineTags.length > 0) { |
duke@1 | 206 | return output; |
duke@1 | 207 | } |
duke@1 | 208 | } |
duke@1 | 209 | //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does |
duke@1 | 210 | // not pass all implemented interfaces, we will use the |
duke@1 | 211 | // appropriate method here. |
duke@1 | 212 | MethodDoc[] implementedMethods = |
duke@1 | 213 | (new ImplementedMethods(input.method, null)).build(false); |
duke@1 | 214 | for (int i = 0; i < implementedMethods.length; i++) { |
duke@1 | 215 | inheritedSearchInput.method = implementedMethods[i]; |
duke@1 | 216 | output = search(inheritedSearchInput); |
duke@1 | 217 | output.isValidInheritDocTag = true; |
duke@1 | 218 | if (output != null && output.inlineTags.length > 0) { |
duke@1 | 219 | return output; |
duke@1 | 220 | } |
duke@1 | 221 | } |
duke@1 | 222 | return output; |
duke@1 | 223 | } |
duke@1 | 224 | } |