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