src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFinder.java

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1724
d918b63a5509
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

duke@1 1 /*
jjg@1357 2 * Copyright (c) 2003, 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.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 /**
duke@1 51 * The method to search documentation from.
duke@1 52 */
duke@1 53 public MethodDoc method = null;
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
duke@1 87 public Input() {}
duke@1 88
duke@1 89 public Input(MethodDoc method, InheritableTaglet taglet, Tag tag,
duke@1 90 boolean isFirstSentence, boolean isInheritDocTag) {
duke@1 91 this.method = method;
duke@1 92 this.taglet = taglet;
duke@1 93 this.tag = tag;
duke@1 94 this.isFirstSentence = isFirstSentence;
duke@1 95 this.isInheritDocTag = isInheritDocTag;
duke@1 96 }
duke@1 97
duke@1 98 public Input(MethodDoc method, InheritableTaglet taglet, String tagId) {
duke@1 99 this.method = method;
duke@1 100 this.taglet = taglet;
duke@1 101 this.tagId = tagId;
duke@1 102 }
duke@1 103
duke@1 104 public Input(MethodDoc method, InheritableTaglet taglet, String tagId,
duke@1 105 boolean isTypeVariableParamTag) {
duke@1 106 this.method = method;
duke@1 107 this.taglet = taglet;
duke@1 108 this.tagId = tagId;
duke@1 109 this.isTypeVariableParamTag = isTypeVariableParamTag;
duke@1 110 }
duke@1 111
duke@1 112 public Input(MethodDoc method, InheritableTaglet taglet) {
duke@1 113 this.method = method;
duke@1 114 this.taglet = taglet;
duke@1 115 }
duke@1 116
duke@1 117 public Input(MethodDoc method) {
duke@1 118 this.method = method;
duke@1 119 }
duke@1 120
duke@1 121 public Input(MethodDoc method, boolean isFirstSentence) {
duke@1 122 this.method = method;
duke@1 123 this.isFirstSentence = isFirstSentence;
duke@1 124 }
duke@1 125
duke@1 126 public Input copy() {
duke@1 127 Input clone = new Input();
duke@1 128 clone.method = this.method;
duke@1 129 clone.taglet = this.taglet;
duke@1 130 clone.tagId = this.tagId;
duke@1 131 clone.tag = this.tag;
duke@1 132 clone.isFirstSentence = this.isFirstSentence;
duke@1 133 clone.isInheritDocTag = this.isInheritDocTag;
duke@1 134 clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
duke@1 135 return clone;
duke@1 136
duke@1 137 }
duke@1 138 }
duke@1 139
duke@1 140 /**
duke@1 141 * The class that encapsulates the output.
duke@1 142 */
duke@1 143 public static class Output {
duke@1 144 /**
duke@1 145 * The tag that holds the documentation. Null if documentation
duke@1 146 * is not held by a tag.
duke@1 147 */
duke@1 148 public Tag holderTag;
duke@1 149
duke@1 150 /**
duke@1 151 * The Doc object that holds the documentation.
duke@1 152 */
duke@1 153 public Doc holder;
duke@1 154
duke@1 155 /**
duke@1 156 * The inherited documentation.
duke@1 157 */
duke@1 158 public Tag[] inlineTags = new Tag[] {};
duke@1 159
duke@1 160 /**
duke@1 161 * False if documentation could not be inherited.
duke@1 162 */
duke@1 163 public boolean isValidInheritDocTag = true;
duke@1 164
duke@1 165 /**
duke@1 166 * When automatically inheriting throws tags, you sometime must inherit
duke@1 167 * more than one tag. For example if the method declares that it throws
duke@1 168 * IOException and the overidden method has throws tags for IOException and
duke@1 169 * ZipException, both tags would be inherited because ZipException is a
duke@1 170 * subclass of IOException. This subclass of DocFinder.Output allows
duke@1 171 * multiple tag inheritence.
duke@1 172 */
jjg@74 173 public List<Tag> tagList = new ArrayList<Tag>();
duke@1 174 }
duke@1 175
duke@1 176 /**
duke@1 177 * Search for the requested comments in the given method. If it does not
duke@1 178 * have comments, return documentation from the overriden method if possible.
duke@1 179 * If the overriden method does not exist or does not have documentation to
duke@1 180 * inherit, search for documentation to inherit from implemented methods.
duke@1 181 *
duke@1 182 * @param input the input object used to perform the search.
duke@1 183 *
duke@1 184 * @return an Output object representing the documentation that was found.
duke@1 185 */
duke@1 186 public static Output search(Input input) {
duke@1 187 Output output = new Output();
duke@1 188 if (input.isInheritDocTag) {
duke@1 189 //Do nothing because "method" does not have any documentation.
duke@1 190 //All it has it {@inheritDoc}.
duke@1 191 } else if (input.taglet == null) {
duke@1 192 //We want overall documentation.
duke@1 193 output.inlineTags = input.isFirstSentence ?
duke@1 194 input.method.firstSentenceTags() :
duke@1 195 input.method.inlineTags();
duke@1 196 output.holder = input.method;
duke@1 197 } else {
duke@1 198 input.taglet.inherit(input, output);
duke@1 199 }
duke@1 200
duke@1 201 if (output.inlineTags != null && output.inlineTags.length > 0) {
duke@1 202 return output;
duke@1 203 }
duke@1 204 output.isValidInheritDocTag = false;
duke@1 205 Input inheritedSearchInput = input.copy();
duke@1 206 inheritedSearchInput.isInheritDocTag = false;
duke@1 207 if (input.method.overriddenMethod() != null) {
duke@1 208 inheritedSearchInput.method = input.method.overriddenMethod();
duke@1 209 output = search(inheritedSearchInput);
duke@1 210 output.isValidInheritDocTag = true;
duke@1 211 if (output != null && output.inlineTags.length > 0) {
duke@1 212 return output;
duke@1 213 }
duke@1 214 }
duke@1 215 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
duke@1 216 // not pass all implemented interfaces, we will use the
duke@1 217 // appropriate method here.
duke@1 218 MethodDoc[] implementedMethods =
duke@1 219 (new ImplementedMethods(input.method, null)).build(false);
duke@1 220 for (int i = 0; i < implementedMethods.length; i++) {
duke@1 221 inheritedSearchInput.method = implementedMethods[i];
duke@1 222 output = search(inheritedSearchInput);
duke@1 223 output.isValidInheritDocTag = true;
duke@1 224 if (output != null && output.inlineTags.length > 0) {
duke@1 225 return output;
duke@1 226 }
duke@1 227 }
duke@1 228 return output;
duke@1 229 }
duke@1 230 }

mercurial