author | jjg |
Thu, 15 Nov 2012 09:18:36 -0800 | |
changeset 14542 | 7062120649c2 |
parent 14447 | 6f87132c2e54 |
child 15385 | ee1eebe7e210 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14260 | 2 |
* Copyright (c) 1999, 2012, 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 |
||
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
28 |
import java.io.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
29 |
import java.util.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
30 |
|
10 | 31 |
import com.sun.javadoc.*; |
32 |
import com.sun.tools.doclets.internal.toolkit.*; |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
33 |
import javax.tools.StandardLocation; |
10 | 34 |
|
35 |
/** |
|
36 |
* Utilities Class for Doclets. |
|
37 |
* |
|
14260 | 38 |
* <p><b>This is NOT part of any supported API. |
39 |
* If you write code that depends on this, you do so at your own risk. |
|
40 |
* This code and its internal interfaces are subject to change or |
|
41 |
* deletion without notice.</b> |
|
10 | 42 |
* |
43 |
* @author Atul M Dambalkar |
|
44 |
* @author Jamie Ho |
|
45 |
*/ |
|
46 |
public class Util { |
|
47 |
||
48 |
/** |
|
49 |
* Return array of class members whose documentation is to be generated. |
|
50 |
* If the member is deprecated do not include such a member in the |
|
51 |
* returned array. |
|
52 |
* |
|
53 |
* @param members Array of members to choose from. |
|
54 |
* @return ProgramElementDoc[] Array of eligible members for whom |
|
55 |
* documentation is getting generated. |
|
56 |
*/ |
|
57 |
public static ProgramElementDoc[] excludeDeprecatedMembers( |
|
58 |
ProgramElementDoc[] members) { |
|
59 |
return |
|
60 |
toProgramElementDocArray(excludeDeprecatedMembersAsList(members)); |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* Return array of class members whose documentation is to be generated. |
|
65 |
* If the member is deprecated do not include such a member in the |
|
66 |
* returned array. |
|
67 |
* |
|
68 |
* @param members Array of members to choose from. |
|
69 |
* @return List List of eligible members for whom |
|
70 |
* documentation is getting generated. |
|
71 |
*/ |
|
868 | 72 |
public static List<ProgramElementDoc> excludeDeprecatedMembersAsList( |
10 | 73 |
ProgramElementDoc[] members) { |
868 | 74 |
List<ProgramElementDoc> list = new ArrayList<ProgramElementDoc>(); |
10 | 75 |
for (int i = 0; i < members.length; i++) { |
76 |
if (members[i].tags("deprecated").length == 0) { |
|
77 |
list.add(members[i]); |
|
78 |
} |
|
79 |
} |
|
80 |
Collections.sort(list); |
|
81 |
return list; |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Return the list of ProgramElementDoc objects as Array. |
|
86 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
87 |
public static ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) { |
10 | 88 |
ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()]; |
89 |
for (int i = 0; i < list.size(); i++) { |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
90 |
pgmarr[i] = list.get(i); |
10 | 91 |
} |
92 |
return pgmarr; |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Return true if a non-public member found in the given array. |
|
97 |
* |
|
98 |
* @param members Array of members to look into. |
|
99 |
* @return boolean True if non-public member found, false otherwise. |
|
100 |
*/ |
|
101 |
public static boolean nonPublicMemberFound(ProgramElementDoc[] members) { |
|
102 |
for (int i = 0; i < members.length; i++) { |
|
103 |
if (!members[i].isPublic()) { |
|
104 |
return true; |
|
105 |
} |
|
106 |
} |
|
107 |
return false; |
|
108 |
} |
|
109 |
||
110 |
/** |
|
111 |
* Search for the given method in the given class. |
|
112 |
* |
|
113 |
* @param cd Class to search into. |
|
114 |
* @param method Method to be searched. |
|
115 |
* @return MethodDoc Method found, null otherwise. |
|
116 |
*/ |
|
117 |
public static MethodDoc findMethod(ClassDoc cd, MethodDoc method) { |
|
118 |
MethodDoc[] methods = cd.methods(); |
|
119 |
for (int i = 0; i < methods.length; i++) { |
|
120 |
if (executableMembersEqual(method, methods[i])) { |
|
121 |
return methods[i]; |
|
122 |
||
123 |
} |
|
124 |
} |
|
125 |
return null; |
|
126 |
} |
|
127 |
||
128 |
/** |
|
129 |
* @param member1 the first method to compare. |
|
130 |
* @param member2 the second method to compare. |
|
131 |
* @return true if member1 overrides/hides or is overriden/hidden by member2. |
|
132 |
*/ |
|
133 |
public static boolean executableMembersEqual(ExecutableMemberDoc member1, |
|
134 |
ExecutableMemberDoc member2) { |
|
135 |
if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc)) |
|
136 |
return false; |
|
137 |
||
138 |
MethodDoc method1 = (MethodDoc) member1; |
|
139 |
MethodDoc method2 = (MethodDoc) member2; |
|
140 |
if (method1.isStatic() && method2.isStatic()) { |
|
141 |
Parameter[] targetParams = method1.parameters(); |
|
142 |
Parameter[] currentParams; |
|
143 |
if (method1.name().equals(method2.name()) && |
|
144 |
(currentParams = method2.parameters()).length == |
|
145 |
targetParams.length) { |
|
146 |
int j; |
|
147 |
for (j = 0; j < targetParams.length; j++) { |
|
148 |
if (! (targetParams[j].typeName().equals( |
|
149 |
currentParams[j].typeName()) || |
|
150 |
currentParams[j].type() instanceof TypeVariable || |
|
151 |
targetParams[j].type() instanceof TypeVariable)) { |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
155 |
if (j == targetParams.length) { |
|
156 |
return true; |
|
157 |
} |
|
158 |
} |
|
159 |
return false; |
|
160 |
} else { |
|
161 |
return method1.overrides(method2) || |
|
162 |
method2.overrides(method1) || |
|
163 |
member1 == member2; |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
/** |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
168 |
* According to |
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
169 |
* <cite>The Java™ Language Specification</cite>, |
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
170 |
* all the outer classes and static inner classes are core classes. |
10 | 171 |
*/ |
172 |
public static boolean isCoreClass(ClassDoc cd) { |
|
173 |
return cd.containingClass() == null || cd.isStatic(); |
|
174 |
} |
|
175 |
||
176 |
public static boolean matches(ProgramElementDoc doc1, |
|
177 |
ProgramElementDoc doc2) { |
|
178 |
if (doc1 instanceof ExecutableMemberDoc && |
|
179 |
doc2 instanceof ExecutableMemberDoc) { |
|
180 |
ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1; |
|
181 |
ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2; |
|
182 |
return executableMembersEqual(ed1, ed2); |
|
183 |
} else { |
|
184 |
return doc1.name().equals(doc2.name()); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* Copy the given directory contents from the source package directory |
|
190 |
* to the generated documentation directory. For example for a package |
|
191 |
* java.lang this method find out the source location of the package using |
|
192 |
* {@link SourcePath} and if given directory is found in the source |
|
193 |
* directory structure, copy the entire directory, to the generated |
|
194 |
* documentation hierarchy. |
|
195 |
* |
|
196 |
* @param configuration The configuration of the current doclet. |
|
197 |
* @param path The relative path to the directory to be copied. |
|
198 |
* @param dir The original directory name to copy from. |
|
199 |
* @param overwrite Overwrite files if true. |
|
200 |
*/ |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
201 |
public static void copyDocFiles(Configuration configuration, PackageDoc pd) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
202 |
copyDocFiles(configuration, DocPath.forPackage(pd).resolve(DocPaths.DOC_FILES)); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
203 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
204 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
205 |
public static void copyDocFiles(Configuration configuration, DocPath dir) { |
10 | 206 |
try { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
207 |
boolean first = true; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
208 |
for (DocFile f : DocFile.list(configuration, StandardLocation.SOURCE_PATH, dir)) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
209 |
if (!f.isDirectory()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
210 |
continue; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
211 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
212 |
DocFile srcdir = f; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
213 |
DocFile destdir = DocFile.createFileForOutput(configuration, dir); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
214 |
if (srcdir.isSameFile(destdir)) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
215 |
continue; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
216 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
217 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
218 |
for (DocFile srcfile: srcdir.list()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
219 |
DocFile destfile = destdir.resolve(srcfile.getName()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
220 |
if (srcfile.isFile()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
221 |
if (destfile.exists() && !first) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
222 |
configuration.message.warning((SourcePosition) null, |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
223 |
"doclet.Copy_Overwrite_warning", |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
224 |
srcfile.getPath(), destdir.getPath()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
225 |
} else { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
226 |
configuration.message.notice( |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
227 |
"doclet.Copying_File_0_To_Dir_1", |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
228 |
srcfile.getPath(), destdir.getPath()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
229 |
destfile.copyFile(srcfile); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
230 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
231 |
} else if (srcfile.isDirectory()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
232 |
if (configuration.copydocfilesubdirs |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
233 |
&& !configuration.shouldExcludeDocFileDir(srcfile.getName())) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
234 |
copyDocFiles(configuration, dir.resolve(srcfile.getName())); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
235 |
} |
10 | 236 |
} |
237 |
} |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
238 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
239 |
first = false; |
10 | 240 |
} |
241 |
} catch (SecurityException exc) { |
|
242 |
throw new DocletAbortException(); |
|
243 |
} catch (IOException exc) { |
|
244 |
throw new DocletAbortException(); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
/** |
|
249 |
* We want the list of types in alphabetical order. However, types are not |
|
250 |
* comparable. We need a comparator for now. |
|
251 |
*/ |
|
868 | 252 |
private static class TypeComparator implements Comparator<Type> { |
253 |
public int compare(Type type1, Type type2) { |
|
254 |
return type1.qualifiedTypeName().toLowerCase().compareTo( |
|
255 |
type2.qualifiedTypeName().toLowerCase()); |
|
10 | 256 |
} |
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* For the class return all implemented interfaces including the |
|
261 |
* superinterfaces of the implementing interfaces, also iterate over for |
|
262 |
* all the superclasses. For interface return all the extended interfaces |
|
263 |
* as well as superinterfaces for those extended interfaces. |
|
264 |
* |
|
265 |
* @param type type whose implemented or |
|
266 |
* super interfaces are sought. |
|
267 |
* @param configuration the current configuration of the doclet. |
|
268 |
* @param sort if true, return list of interfaces sorted alphabetically. |
|
269 |
* @return List of all the required interfaces. |
|
270 |
*/ |
|
868 | 271 |
public static List<Type> getAllInterfaces(Type type, |
10 | 272 |
Configuration configuration, boolean sort) { |
868 | 273 |
Map<ClassDoc,Type> results = sort ? new TreeMap<ClassDoc,Type>() : new LinkedHashMap<ClassDoc,Type>(); |
10 | 274 |
Type[] interfaceTypes = null; |
275 |
Type superType = null; |
|
276 |
if (type instanceof ParameterizedType) { |
|
277 |
interfaceTypes = ((ParameterizedType) type).interfaceTypes(); |
|
278 |
superType = ((ParameterizedType) type).superclassType(); |
|
279 |
} else if (type instanceof ClassDoc) { |
|
280 |
interfaceTypes = ((ClassDoc) type).interfaceTypes(); |
|
281 |
superType = ((ClassDoc) type).superclassType(); |
|
282 |
} else { |
|
283 |
interfaceTypes = type.asClassDoc().interfaceTypes(); |
|
284 |
superType = type.asClassDoc().superclassType(); |
|
285 |
} |
|
286 |
||
287 |
for (int i = 0; i < interfaceTypes.length; i++) { |
|
288 |
Type interfaceType = interfaceTypes[i]; |
|
289 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
|
290 |
if (! (interfaceClassDoc.isPublic() || |
|
291 |
(configuration == null || |
|
292 |
isLinkable(interfaceClassDoc, configuration)))) { |
|
293 |
continue; |
|
294 |
} |
|
295 |
results.put(interfaceClassDoc, interfaceType); |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
296 |
List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration, sort); |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
297 |
for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
298 |
Type t = iter.next(); |
10 | 299 |
results.put(t.asClassDoc(), t); |
300 |
} |
|
301 |
} |
|
302 |
if (superType == null) |
|
868 | 303 |
return new ArrayList<Type>(results.values()); |
10 | 304 |
//Try walking the tree. |
305 |
addAllInterfaceTypes(results, |
|
306 |
superType, |
|
307 |
superType instanceof ClassDoc ? |
|
308 |
((ClassDoc) superType).interfaceTypes() : |
|
309 |
((ParameterizedType) superType).interfaceTypes(), |
|
310 |
false, configuration); |
|
868 | 311 |
List<Type> resultsList = new ArrayList<Type>(results.values()); |
10 | 312 |
if (sort) { |
313 |
Collections.sort(resultsList, new TypeComparator()); |
|
314 |
} |
|
315 |
return resultsList; |
|
316 |
} |
|
317 |
||
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
318 |
public static List<Type> getAllInterfaces(Type type, Configuration configuration) { |
10 | 319 |
return getAllInterfaces(type, configuration, true); |
320 |
} |
|
321 |
||
868 | 322 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw, |
10 | 323 |
Configuration configuration) { |
324 |
Type superType = c.superclassType(); |
|
325 |
if (superType == null) |
|
326 |
return; |
|
327 |
addAllInterfaceTypes(results, superType, |
|
328 |
superType instanceof ClassDoc ? |
|
329 |
((ClassDoc) superType).interfaceTypes() : |
|
330 |
((ParameterizedType) superType).interfaceTypes(), |
|
331 |
raw, configuration); |
|
332 |
} |
|
333 |
||
868 | 334 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p, |
10 | 335 |
Configuration configuration) { |
336 |
Type superType = p.superclassType(); |
|
337 |
if (superType == null) |
|
338 |
return; |
|
339 |
addAllInterfaceTypes(results, superType, |
|
340 |
superType instanceof ClassDoc ? |
|
341 |
((ClassDoc) superType).interfaceTypes() : |
|
342 |
((ParameterizedType) superType).interfaceTypes(), |
|
343 |
false, configuration); |
|
344 |
} |
|
345 |
||
868 | 346 |
private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type, |
10 | 347 |
Type[] interfaceTypes, boolean raw, |
348 |
Configuration configuration) { |
|
349 |
for (int i = 0; i < interfaceTypes.length; i++) { |
|
350 |
Type interfaceType = interfaceTypes[i]; |
|
351 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
|
352 |
if (! (interfaceClassDoc.isPublic() || |
|
353 |
(configuration != null && |
|
354 |
isLinkable(interfaceClassDoc, configuration)))) { |
|
355 |
continue; |
|
356 |
} |
|
357 |
if (raw) |
|
358 |
interfaceType = interfaceType.asClassDoc(); |
|
359 |
results.put(interfaceClassDoc, interfaceType); |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
360 |
List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration); |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
361 |
for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
362 |
Type superInterface = iter.next(); |
10 | 363 |
results.put(superInterface.asClassDoc(), superInterface); |
364 |
} |
|
365 |
} |
|
366 |
if (type instanceof ParameterizedType) |
|
367 |
findAllInterfaceTypes(results, (ParameterizedType) type, configuration); |
|
368 |
else if (((ClassDoc) type).typeParameters().length == 0) |
|
369 |
findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration); |
|
370 |
else |
|
371 |
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); |
|
372 |
} |
|
373 |
||
374 |
/** |
|
375 |
* Enclose in quotes, used for paths and filenames that contains spaces |
|
376 |
*/ |
|
377 |
public static String quote(String filepath) { |
|
378 |
return ("\"" + filepath + "\""); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
382 |
* Given a package, return its name. |
10 | 383 |
* @param packageDoc the package to check. |
384 |
* @return the name of the given package. |
|
385 |
*/ |
|
386 |
public static String getPackageName(PackageDoc packageDoc) { |
|
387 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
388 |
DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name(); |
|
389 |
} |
|
390 |
||
391 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
392 |
* Given a package, return its file name without the extension. |
10 | 393 |
* @param packageDoc the package to check. |
394 |
* @return the file name of the given package. |
|
395 |
*/ |
|
396 |
public static String getPackageFileHeadName(PackageDoc packageDoc) { |
|
397 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
398 |
DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name(); |
|
399 |
} |
|
400 |
||
401 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
402 |
* Given a string, replace all occurrences of 'newStr' with 'oldStr'. |
10 | 403 |
* @param originalStr the string to modify. |
404 |
* @param oldStr the string to replace. |
|
405 |
* @param newStr the string to insert in place of the old string. |
|
406 |
*/ |
|
407 |
public static String replaceText(String originalStr, String oldStr, |
|
408 |
String newStr) { |
|
409 |
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { |
|
410 |
return originalStr; |
|
411 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
412 |
return originalStr.replace(oldStr, newStr); |
10 | 413 |
} |
414 |
||
415 |
/** |
|
416 |
* Given a string, escape all special html characters and |
|
417 |
* return the result. |
|
418 |
* |
|
419 |
* @param s The string to check. |
|
14542 | 420 |
* @return the original string with all of the HTML characters escaped. |
10 | 421 |
*/ |
422 |
public static String escapeHtmlChars(String s) { |
|
14542 | 423 |
for (int i = 0; i < s.length(); i++) { |
424 |
char ch = s.charAt(i); |
|
425 |
switch (ch) { |
|
426 |
// only start building a new string if we need to |
|
427 |
case '<': case '>': case '&': |
|
428 |
StringBuilder sb = new StringBuilder(s.substring(0, i)); |
|
429 |
for ( ; i < s.length(); i++) { |
|
430 |
ch = s.charAt(i); |
|
431 |
switch (ch) { |
|
432 |
case '<': sb.append("<"); break; |
|
433 |
case '>': sb.append(">"); break; |
|
434 |
case '&': sb.append("&"); break; |
|
435 |
default: sb.append(ch); break; |
|
436 |
} |
|
437 |
} |
|
438 |
return sb.toString(); |
|
439 |
} |
|
10 | 440 |
} |
14542 | 441 |
return s; |
442 |
} |
|
443 |
||
444 |
/** |
|
445 |
* Escape all special html characters in a string buffer. |
|
446 |
* |
|
447 |
* @param sb The string buffer to update |
|
448 |
*/ |
|
449 |
public static void escapeHtmlChars(StringBuilder sb) { |
|
450 |
// scan backwards, replacing characters as needed. |
|
451 |
for (int i = sb.length() - 1; i >= 0; i--) { |
|
452 |
switch (sb.charAt(i)) { |
|
453 |
case '<': sb.replace(i, i+1, "<"); break; |
|
454 |
case '>': sb.replace(i, i+1, ">"); break; |
|
455 |
case '&': sb.replace(i, i+1, "&"); break; |
|
456 |
} |
|
457 |
} |
|
10 | 458 |
} |
459 |
||
460 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
461 |
* Given a string, strips all html characters and |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
462 |
* return the result. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
463 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
464 |
* @param rawString The string to check. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
465 |
* @return the original string with all of the HTML characters |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
466 |
* stripped. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
467 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
468 |
*/ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
469 |
public static String stripHtml(String rawString) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
470 |
// remove HTML tags |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
471 |
rawString = rawString.replaceAll("\\<.*?>", " "); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
472 |
// consolidate multiple spaces between a word to a single space |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
473 |
rawString = rawString.replaceAll("\\b\\s{2,}\\b", " "); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
474 |
// remove extra whitespaces |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
475 |
return rawString.trim(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
476 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
477 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
478 |
/** |
10 | 479 |
* Given an annotation, return true if it should be documented and false |
480 |
* otherwise. |
|
481 |
* |
|
482 |
* @param annotationDoc the annotation to check. |
|
483 |
* |
|
484 |
* @return true return true if it should be documented and false otherwise. |
|
485 |
*/ |
|
486 |
public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) { |
|
487 |
AnnotationDesc[] annotationDescList = annotationDoc.annotations(); |
|
488 |
for (int i = 0; i < annotationDescList.length; i++) { |
|
489 |
if (annotationDescList[i].annotationType().qualifiedName().equals( |
|
490 |
java.lang.annotation.Documented.class.getName())){ |
|
491 |
return true; |
|
492 |
} |
|
493 |
} |
|
494 |
return false; |
|
495 |
} |
|
496 |
||
497 |
/** |
|
498 |
* Return true if this class is linkable and false if we can't link to the |
|
499 |
* desired class. |
|
500 |
* <br> |
|
501 |
* <b>NOTE:</b> You can only link to external classes if they are public or |
|
502 |
* protected. |
|
503 |
* |
|
504 |
* @param classDoc the class to check. |
|
505 |
* @param configuration the current configuration of the doclet. |
|
506 |
* |
|
507 |
* @return true if this class is linkable and false if we can't link to the |
|
508 |
* desired class. |
|
509 |
*/ |
|
510 |
public static boolean isLinkable(ClassDoc classDoc, |
|
511 |
Configuration configuration) { |
|
512 |
return |
|
513 |
((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) || |
|
514 |
(configuration.extern.isExternal(classDoc) && |
|
515 |
(classDoc.isPublic() || classDoc.isProtected())); |
|
516 |
} |
|
517 |
||
518 |
/** |
|
519 |
* Given a class, return the closest visible super class. |
|
520 |
* |
|
521 |
* @param classDoc the class we are searching the parent for. |
|
522 |
* @param configuration the current configuration of the doclet. |
|
523 |
* @return the closest visible super class. Return null if it cannot |
|
524 |
* be found (i.e. classDoc is java.lang.Object). |
|
525 |
*/ |
|
526 |
public static Type getFirstVisibleSuperClass(ClassDoc classDoc, |
|
527 |
Configuration configuration) { |
|
528 |
if (classDoc == null) { |
|
529 |
return null; |
|
530 |
} |
|
531 |
Type sup = classDoc.superclassType(); |
|
532 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
533 |
while (sup != null && |
|
534 |
(! (supClassDoc.isPublic() || |
|
535 |
isLinkable(supClassDoc, configuration))) ) { |
|
536 |
if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName())) |
|
537 |
break; |
|
538 |
sup = supClassDoc.superclassType(); |
|
539 |
supClassDoc = supClassDoc.superclass(); |
|
540 |
} |
|
541 |
if (classDoc.equals(supClassDoc)) { |
|
542 |
return null; |
|
543 |
} |
|
544 |
return sup; |
|
545 |
} |
|
546 |
||
547 |
/** |
|
548 |
* Given a class, return the closest visible super class. |
|
549 |
* |
|
550 |
* @param classDoc the class we are searching the parent for. |
|
551 |
* @param configuration the current configuration of the doclet. |
|
552 |
* @return the closest visible super class. Return null if it cannot |
|
553 |
* be found (i.e. classDoc is java.lang.Object). |
|
554 |
*/ |
|
555 |
public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc, |
|
556 |
Configuration configuration) { |
|
557 |
if (classDoc == null) { |
|
558 |
return null; |
|
559 |
} |
|
560 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
561 |
while (supClassDoc != null && |
|
562 |
(! (supClassDoc.isPublic() || |
|
563 |
isLinkable(supClassDoc, configuration))) ) { |
|
564 |
supClassDoc = supClassDoc.superclass(); |
|
565 |
} |
|
566 |
if (classDoc.equals(supClassDoc)) { |
|
567 |
return null; |
|
568 |
} |
|
569 |
return supClassDoc; |
|
570 |
} |
|
571 |
||
572 |
/** |
|
573 |
* Given a ClassDoc, return the name of its type (Class, Interface, etc.). |
|
574 |
* |
|
575 |
* @param cd the ClassDoc to check. |
|
576 |
* @param lowerCaseOnly true if you want the name returned in lower case. |
|
14447
6f87132c2e54
8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents:
14368
diff
changeset
|
577 |
* If false, the first letter of the name is capitalized. |
10 | 578 |
* @return |
579 |
*/ |
|
580 |
public static String getTypeName(Configuration config, |
|
581 |
ClassDoc cd, boolean lowerCaseOnly) { |
|
582 |
String typeName = ""; |
|
583 |
if (cd.isOrdinaryClass()) { |
|
584 |
typeName = "doclet.Class"; |
|
585 |
} else if (cd.isInterface()) { |
|
586 |
typeName = "doclet.Interface"; |
|
587 |
} else if (cd.isException()) { |
|
588 |
typeName = "doclet.Exception"; |
|
589 |
} else if (cd.isError()) { |
|
590 |
typeName = "doclet.Error"; |
|
591 |
} else if (cd.isAnnotationType()) { |
|
592 |
typeName = "doclet.AnnotationType"; |
|
593 |
} else if (cd.isEnum()) { |
|
594 |
typeName = "doclet.Enum"; |
|
595 |
} |
|
596 |
return config.getText( |
|
597 |
lowerCaseOnly ? typeName.toLowerCase() : typeName); |
|
598 |
} |
|
599 |
||
600 |
/** |
|
14542 | 601 |
* Replace all tabs with the appropriate number of spaces. |
602 |
* @param configuration the doclet configuration defining the setting for the |
|
603 |
* tab length. |
|
604 |
* @param sb the StringBuilder in which to replace the tabs |
|
10 | 605 |
*/ |
14542 | 606 |
public static void replaceTabs(Configuration configuration, StringBuilder sb) { |
607 |
int tabLength = configuration.sourcetab; |
|
608 |
String whitespace = configuration.tabSpaces; |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
609 |
int index = 0; |
14542 | 610 |
while ((index = sb.indexOf("\t", index)) != -1) { |
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
611 |
int spaceCount = tabLength - index % tabLength; |
14542 | 612 |
sb.replace(index, index+1, whitespace.substring(0, spaceCount)); |
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
613 |
index += spaceCount; |
10 | 614 |
} |
615 |
} |
|
616 |
||
617 |
/** |
|
618 |
* The documentation for values() and valueOf() in Enums are set by the |
|
619 |
* doclet. |
|
620 |
*/ |
|
621 |
public static void setEnumDocumentation(Configuration configuration, |
|
622 |
ClassDoc classDoc) { |
|
623 |
MethodDoc[] methods = classDoc.methods(); |
|
624 |
for (int j = 0; j < methods.length; j++) { |
|
625 |
MethodDoc currentMethod = methods[j]; |
|
626 |
if (currentMethod.name().equals("values") && |
|
627 |
currentMethod.parameters().length == 0) { |
|
628 |
currentMethod.setRawCommentText( |
|
629 |
configuration.getText("doclet.enum_values_doc", classDoc.name())); |
|
630 |
} else if (currentMethod.name().equals("valueOf") && |
|
631 |
currentMethod.parameters().length == 1) { |
|
632 |
Type paramType = currentMethod.parameters()[0].type(); |
|
633 |
if (paramType != null && |
|
634 |
paramType.qualifiedTypeName().equals(String.class.getName())) { |
|
635 |
currentMethod.setRawCommentText( |
|
636 |
configuration.getText("doclet.enum_valueof_doc")); |
|
637 |
} |
|
638 |
} |
|
639 |
} |
|
640 |
} |
|
641 |
||
642 |
/** |
|
643 |
* Return true if the given Doc is deprecated. |
|
644 |
* |
|
645 |
* @param doc the Doc to check. |
|
646 |
* @return true if the given Doc is deprecated. |
|
647 |
*/ |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
648 |
public static boolean isDeprecated(Doc doc) { |
10 | 649 |
if (doc.tags("deprecated").length > 0) { |
650 |
return true; |
|
651 |
} |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
652 |
AnnotationDesc[] annotationDescList; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
653 |
if (doc instanceof PackageDoc) |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
654 |
annotationDescList = ((PackageDoc)doc).annotations(); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
655 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
656 |
annotationDescList = ((ProgramElementDoc)doc).annotations(); |
10 | 657 |
for (int i = 0; i < annotationDescList.length; i++) { |
658 |
if (annotationDescList[i].annotationType().qualifiedName().equals( |
|
659 |
java.lang.Deprecated.class.getName())){ |
|
660 |
return true; |
|
661 |
} |
|
662 |
} |
|
663 |
return false; |
|
664 |
} |
|
665 |
} |