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