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