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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 554
9d9f26857129
child 1359
25e14ad23cef
permissions
-rw-r--r--

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

mercurial