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