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