author | ksrini |
Fri, 27 Jun 2014 17:54:54 -0700 | |
changeset 25300 | 3b8a5067fe29 |
parent 25004 | b33effe4f252 |
child 25449 | 3c14a2e16bd6 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
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; |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
32 |
import java.text.Collator; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
33 |
import java.util.*; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
34 |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
35 |
import javax.tools.StandardLocation; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
36 |
|
10 | 37 |
import com.sun.javadoc.*; |
15385 | 38 |
import com.sun.javadoc.AnnotationDesc.ElementValuePair; |
10 | 39 |
import com.sun.tools.doclets.internal.toolkit.*; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
40 |
import com.sun.tools.javac.util.StringUtils; |
10 | 41 |
|
42 |
/** |
|
43 |
* Utilities Class for Doclets. |
|
44 |
* |
|
14260 | 45 |
* <p><b>This is NOT part of any supported API. |
46 |
* If you write code that depends on this, you do so at your own risk. |
|
47 |
* This code and its internal interfaces are subject to change or |
|
48 |
* deletion without notice.</b> |
|
10 | 49 |
* |
50 |
* @author Atul M Dambalkar |
|
51 |
* @author Jamie Ho |
|
52 |
*/ |
|
53 |
public class Util { |
|
54 |
/** |
|
55 |
* Return array of class members whose documentation is to be generated. |
|
56 |
* If the member is deprecated do not include such a member in the |
|
57 |
* returned array. |
|
58 |
* |
|
59 |
* @param members Array of members to choose from. |
|
60 |
* @return ProgramElementDoc[] Array of eligible members for whom |
|
61 |
* documentation is getting generated. |
|
62 |
*/ |
|
63 |
public static ProgramElementDoc[] excludeDeprecatedMembers( |
|
64 |
ProgramElementDoc[] members) { |
|
65 |
return |
|
66 |
toProgramElementDocArray(excludeDeprecatedMembersAsList(members)); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Return array of class members whose documentation is to be generated. |
|
71 |
* If the member is deprecated do not include such a member in the |
|
72 |
* returned array. |
|
73 |
* |
|
74 |
* @param members Array of members to choose from. |
|
75 |
* @return List List of eligible members for whom |
|
76 |
* documentation is getting generated. |
|
77 |
*/ |
|
868 | 78 |
public static List<ProgramElementDoc> excludeDeprecatedMembersAsList( |
10 | 79 |
ProgramElementDoc[] members) { |
22163 | 80 |
List<ProgramElementDoc> list = new ArrayList<>(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
81 |
for (ProgramElementDoc member : members) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
82 |
if (member.tags("deprecated").length == 0) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
83 |
list.add(member); |
10 | 84 |
} |
85 |
} |
|
86 |
Collections.sort(list); |
|
87 |
return list; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Return the list of ProgramElementDoc objects as Array. |
|
92 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
93 |
public static ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) { |
10 | 94 |
ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()]; |
95 |
for (int i = 0; i < list.size(); i++) { |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
96 |
pgmarr[i] = list.get(i); |
10 | 97 |
} |
98 |
return pgmarr; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Return true if a non-public member found in the given array. |
|
103 |
* |
|
104 |
* @param members Array of members to look into. |
|
105 |
* @return boolean True if non-public member found, false otherwise. |
|
106 |
*/ |
|
107 |
public static boolean nonPublicMemberFound(ProgramElementDoc[] members) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
108 |
for (ProgramElementDoc member : members) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
109 |
if (!member.isPublic()) { |
10 | 110 |
return true; |
111 |
} |
|
112 |
} |
|
113 |
return false; |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* Search for the given method in the given class. |
|
118 |
* |
|
119 |
* @param cd Class to search into. |
|
120 |
* @param method Method to be searched. |
|
121 |
* @return MethodDoc Method found, null otherwise. |
|
122 |
*/ |
|
123 |
public static MethodDoc findMethod(ClassDoc cd, MethodDoc method) { |
|
124 |
MethodDoc[] methods = cd.methods(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
125 |
for (MethodDoc m : methods) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
126 |
if (executableMembersEqual(method, m)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
127 |
return m; |
10 | 128 |
|
129 |
} |
|
130 |
} |
|
131 |
return null; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* @param member1 the first method to compare. |
|
136 |
* @param member2 the second method to compare. |
|
137 |
* @return true if member1 overrides/hides or is overriden/hidden by member2. |
|
138 |
*/ |
|
139 |
public static boolean executableMembersEqual(ExecutableMemberDoc member1, |
|
140 |
ExecutableMemberDoc member2) { |
|
141 |
if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc)) |
|
142 |
return false; |
|
143 |
||
144 |
MethodDoc method1 = (MethodDoc) member1; |
|
145 |
MethodDoc method2 = (MethodDoc) member2; |
|
146 |
if (method1.isStatic() && method2.isStatic()) { |
|
147 |
Parameter[] targetParams = method1.parameters(); |
|
148 |
Parameter[] currentParams; |
|
149 |
if (method1.name().equals(method2.name()) && |
|
150 |
(currentParams = method2.parameters()).length == |
|
151 |
targetParams.length) { |
|
152 |
int j; |
|
153 |
for (j = 0; j < targetParams.length; j++) { |
|
154 |
if (! (targetParams[j].typeName().equals( |
|
155 |
currentParams[j].typeName()) || |
|
156 |
currentParams[j].type() instanceof TypeVariable || |
|
157 |
targetParams[j].type() instanceof TypeVariable)) { |
|
158 |
break; |
|
159 |
} |
|
160 |
} |
|
161 |
if (j == targetParams.length) { |
|
162 |
return true; |
|
163 |
} |
|
164 |
} |
|
165 |
return false; |
|
166 |
} else { |
|
167 |
return method1.overrides(method2) || |
|
168 |
method2.overrides(method1) || |
|
169 |
member1 == member2; |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
/** |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
174 |
* According to |
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
175 |
* <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
|
176 |
* all the outer classes and static inner classes are core classes. |
10 | 177 |
*/ |
178 |
public static boolean isCoreClass(ClassDoc cd) { |
|
179 |
return cd.containingClass() == null || cd.isStatic(); |
|
180 |
} |
|
181 |
||
182 |
public static boolean matches(ProgramElementDoc doc1, |
|
183 |
ProgramElementDoc doc2) { |
|
184 |
if (doc1 instanceof ExecutableMemberDoc && |
|
185 |
doc2 instanceof ExecutableMemberDoc) { |
|
186 |
ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1; |
|
187 |
ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2; |
|
188 |
return executableMembersEqual(ed1, ed2); |
|
189 |
} else { |
|
190 |
return doc1.name().equals(doc2.name()); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* Copy the given directory contents from the source package directory |
|
196 |
* to the generated documentation directory. For example for a package |
|
197 |
* java.lang this method find out the source location of the package using |
|
198 |
* {@link SourcePath} and if given directory is found in the source |
|
199 |
* directory structure, copy the entire directory, to the generated |
|
200 |
* documentation hierarchy. |
|
201 |
* |
|
202 |
* @param configuration The configuration of the current doclet. |
|
203 |
* @param path The relative path to the directory to be copied. |
|
204 |
* @param dir The original directory name to copy from. |
|
205 |
* @param overwrite Overwrite files if true. |
|
206 |
*/ |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
207 |
public static void copyDocFiles(Configuration configuration, PackageDoc pd) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
208 |
copyDocFiles(configuration, DocPath.forPackage(pd).resolve(DocPaths.DOC_FILES)); |
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 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
211 |
public static void copyDocFiles(Configuration configuration, DocPath dir) { |
10 | 212 |
try { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
213 |
boolean first = true; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
214 |
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
|
215 |
if (!f.isDirectory()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
216 |
continue; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
217 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
218 |
DocFile srcdir = f; |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
219 |
DocFile destdir = DocFile.createFileForOutput(configuration, dir); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
220 |
if (srcdir.isSameFile(destdir)) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
221 |
continue; |
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 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
224 |
for (DocFile srcfile: srcdir.list()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
225 |
DocFile destfile = destdir.resolve(srcfile.getName()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
226 |
if (srcfile.isFile()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
227 |
if (destfile.exists() && !first) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
228 |
configuration.message.warning((SourcePosition) null, |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
229 |
"doclet.Copy_Overwrite_warning", |
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 |
} else { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
232 |
configuration.message.notice( |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
233 |
"doclet.Copying_File_0_To_Dir_1", |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
234 |
srcfile.getPath(), destdir.getPath()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
235 |
destfile.copyFile(srcfile); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
236 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
237 |
} else if (srcfile.isDirectory()) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
238 |
if (configuration.copydocfilesubdirs |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
239 |
&& !configuration.shouldExcludeDocFileDir(srcfile.getName())) { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
240 |
copyDocFiles(configuration, dir.resolve(srcfile.getName())); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
241 |
} |
10 | 242 |
} |
243 |
} |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
244 |
|
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14366
diff
changeset
|
245 |
first = false; |
10 | 246 |
} |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
247 |
} catch (SecurityException | IOException exc) { |
19667
fdfce85627a9
8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents:
19510
diff
changeset
|
248 |
throw new DocletAbortException(exc); |
10 | 249 |
} |
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* We want the list of types in alphabetical order. However, types are not |
|
254 |
* comparable. We need a comparator for now. |
|
255 |
*/ |
|
868 | 256 |
private static class TypeComparator implements Comparator<Type> { |
257 |
public int compare(Type type1, Type type2) { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
258 |
return type1.qualifiedTypeName().compareToIgnoreCase( |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
259 |
type2.qualifiedTypeName()); |
10 | 260 |
} |
261 |
} |
|
262 |
||
263 |
/** |
|
264 |
* For the class return all implemented interfaces including the |
|
265 |
* superinterfaces of the implementing interfaces, also iterate over for |
|
266 |
* all the superclasses. For interface return all the extended interfaces |
|
267 |
* as well as superinterfaces for those extended interfaces. |
|
268 |
* |
|
269 |
* @param type type whose implemented or |
|
270 |
* super interfaces are sought. |
|
271 |
* @param configuration the current configuration of the doclet. |
|
272 |
* @param sort if true, return list of interfaces sorted alphabetically. |
|
273 |
* @return List of all the required interfaces. |
|
274 |
*/ |
|
868 | 275 |
public static List<Type> getAllInterfaces(Type type, |
10 | 276 |
Configuration configuration, boolean sort) { |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
277 |
Map<ClassDoc,Type> results = sort ? |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
278 |
new TreeMap<ClassDoc,Type>() : |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
279 |
new LinkedHashMap<ClassDoc,Type>(); |
10 | 280 |
Type[] interfaceTypes = null; |
281 |
Type superType = null; |
|
282 |
if (type instanceof ParameterizedType) { |
|
283 |
interfaceTypes = ((ParameterizedType) type).interfaceTypes(); |
|
284 |
superType = ((ParameterizedType) type).superclassType(); |
|
285 |
} else if (type instanceof ClassDoc) { |
|
286 |
interfaceTypes = ((ClassDoc) type).interfaceTypes(); |
|
287 |
superType = ((ClassDoc) type).superclassType(); |
|
288 |
} else { |
|
289 |
interfaceTypes = type.asClassDoc().interfaceTypes(); |
|
290 |
superType = type.asClassDoc().superclassType(); |
|
291 |
} |
|
292 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
293 |
for (Type interfaceType : interfaceTypes) { |
10 | 294 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
295 |
if (!(interfaceClassDoc.isPublic() || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
296 |
(configuration == null || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
297 |
isLinkable(interfaceClassDoc, configuration)))) { |
10 | 298 |
continue; |
299 |
} |
|
300 |
results.put(interfaceClassDoc, interfaceType); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
301 |
for (Type t : getAllInterfaces(interfaceType, configuration, sort)) { |
10 | 302 |
results.put(t.asClassDoc(), t); |
303 |
} |
|
304 |
} |
|
305 |
if (superType == null) |
|
22163 | 306 |
return new ArrayList<>(results.values()); |
10 | 307 |
//Try walking the tree. |
308 |
addAllInterfaceTypes(results, |
|
309 |
superType, |
|
15385 | 310 |
interfaceTypesOf(superType), |
10 | 311 |
false, configuration); |
22163 | 312 |
List<Type> resultsList = new ArrayList<>(results.values()); |
10 | 313 |
if (sort) { |
314 |
Collections.sort(resultsList, new TypeComparator()); |
|
315 |
} |
|
316 |
return resultsList; |
|
317 |
} |
|
318 |
||
15385 | 319 |
private static Type[] interfaceTypesOf(Type type) { |
320 |
if (type instanceof AnnotatedType) |
|
321 |
type = ((AnnotatedType)type).underlyingType(); |
|
322 |
return type instanceof ClassDoc ? |
|
323 |
((ClassDoc)type).interfaceTypes() : |
|
324 |
((ParameterizedType)type).interfaceTypes(); |
|
325 |
} |
|
326 |
||
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
327 |
public static List<Type> getAllInterfaces(Type type, Configuration configuration) { |
10 | 328 |
return getAllInterfaces(type, configuration, true); |
329 |
} |
|
330 |
||
868 | 331 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw, |
10 | 332 |
Configuration configuration) { |
333 |
Type superType = c.superclassType(); |
|
334 |
if (superType == null) |
|
335 |
return; |
|
336 |
addAllInterfaceTypes(results, superType, |
|
15385 | 337 |
interfaceTypesOf(superType), |
10 | 338 |
raw, configuration); |
339 |
} |
|
340 |
||
868 | 341 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p, |
10 | 342 |
Configuration configuration) { |
343 |
Type superType = p.superclassType(); |
|
344 |
if (superType == null) |
|
345 |
return; |
|
346 |
addAllInterfaceTypes(results, superType, |
|
15385 | 347 |
interfaceTypesOf(superType), |
10 | 348 |
false, configuration); |
349 |
} |
|
350 |
||
868 | 351 |
private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type, |
10 | 352 |
Type[] interfaceTypes, boolean raw, |
353 |
Configuration configuration) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
354 |
for (Type interfaceType : interfaceTypes) { |
10 | 355 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
356 |
if (!(interfaceClassDoc.isPublic() || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
357 |
(configuration != null && |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
358 |
isLinkable(interfaceClassDoc, configuration)))) { |
10 | 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); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
365 |
for (Type superInterface : superInterfaces) { |
10 | 366 |
results.put(superInterface.asClassDoc(), superInterface); |
367 |
} |
|
368 |
} |
|
15385 | 369 |
if (type instanceof AnnotatedType) |
370 |
type = ((AnnotatedType)type).underlyingType(); |
|
371 |
||
10 | 372 |
if (type instanceof ParameterizedType) |
373 |
findAllInterfaceTypes(results, (ParameterizedType) type, configuration); |
|
374 |
else if (((ClassDoc) type).typeParameters().length == 0) |
|
375 |
findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration); |
|
376 |
else |
|
377 |
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); |
|
378 |
} |
|
379 |
||
380 |
/** |
|
381 |
* Enclose in quotes, used for paths and filenames that contains spaces |
|
382 |
*/ |
|
383 |
public static String quote(String filepath) { |
|
384 |
return ("\"" + filepath + "\""); |
|
385 |
} |
|
386 |
||
387 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
388 |
* Given a package, return its name. |
10 | 389 |
* @param packageDoc the package to check. |
390 |
* @return the name of the given package. |
|
391 |
*/ |
|
392 |
public static String getPackageName(PackageDoc packageDoc) { |
|
393 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
394 |
DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name(); |
|
395 |
} |
|
396 |
||
397 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
398 |
* Given a package, return its file name without the extension. |
10 | 399 |
* @param packageDoc the package to check. |
400 |
* @return the file name of the given package. |
|
401 |
*/ |
|
402 |
public static String getPackageFileHeadName(PackageDoc packageDoc) { |
|
403 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
404 |
DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name(); |
|
405 |
} |
|
406 |
||
407 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
408 |
* Given a string, replace all occurrences of 'newStr' with 'oldStr'. |
10 | 409 |
* @param originalStr the string to modify. |
410 |
* @param oldStr the string to replace. |
|
411 |
* @param newStr the string to insert in place of the old string. |
|
412 |
*/ |
|
413 |
public static String replaceText(String originalStr, String oldStr, |
|
414 |
String newStr) { |
|
415 |
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { |
|
416 |
return originalStr; |
|
417 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
418 |
return originalStr.replace(oldStr, newStr); |
10 | 419 |
} |
420 |
||
421 |
/** |
|
422 |
* Given an annotation, return true if it should be documented and false |
|
423 |
* otherwise. |
|
424 |
* |
|
425 |
* @param annotationDoc the annotation to check. |
|
426 |
* |
|
427 |
* @return true return true if it should be documented and false otherwise. |
|
428 |
*/ |
|
429 |
public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
430 |
for (AnnotationDesc anno : annotationDoc.annotations()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
431 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
432 |
Documented.class.getName())) { |
10 | 433 |
return true; |
434 |
} |
|
435 |
} |
|
436 |
return false; |
|
437 |
} |
|
438 |
||
15385 | 439 |
private static boolean isDeclarationTarget(AnnotationDesc targetAnno) { |
440 |
// The error recovery steps here are analogous to TypeAnnotations |
|
441 |
ElementValuePair[] elems = targetAnno.elementValues(); |
|
442 |
if (elems == null |
|
443 |
|| elems.length != 1 |
|
444 |
|| !"value".equals(elems[0].element().name()) |
|
445 |
|| !(elems[0].value().value() instanceof AnnotationValue[])) |
|
446 |
return true; // error recovery |
|
447 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
448 |
for (AnnotationValue aValue : (AnnotationValue[])elems[0].value().value()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
449 |
Object value = aValue.value(); |
15385 | 450 |
if (!(value instanceof FieldDoc)) |
451 |
return true; // error recovery |
|
452 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
453 |
FieldDoc eValue = (FieldDoc) value; |
15385 | 454 |
if (Util.isJava5DeclarationElementType(eValue)) { |
455 |
return true; |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
return false; |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Returns true if the {@code annotationDoc} is to be treated |
|
464 |
* as a declaration annotation, when targeting the |
|
465 |
* {@code elemType} element type. |
|
466 |
* |
|
467 |
* @param annotationDoc the annotationDoc to check |
|
468 |
* @param elemType the targeted elemType |
|
469 |
* @return true if annotationDoc is a declaration annotation |
|
470 |
*/ |
|
471 |
public static boolean isDeclarationAnnotation(AnnotationTypeDoc annotationDoc, |
|
472 |
boolean isJava5DeclarationLocation) { |
|
473 |
if (!isJava5DeclarationLocation) |
|
474 |
return false; |
|
475 |
AnnotationDesc[] annotationDescList = annotationDoc.annotations(); |
|
476 |
// Annotations with no target are treated as declaration as well |
|
477 |
if (annotationDescList.length==0) |
|
478 |
return true; |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
479 |
for (AnnotationDesc anno : annotationDescList) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
480 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
481 |
Target.class.getName())) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
482 |
if (isDeclarationTarget(anno)) |
15385 | 483 |
return true; |
484 |
} |
|
485 |
} |
|
486 |
return false; |
|
487 |
} |
|
488 |
||
10 | 489 |
/** |
490 |
* Return true if this class is linkable and false if we can't link to the |
|
491 |
* desired class. |
|
492 |
* <br> |
|
493 |
* <b>NOTE:</b> You can only link to external classes if they are public or |
|
494 |
* protected. |
|
495 |
* |
|
496 |
* @param classDoc the class to check. |
|
497 |
* @param configuration the current configuration of the doclet. |
|
498 |
* |
|
499 |
* @return true if this class is linkable and false if we can't link to the |
|
500 |
* desired class. |
|
501 |
*/ |
|
502 |
public static boolean isLinkable(ClassDoc classDoc, |
|
503 |
Configuration configuration) { |
|
504 |
return |
|
505 |
((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) || |
|
506 |
(configuration.extern.isExternal(classDoc) && |
|
507 |
(classDoc.isPublic() || classDoc.isProtected())); |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Given a class, return the closest visible super class. |
|
512 |
* |
|
513 |
* @param classDoc the class we are searching the parent for. |
|
514 |
* @param configuration the current configuration of the doclet. |
|
515 |
* @return the closest visible super class. Return null if it cannot |
|
516 |
* be found (i.e. classDoc is java.lang.Object). |
|
517 |
*/ |
|
518 |
public static Type getFirstVisibleSuperClass(ClassDoc classDoc, |
|
519 |
Configuration configuration) { |
|
520 |
if (classDoc == null) { |
|
521 |
return null; |
|
522 |
} |
|
523 |
Type sup = classDoc.superclassType(); |
|
524 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
525 |
while (sup != null && |
|
526 |
(! (supClassDoc.isPublic() || |
|
527 |
isLinkable(supClassDoc, configuration))) ) { |
|
528 |
if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName())) |
|
529 |
break; |
|
530 |
sup = supClassDoc.superclassType(); |
|
531 |
supClassDoc = supClassDoc.superclass(); |
|
532 |
} |
|
533 |
if (classDoc.equals(supClassDoc)) { |
|
534 |
return null; |
|
535 |
} |
|
536 |
return sup; |
|
537 |
} |
|
538 |
||
539 |
/** |
|
540 |
* Given a class, return the closest visible super class. |
|
541 |
* |
|
542 |
* @param classDoc the class we are searching the parent for. |
|
543 |
* @param configuration the current configuration of the doclet. |
|
544 |
* @return the closest visible super class. Return null if it cannot |
|
545 |
* be found (i.e. classDoc is java.lang.Object). |
|
546 |
*/ |
|
547 |
public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc, |
|
548 |
Configuration configuration) { |
|
549 |
if (classDoc == null) { |
|
550 |
return null; |
|
551 |
} |
|
552 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
553 |
while (supClassDoc != null && |
|
554 |
(! (supClassDoc.isPublic() || |
|
555 |
isLinkable(supClassDoc, configuration))) ) { |
|
556 |
supClassDoc = supClassDoc.superclass(); |
|
557 |
} |
|
558 |
if (classDoc.equals(supClassDoc)) { |
|
559 |
return null; |
|
560 |
} |
|
561 |
return supClassDoc; |
|
562 |
} |
|
563 |
||
564 |
/** |
|
565 |
* Given a ClassDoc, return the name of its type (Class, Interface, etc.). |
|
566 |
* |
|
567 |
* @param cd the ClassDoc to check. |
|
568 |
* @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
|
569 |
* If false, the first letter of the name is capitalized. |
10 | 570 |
* @return |
571 |
*/ |
|
572 |
public static String getTypeName(Configuration config, |
|
573 |
ClassDoc cd, boolean lowerCaseOnly) { |
|
574 |
String typeName = ""; |
|
575 |
if (cd.isOrdinaryClass()) { |
|
576 |
typeName = "doclet.Class"; |
|
577 |
} else if (cd.isInterface()) { |
|
578 |
typeName = "doclet.Interface"; |
|
579 |
} else if (cd.isException()) { |
|
580 |
typeName = "doclet.Exception"; |
|
581 |
} else if (cd.isError()) { |
|
582 |
typeName = "doclet.Error"; |
|
583 |
} else if (cd.isAnnotationType()) { |
|
584 |
typeName = "doclet.AnnotationType"; |
|
585 |
} else if (cd.isEnum()) { |
|
586 |
typeName = "doclet.Enum"; |
|
587 |
} |
|
588 |
return config.getText( |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
589 |
lowerCaseOnly ? StringUtils.toLowerCase(typeName) : typeName); |
10 | 590 |
} |
591 |
||
592 |
/** |
|
17571 | 593 |
* Replace all tabs in a string with the appropriate number of spaces. |
594 |
* The string may be a multi-line string. |
|
14542 | 595 |
* @param configuration the doclet configuration defining the setting for the |
596 |
* tab length. |
|
17571 | 597 |
* @param text the text for which the tabs should be expanded |
598 |
* @return the text with all tabs expanded |
|
10 | 599 |
*/ |
17571 | 600 |
public static String replaceTabs(Configuration configuration, String text) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
601 |
if (!text.contains("\t")) |
17571 | 602 |
return text; |
603 |
||
604 |
final int tabLength = configuration.sourcetab; |
|
605 |
final String whitespace = configuration.tabSpaces; |
|
606 |
final int textLength = text.length(); |
|
607 |
StringBuilder result = new StringBuilder(textLength); |
|
608 |
int pos = 0; |
|
609 |
int lineLength = 0; |
|
610 |
for (int i = 0; i < textLength; i++) { |
|
611 |
char ch = text.charAt(i); |
|
612 |
switch (ch) { |
|
613 |
case '\n': case '\r': |
|
614 |
lineLength = 0; |
|
615 |
break; |
|
616 |
case '\t': |
|
617 |
result.append(text, pos, i); |
|
618 |
int spaceCount = tabLength - lineLength % tabLength; |
|
619 |
result.append(whitespace, 0, spaceCount); |
|
620 |
lineLength += spaceCount; |
|
621 |
pos = i + 1; |
|
622 |
break; |
|
623 |
default: |
|
624 |
lineLength++; |
|
625 |
} |
|
10 | 626 |
} |
17571 | 627 |
result.append(text, pos, textLength); |
628 |
return result.toString(); |
|
10 | 629 |
} |
630 |
||
19119 | 631 |
public static String normalizeNewlines(String text) { |
632 |
StringBuilder sb = new StringBuilder(); |
|
633 |
final int textLength = text.length(); |
|
634 |
final String NL = DocletConstants.NL; |
|
635 |
int pos = 0; |
|
636 |
for (int i = 0; i < textLength; i++) { |
|
637 |
char ch = text.charAt(i); |
|
638 |
switch (ch) { |
|
639 |
case '\n': |
|
640 |
sb.append(text, pos, i); |
|
641 |
sb.append(NL); |
|
642 |
pos = i + 1; |
|
643 |
break; |
|
644 |
case '\r': |
|
645 |
sb.append(text, pos, i); |
|
646 |
sb.append(NL); |
|
647 |
if (i + 1 < textLength && text.charAt(i + 1) == '\n') |
|
648 |
i++; |
|
649 |
pos = i + 1; |
|
650 |
break; |
|
651 |
} |
|
652 |
} |
|
653 |
sb.append(text, pos, textLength); |
|
654 |
return sb.toString(); |
|
655 |
} |
|
656 |
||
10 | 657 |
/** |
658 |
* The documentation for values() and valueOf() in Enums are set by the |
|
659 |
* doclet. |
|
660 |
*/ |
|
661 |
public static void setEnumDocumentation(Configuration configuration, |
|
662 |
ClassDoc classDoc) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
663 |
for (MethodDoc currentMethod : classDoc.methods()) { |
10 | 664 |
if (currentMethod.name().equals("values") && |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
665 |
currentMethod.parameters().length == 0) { |
19510
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
666 |
StringBuilder sb = new StringBuilder(); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
667 |
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
|
668 |
sb.append("\n@return "); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
669 |
sb.append(configuration.getText("doclet.enum_values_doc.return")); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
670 |
currentMethod.setRawCommentText(sb.toString()); |
10 | 671 |
} else if (currentMethod.name().equals("valueOf") && |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
672 |
currentMethod.parameters().length == 1) { |
10 | 673 |
Type paramType = currentMethod.parameters()[0].type(); |
674 |
if (paramType != null && |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
675 |
paramType.qualifiedTypeName().equals(String.class.getName())) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
676 |
StringBuilder sb = new StringBuilder(); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
677 |
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
|
678 |
sb.append("\n@param name "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
679 |
sb.append(configuration.getText("doclet.enum_valueof_doc.param_name")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
680 |
sb.append("\n@return "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
681 |
sb.append(configuration.getText("doclet.enum_valueof_doc.return")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
682 |
sb.append("\n@throws IllegalArgumentException "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
683 |
sb.append(configuration.getText("doclet.enum_valueof_doc.throws_ila")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
684 |
sb.append("\n@throws NullPointerException "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
685 |
sb.append(configuration.getText("doclet.enum_valueof_doc.throws_npe")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
686 |
currentMethod.setRawCommentText(sb.toString()); |
10 | 687 |
} |
688 |
} |
|
689 |
} |
|
690 |
} |
|
691 |
||
692 |
/** |
|
693 |
* Return true if the given Doc is deprecated. |
|
694 |
* |
|
695 |
* @param doc the Doc to check. |
|
696 |
* @return true if the given Doc is deprecated. |
|
697 |
*/ |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
698 |
public static boolean isDeprecated(Doc doc) { |
10 | 699 |
if (doc.tags("deprecated").length > 0) { |
700 |
return true; |
|
701 |
} |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
702 |
AnnotationDesc[] annotationDescList; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
703 |
if (doc instanceof PackageDoc) |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
704 |
annotationDescList = ((PackageDoc)doc).annotations(); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
705 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
706 |
annotationDescList = ((ProgramElementDoc)doc).annotations(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
707 |
for (AnnotationDesc anno : annotationDescList) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
708 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
709 |
Deprecated.class.getName())) { |
10 | 710 |
return true; |
711 |
} |
|
712 |
} |
|
713 |
return false; |
|
714 |
} |
|
15385 | 715 |
|
716 |
/** |
|
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
717 |
* 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
|
718 |
* getter or setter method. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
719 |
* @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
|
720 |
* @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
|
721 |
*/ |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
722 |
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
|
723 |
String propertyName = null; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
724 |
if (name.startsWith("get") || name.startsWith("set")) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
725 |
propertyName = name.substring(3); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
726 |
} else if (name.startsWith("is")) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
727 |
propertyName = name.substring(2); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
728 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
729 |
if ((propertyName == null) || propertyName.isEmpty()){ |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
730 |
return ""; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
731 |
} |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
732 |
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
|
733 |
+ propertyName.substring(1); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
734 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
735 |
|
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 |
* 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
|
738 |
* 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
|
739 |
* documented in JavaFX mode. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
740 |
* |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
741 |
* @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
|
742 |
* @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
|
743 |
* @return list of filtered classes. |
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 |
public static ClassDoc[] filterOutPrivateClasses(final ClassDoc[] classes, |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
746 |
boolean javafx) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
747 |
if (!javafx) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
748 |
return classes; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
749 |
} |
22163 | 750 |
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
|
751 |
for (ClassDoc classDoc : classes) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
752 |
if (classDoc.isPrivate() || classDoc.isPackagePrivate()) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
753 |
continue; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
754 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
755 |
Tag[] aspTags = classDoc.tags("treatAsPrivate"); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
756 |
if (aspTags != null && aspTags.length > 0) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
757 |
continue; |
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 |
filteredOutClasses.add(classDoc); |
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 |
return filteredOutClasses.toArray(new ClassDoc[0]); |
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 |
|
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
765 |
/** |
15385 | 766 |
* Test whether the given FieldDoc is one of the declaration annotation ElementTypes |
767 |
* defined in Java 5. |
|
768 |
* Instead of testing for one of the new enum constants added in Java 8, test for |
|
769 |
* the old constants. This prevents bootstrapping problems. |
|
770 |
* |
|
771 |
* @param elt The FieldDoc to test |
|
772 |
* @return true, iff the given ElementType is one of the constants defined in Java 5 |
|
773 |
* @since 1.8 |
|
774 |
*/ |
|
775 |
public static boolean isJava5DeclarationElementType(FieldDoc elt) { |
|
776 |
return elt.name().contentEquals(ElementType.ANNOTATION_TYPE.name()) || |
|
777 |
elt.name().contentEquals(ElementType.CONSTRUCTOR.name()) || |
|
778 |
elt.name().contentEquals(ElementType.FIELD.name()) || |
|
779 |
elt.name().contentEquals(ElementType.LOCAL_VARIABLE.name()) || |
|
780 |
elt.name().contentEquals(ElementType.METHOD.name()) || |
|
781 |
elt.name().contentEquals(ElementType.PACKAGE.name()) || |
|
782 |
elt.name().contentEquals(ElementType.PARAMETER.name()) || |
|
783 |
elt.name().contentEquals(ElementType.TYPE.name()); |
|
784 |
} |
|
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
785 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
786 |
/** |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
787 |
* A general purpose case insensitive String comparator, which compares two Strings using a Collator |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
788 |
* strength of "TERTIARY". |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
789 |
* |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
790 |
* @param s1 first String to compare. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
791 |
* @param s2 second String to compare. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
792 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
793 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
794 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
795 |
public static int compareStrings(String s1, String s2) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
796 |
return compareStrings(true, s1, s2); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
797 |
} |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
798 |
/** |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
799 |
* A general purpose case sensitive String comparator, which compares two Strings using a Collator |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
800 |
* strength of "SECONDARY". |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
801 |
* |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
802 |
* @param s1 first String to compare. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
803 |
* @param s2 second String to compare. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
804 |
* @return a negative integer, zero, or a positive integer as the first |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
805 |
* argument is less than, equal to, or greater than the second. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
806 |
*/ |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
807 |
public static int compareCaseCompare(String s1, String s2) { |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
808 |
return compareStrings(false, s1, s2); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
809 |
} |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
810 |
private static int compareStrings(boolean caseSensitive, String s1, String s2) { |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
811 |
Collator collator = Collator.getInstance(); |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
812 |
collator.setStrength(caseSensitive ? Collator.TERTIARY : Collator.SECONDARY); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
813 |
return collator.compare(s1, s2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
814 |
} |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
815 |
|
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
816 |
/** |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
817 |
* A comparator for index file presentations, |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
818 |
* 1. this sorts first on simple names |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
819 |
* 2. if equal, then compare the DocKind ex: Package, Interface etc. |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
820 |
* 3a. if equal and if the type is of ExecutableMemberDoc(Constructor, Fields), |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
821 |
* a case insensitive comparison of parameter types |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
822 |
* 3b. if equal, a case sensitive comparison of parameter types |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
823 |
* 4. finally, if equal, compare the FQNs of the entities |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
824 |
* @return a comparator for index file use |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
825 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
826 |
public static Comparator<Doc> makeComparatorForIndexUse() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
827 |
return new Util.DocComparator<Doc>() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
828 |
/** |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
829 |
* Compare two given Doc entities, first sort on name, then on the kinds, |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
830 |
* then on the parameters only if the type is an instance of ExecutableMemberDocs, |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
831 |
* the parameters are compared ignoring the case first, then a case sensitive comparison, |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
832 |
* and finally the fully qualified names. |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
833 |
* |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
834 |
* @param d1 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
835 |
* @param d2 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
836 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
837 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
838 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
839 |
public int compare(Doc d1, Doc d2) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
840 |
int result = compareNames(d1, d2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
841 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
842 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
843 |
} |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
844 |
result = compareDocKinds(d1, d2); |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
845 |
if (result != 0) { |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
846 |
return result; |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
847 |
} |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
848 |
if (hasParameters(d1)) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
849 |
Parameter[] param1 = ((ExecutableMemberDoc) d1).parameters(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
850 |
Parameter[] param2 = ((ExecutableMemberDoc) d2).parameters(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
851 |
result = compareParameters(false, param1, param2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
852 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
853 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
854 |
} |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
855 |
result = compareParameters(true, param1, param2); |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
856 |
if (result != 0) { |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
857 |
return result; |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
858 |
} |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
859 |
} |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
860 |
return compareFullyQualifiedNames(d1, d2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
861 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
862 |
}; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
863 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
864 |
/** |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
865 |
* Comparator for ClassUse presentations, and sorts as follows: |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
866 |
* 1. member names |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
867 |
* 2. then fully qualified member names |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
868 |
* 3. then parameter types if applicable |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
869 |
* 4. finally the Doc kinds ie. package, class, interface etc. |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
870 |
* @return a comparator to sort classes and members for class use |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
871 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
872 |
public static Comparator<Doc> makeComparatorForClassUse() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
873 |
return new Util.DocComparator<Doc>() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
874 |
/** |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
875 |
* Compare two given Doc entities, first sort on name, and if |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
876 |
* applicable on the fully qualified name, and if applicable |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
877 |
* on the parameter types, and finally the DocKind. |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
878 |
* @param d1 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
879 |
* @param d2 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
880 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
881 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
882 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
883 |
public int compare(Doc d1, Doc d2) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
884 |
int result = compareNames(d1, d2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
885 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
886 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
887 |
} |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
888 |
result = compareFullyQualifiedNames(d1, d2); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
889 |
if (result != 0) { |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
890 |
return result; |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
891 |
} |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
892 |
if (hasParameters(d1) && hasParameters(d2)) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
893 |
Parameter[] param1 = ((ExecutableMemberDoc) d1).parameters(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
894 |
Parameter[] param2 = ((ExecutableMemberDoc) d2).parameters(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
895 |
result = compareParameters(false, param1, param2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
896 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
897 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
898 |
} |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
899 |
return compareParameters(true, param1, param2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
900 |
} |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
901 |
return compareDocKinds(d1, d2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
902 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
903 |
}; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
904 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
905 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
906 |
* A general purpose comparator to sort Doc entities, basically provides the building blocks |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
907 |
* for creating specific comparators for an use-case. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
908 |
* @param <T> a Doc entity |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
909 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
910 |
static abstract class DocComparator<T extends Doc> implements Comparator<Doc> { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
911 |
static enum DocKind { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
912 |
PACKAGE, |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
913 |
CLASS, |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
914 |
ENUM, |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
915 |
INTERFACE, |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
916 |
ANNOTATION, |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
917 |
FIELD, |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
918 |
CONSTRUCTOR, |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
919 |
METHOD |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
920 |
}; |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
921 |
boolean hasParameters(Doc d) { |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
922 |
return d instanceof ExecutableMemberDoc; |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
923 |
} |
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
924 |
DocKind getDocKind(Doc d) { |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
925 |
if (d.isAnnotationType() || d.isAnnotationTypeElement()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
926 |
return DocKind.ANNOTATION; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
927 |
} else if (d.isEnum() || d.isEnumConstant()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
928 |
return DocKind.ENUM; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
929 |
} else if (d.isField()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
930 |
return DocKind.FIELD; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
931 |
} else if (d.isInterface()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
932 |
return DocKind.INTERFACE; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
933 |
} else if (d.isClass()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
934 |
return DocKind.CLASS; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
935 |
} else if (d.isConstructor()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
936 |
return DocKind.CONSTRUCTOR; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
937 |
} else if (d.isMethod()) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
938 |
return DocKind.METHOD; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
939 |
} else { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
940 |
return DocKind.PACKAGE; |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
941 |
} |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
942 |
} |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
943 |
/** |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
944 |
* Compares two Doc entities' kinds, and these are ordered as defined in |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
945 |
* the DocKind enumeration. |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
946 |
* @param d1 the first Doc object |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
947 |
* @param d2 the second Doc object |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
948 |
* @return a negative integer, zero, or a positive integer as the first |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
949 |
* argument is less than, equal to, or greater than the second. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
950 |
*/ |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
951 |
protected int compareDocKinds(Doc d1, Doc d2) { |
25300
3b8a5067fe29
8047162: [javadoc] index files are non deterministic
ksrini
parents:
25004
diff
changeset
|
952 |
return getDocKind(d1).compareTo(getDocKind(d2)); |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
953 |
} |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
954 |
/** |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
955 |
* Compares two parameter arrays by comparing each Type of the parameter in the array, |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
956 |
* and as many as possible, otherwise compare their lengths. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
957 |
* @param ignoreCase specifies case sensitive or insensitive comparison. |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
958 |
* @param params1 the first parameter array. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
959 |
* @param params2 the first parameter array. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
960 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
961 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
962 |
*/ |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
963 |
protected int compareParameters(boolean ignoreCase, Parameter[] params1, Parameter[] params2) { |
24394 | 964 |
// try to compare as many as possible |
965 |
for (int i = 0; i < params1.length && i < params2.length; i++) { |
|
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
966 |
int result = compareStrings(ignoreCase, params1[i].typeName(), params2[i].typeName()); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
967 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
968 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
969 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
970 |
} |
24394 | 971 |
return Integer.compare(params1.length, params2.length); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
972 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
973 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
974 |
/** |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
975 |
* Compares two Doc entities typically the simple name of a method, |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
976 |
* field, constructor etc. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
977 |
* @param d1 the first Doc. |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
978 |
* @param d2 the second Doc. |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
979 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
980 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
981 |
*/ |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
982 |
protected int compareNames(Doc d1, Doc d2) { |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
983 |
return compareStrings(d1.name(), d2.name()); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
984 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
985 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
986 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
987 |
* Compares the fully qualified names of the entities |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
988 |
* @param d1 the first entity |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
989 |
* @param d2 the second entity |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
990 |
* @return a negative integer, zero, or a positive integer as the first |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
991 |
* argument is less than, equal to, or greater than the second. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
992 |
*/ |
25004
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
993 |
protected int compareFullyQualifiedNames(Doc d1, Doc d2) { |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
994 |
String name1 = (d1 instanceof ProgramElementDoc) |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
995 |
? ((ProgramElementDoc)d1).qualifiedName() |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
996 |
: d1.name(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
997 |
String name2 = (d2 instanceof ProgramElementDoc) |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
998 |
? ((ProgramElementDoc)d2).qualifiedName() |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
999 |
: d2.name(); |
b33effe4f252
8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents:
24394
diff
changeset
|
1000 |
return compareStrings(name1, name2); |
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
1001 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
1002 |
} |
10 | 1003 |
} |