Tue, 09 Oct 2012 19:10:00 -0700
8000663: clean up langtools imports
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit.util;
28 import java.util.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.taglets.*;
33 /**
34 * Search for the requested documentation. Inherit documentation if necessary.
35 *
36 * @author Jamie Ho
37 * @since 1.5
38 */
39 public class DocFinder {
41 /**
42 * The class that encapsulates the input.
43 */
44 public static class Input {
45 /**
46 * The method to search documentation from.
47 */
48 public MethodDoc method = null;
49 /**
50 * The taglet to search for documentation on behalf of. Null if we want
51 * to search for overall documentation.
52 */
53 public InheritableTaglet taglet = null;
55 /**
56 * The id of the tag to retrieve documentation for.
57 */
58 public String tagId = null;
60 /**
61 * The tag to retrieve documentation for. This is only used for the
62 * inheritDoc tag.
63 */
64 public Tag tag = null;
66 /**
67 * True if we only want to search for the first sentence.
68 */
69 public boolean isFirstSentence = false;
71 /**
72 * True if we are looking for documentation to replace the inheritDocTag.
73 */
74 public boolean isInheritDocTag = false;
76 /**
77 * Used to distinguish between type variable param tags and regular
78 * param tags.
79 */
80 public boolean isTypeVariableParamTag = false;
82 public Input() {}
84 public Input(MethodDoc method, InheritableTaglet taglet, Tag tag,
85 boolean isFirstSentence, boolean isInheritDocTag) {
86 this.method = method;
87 this.taglet = taglet;
88 this.tag = tag;
89 this.isFirstSentence = isFirstSentence;
90 this.isInheritDocTag = isInheritDocTag;
91 }
93 public Input(MethodDoc method, InheritableTaglet taglet, String tagId) {
94 this.method = method;
95 this.taglet = taglet;
96 this.tagId = tagId;
97 }
99 public Input(MethodDoc method, InheritableTaglet taglet, String tagId,
100 boolean isTypeVariableParamTag) {
101 this.method = method;
102 this.taglet = taglet;
103 this.tagId = tagId;
104 this.isTypeVariableParamTag = isTypeVariableParamTag;
105 }
107 public Input(MethodDoc method, InheritableTaglet taglet) {
108 this.method = method;
109 this.taglet = taglet;
110 }
112 public Input(MethodDoc method) {
113 this.method = method;
114 }
116 public Input(MethodDoc method, boolean isFirstSentence) {
117 this.method = method;
118 this.isFirstSentence = isFirstSentence;
119 }
121 public Input copy() {
122 Input clone = new Input();
123 clone.method = this.method;
124 clone.taglet = this.taglet;
125 clone.tagId = this.tagId;
126 clone.tag = this.tag;
127 clone.isFirstSentence = this.isFirstSentence;
128 clone.isInheritDocTag = this.isInheritDocTag;
129 clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
130 return clone;
132 }
133 }
135 /**
136 * The class that encapsulates the output.
137 */
138 public static class Output {
139 /**
140 * The tag that holds the documentation. Null if documentation
141 * is not held by a tag.
142 */
143 public Tag holderTag;
145 /**
146 * The Doc object that holds the documentation.
147 */
148 public Doc holder;
150 /**
151 * The inherited documentation.
152 */
153 public Tag[] inlineTags = new Tag[] {};
155 /**
156 * False if documentation could not be inherited.
157 */
158 public boolean isValidInheritDocTag = true;
160 /**
161 * When automatically inheriting throws tags, you sometime must inherit
162 * more than one tag. For example if the method declares that it throws
163 * IOException and the overidden method has throws tags for IOException and
164 * ZipException, both tags would be inherited because ZipException is a
165 * subclass of IOException. This subclass of DocFinder.Output allows
166 * multiple tag inheritence.
167 */
168 public List<Tag> tagList = new ArrayList<Tag>();
169 }
171 /**
172 * Search for the requested comments in the given method. If it does not
173 * have comments, return documentation from the overriden method if possible.
174 * If the overriden method does not exist or does not have documentation to
175 * inherit, search for documentation to inherit from implemented methods.
176 *
177 * @param input the input object used to perform the search.
178 *
179 * @return an Output object representing the documentation that was found.
180 */
181 public static Output search(Input input) {
182 Output output = new Output();
183 if (input.isInheritDocTag) {
184 //Do nothing because "method" does not have any documentation.
185 //All it has it {@inheritDoc}.
186 } else if (input.taglet == null) {
187 //We want overall documentation.
188 output.inlineTags = input.isFirstSentence ?
189 input.method.firstSentenceTags() :
190 input.method.inlineTags();
191 output.holder = input.method;
192 } else {
193 input.taglet.inherit(input, output);
194 }
196 if (output.inlineTags != null && output.inlineTags.length > 0) {
197 return output;
198 }
199 output.isValidInheritDocTag = false;
200 Input inheritedSearchInput = input.copy();
201 inheritedSearchInput.isInheritDocTag = false;
202 if (input.method.overriddenMethod() != null) {
203 inheritedSearchInput.method = input.method.overriddenMethod();
204 output = search(inheritedSearchInput);
205 output.isValidInheritDocTag = true;
206 if (output != null && output.inlineTags.length > 0) {
207 return output;
208 }
209 }
210 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
211 // not pass all implemented interfaces, we will use the
212 // appropriate method here.
213 MethodDoc[] implementedMethods =
214 (new ImplementedMethods(input.method, null)).build(false);
215 for (int i = 0; i < implementedMethods.length; i++) {
216 inheritedSearchInput.method = implementedMethods[i];
217 output = search(inheritedSearchInput);
218 output.isValidInheritDocTag = true;
219 if (output != null && output.inlineTags.length > 0) {
220 return output;
221 }
222 }
223 return output;
224 }
225 }