author | ksrini |
Fri, 18 Apr 2014 08:35:59 -0700 | |
changeset 24220 | eb213562268d |
parent 22165 | ec53c8946fc2 |
child 24394 | 74279778c307 |
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.*; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
34 |
import javax.tools.StandardLocation; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
35 |
|
10 | 36 |
import com.sun.javadoc.*; |
15385 | 37 |
import com.sun.javadoc.AnnotationDesc.ElementValuePair; |
10 | 38 |
import com.sun.tools.doclets.internal.toolkit.*; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
39 |
import com.sun.tools.javac.util.StringUtils; |
10 | 40 |
|
41 |
/** |
|
42 |
* Utilities Class for Doclets. |
|
43 |
* |
|
14260 | 44 |
* <p><b>This is NOT part of any supported API. |
45 |
* If you write code that depends on this, you do so at your own risk. |
|
46 |
* This code and its internal interfaces are subject to change or |
|
47 |
* deletion without notice.</b> |
|
10 | 48 |
* |
49 |
* @author Atul M Dambalkar |
|
50 |
* @author Jamie Ho |
|
51 |
*/ |
|
52 |
public class Util { |
|
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) { |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
276 |
Map<ClassDoc,Type> results = sort ? |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
277 |
new TreeMap<ClassDoc,Type>() : |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
278 |
new LinkedHashMap<ClassDoc,Type>(); |
10 | 279 |
Type[] interfaceTypes = null; |
280 |
Type superType = null; |
|
281 |
if (type instanceof ParameterizedType) { |
|
282 |
interfaceTypes = ((ParameterizedType) type).interfaceTypes(); |
|
283 |
superType = ((ParameterizedType) type).superclassType(); |
|
284 |
} else if (type instanceof ClassDoc) { |
|
285 |
interfaceTypes = ((ClassDoc) type).interfaceTypes(); |
|
286 |
superType = ((ClassDoc) type).superclassType(); |
|
287 |
} else { |
|
288 |
interfaceTypes = type.asClassDoc().interfaceTypes(); |
|
289 |
superType = type.asClassDoc().superclassType(); |
|
290 |
} |
|
291 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
292 |
for (Type interfaceType : interfaceTypes) { |
10 | 293 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
294 |
if (!(interfaceClassDoc.isPublic() || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
295 |
(configuration == null || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
296 |
isLinkable(interfaceClassDoc, configuration)))) { |
10 | 297 |
continue; |
298 |
} |
|
299 |
results.put(interfaceClassDoc, interfaceType); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
300 |
for (Type t : getAllInterfaces(interfaceType, configuration, sort)) { |
10 | 301 |
results.put(t.asClassDoc(), t); |
302 |
} |
|
303 |
} |
|
304 |
if (superType == null) |
|
22163 | 305 |
return new ArrayList<>(results.values()); |
10 | 306 |
//Try walking the tree. |
307 |
addAllInterfaceTypes(results, |
|
308 |
superType, |
|
15385 | 309 |
interfaceTypesOf(superType), |
10 | 310 |
false, configuration); |
22163 | 311 |
List<Type> resultsList = new ArrayList<>(results.values()); |
10 | 312 |
if (sort) { |
313 |
Collections.sort(resultsList, new TypeComparator()); |
|
314 |
} |
|
315 |
return resultsList; |
|
316 |
} |
|
317 |
||
15385 | 318 |
private static Type[] interfaceTypesOf(Type type) { |
319 |
if (type instanceof AnnotatedType) |
|
320 |
type = ((AnnotatedType)type).underlyingType(); |
|
321 |
return type instanceof ClassDoc ? |
|
322 |
((ClassDoc)type).interfaceTypes() : |
|
323 |
((ParameterizedType)type).interfaceTypes(); |
|
324 |
} |
|
325 |
||
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
326 |
public static List<Type> getAllInterfaces(Type type, Configuration configuration) { |
10 | 327 |
return getAllInterfaces(type, configuration, true); |
328 |
} |
|
329 |
||
868 | 330 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw, |
10 | 331 |
Configuration configuration) { |
332 |
Type superType = c.superclassType(); |
|
333 |
if (superType == null) |
|
334 |
return; |
|
335 |
addAllInterfaceTypes(results, superType, |
|
15385 | 336 |
interfaceTypesOf(superType), |
10 | 337 |
raw, configuration); |
338 |
} |
|
339 |
||
868 | 340 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p, |
10 | 341 |
Configuration configuration) { |
342 |
Type superType = p.superclassType(); |
|
343 |
if (superType == null) |
|
344 |
return; |
|
345 |
addAllInterfaceTypes(results, superType, |
|
15385 | 346 |
interfaceTypesOf(superType), |
10 | 347 |
false, configuration); |
348 |
} |
|
349 |
||
868 | 350 |
private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type, |
10 | 351 |
Type[] interfaceTypes, boolean raw, |
352 |
Configuration configuration) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
353 |
for (Type interfaceType : interfaceTypes) { |
10 | 354 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
355 |
if (!(interfaceClassDoc.isPublic() || |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
356 |
(configuration != null && |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
357 |
isLinkable(interfaceClassDoc, configuration)))) { |
10 | 358 |
continue; |
359 |
} |
|
360 |
if (raw) |
|
361 |
interfaceType = interfaceType.asClassDoc(); |
|
362 |
results.put(interfaceClassDoc, interfaceType); |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
363 |
List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
364 |
for (Type superInterface : superInterfaces) { |
10 | 365 |
results.put(superInterface.asClassDoc(), superInterface); |
366 |
} |
|
367 |
} |
|
15385 | 368 |
if (type instanceof AnnotatedType) |
369 |
type = ((AnnotatedType)type).underlyingType(); |
|
370 |
||
10 | 371 |
if (type instanceof ParameterizedType) |
372 |
findAllInterfaceTypes(results, (ParameterizedType) type, configuration); |
|
373 |
else if (((ClassDoc) type).typeParameters().length == 0) |
|
374 |
findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration); |
|
375 |
else |
|
376 |
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); |
|
377 |
} |
|
378 |
||
379 |
/** |
|
380 |
* Enclose in quotes, used for paths and filenames that contains spaces |
|
381 |
*/ |
|
382 |
public static String quote(String filepath) { |
|
383 |
return ("\"" + filepath + "\""); |
|
384 |
} |
|
385 |
||
386 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
387 |
* Given a package, return its name. |
10 | 388 |
* @param packageDoc the package to check. |
389 |
* @return the name of the given package. |
|
390 |
*/ |
|
391 |
public static String getPackageName(PackageDoc packageDoc) { |
|
392 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
393 |
DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name(); |
|
394 |
} |
|
395 |
||
396 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
397 |
* Given a package, return its file name without the extension. |
10 | 398 |
* @param packageDoc the package to check. |
399 |
* @return the file name of the given package. |
|
400 |
*/ |
|
401 |
public static String getPackageFileHeadName(PackageDoc packageDoc) { |
|
402 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
403 |
DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name(); |
|
404 |
} |
|
405 |
||
406 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
407 |
* Given a string, replace all occurrences of 'newStr' with 'oldStr'. |
10 | 408 |
* @param originalStr the string to modify. |
409 |
* @param oldStr the string to replace. |
|
410 |
* @param newStr the string to insert in place of the old string. |
|
411 |
*/ |
|
412 |
public static String replaceText(String originalStr, String oldStr, |
|
413 |
String newStr) { |
|
414 |
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { |
|
415 |
return originalStr; |
|
416 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
417 |
return originalStr.replace(oldStr, newStr); |
10 | 418 |
} |
419 |
||
420 |
/** |
|
421 |
* Given an annotation, return true if it should be documented and false |
|
422 |
* otherwise. |
|
423 |
* |
|
424 |
* @param annotationDoc the annotation to check. |
|
425 |
* |
|
426 |
* @return true return true if it should be documented and false otherwise. |
|
427 |
*/ |
|
428 |
public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
429 |
for (AnnotationDesc anno : annotationDoc.annotations()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
430 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
431 |
Documented.class.getName())) { |
10 | 432 |
return true; |
433 |
} |
|
434 |
} |
|
435 |
return false; |
|
436 |
} |
|
437 |
||
15385 | 438 |
private static boolean isDeclarationTarget(AnnotationDesc targetAnno) { |
439 |
// The error recovery steps here are analogous to TypeAnnotations |
|
440 |
ElementValuePair[] elems = targetAnno.elementValues(); |
|
441 |
if (elems == null |
|
442 |
|| elems.length != 1 |
|
443 |
|| !"value".equals(elems[0].element().name()) |
|
444 |
|| !(elems[0].value().value() instanceof AnnotationValue[])) |
|
445 |
return true; // error recovery |
|
446 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
447 |
for (AnnotationValue aValue : (AnnotationValue[])elems[0].value().value()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
448 |
Object value = aValue.value(); |
15385 | 449 |
if (!(value instanceof FieldDoc)) |
450 |
return true; // error recovery |
|
451 |
||
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
452 |
FieldDoc eValue = (FieldDoc) value; |
15385 | 453 |
if (Util.isJava5DeclarationElementType(eValue)) { |
454 |
return true; |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
return false; |
|
459 |
} |
|
460 |
||
461 |
/** |
|
462 |
* Returns true if the {@code annotationDoc} is to be treated |
|
463 |
* as a declaration annotation, when targeting the |
|
464 |
* {@code elemType} element type. |
|
465 |
* |
|
466 |
* @param annotationDoc the annotationDoc to check |
|
467 |
* @param elemType the targeted elemType |
|
468 |
* @return true if annotationDoc is a declaration annotation |
|
469 |
*/ |
|
470 |
public static boolean isDeclarationAnnotation(AnnotationTypeDoc annotationDoc, |
|
471 |
boolean isJava5DeclarationLocation) { |
|
472 |
if (!isJava5DeclarationLocation) |
|
473 |
return false; |
|
474 |
AnnotationDesc[] annotationDescList = annotationDoc.annotations(); |
|
475 |
// Annotations with no target are treated as declaration as well |
|
476 |
if (annotationDescList.length==0) |
|
477 |
return true; |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
478 |
for (AnnotationDesc anno : annotationDescList) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
479 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
480 |
Target.class.getName())) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
481 |
if (isDeclarationTarget(anno)) |
15385 | 482 |
return true; |
483 |
} |
|
484 |
} |
|
485 |
return false; |
|
486 |
} |
|
487 |
||
10 | 488 |
/** |
489 |
* Return true if this class is linkable and false if we can't link to the |
|
490 |
* desired class. |
|
491 |
* <br> |
|
492 |
* <b>NOTE:</b> You can only link to external classes if they are public or |
|
493 |
* protected. |
|
494 |
* |
|
495 |
* @param classDoc the class to check. |
|
496 |
* @param configuration the current configuration of the doclet. |
|
497 |
* |
|
498 |
* @return true if this class is linkable and false if we can't link to the |
|
499 |
* desired class. |
|
500 |
*/ |
|
501 |
public static boolean isLinkable(ClassDoc classDoc, |
|
502 |
Configuration configuration) { |
|
503 |
return |
|
504 |
((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) || |
|
505 |
(configuration.extern.isExternal(classDoc) && |
|
506 |
(classDoc.isPublic() || classDoc.isProtected())); |
|
507 |
} |
|
508 |
||
509 |
/** |
|
510 |
* Given a class, return the closest visible super class. |
|
511 |
* |
|
512 |
* @param classDoc the class we are searching the parent for. |
|
513 |
* @param configuration the current configuration of the doclet. |
|
514 |
* @return the closest visible super class. Return null if it cannot |
|
515 |
* be found (i.e. classDoc is java.lang.Object). |
|
516 |
*/ |
|
517 |
public static Type getFirstVisibleSuperClass(ClassDoc classDoc, |
|
518 |
Configuration configuration) { |
|
519 |
if (classDoc == null) { |
|
520 |
return null; |
|
521 |
} |
|
522 |
Type sup = classDoc.superclassType(); |
|
523 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
524 |
while (sup != null && |
|
525 |
(! (supClassDoc.isPublic() || |
|
526 |
isLinkable(supClassDoc, configuration))) ) { |
|
527 |
if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName())) |
|
528 |
break; |
|
529 |
sup = supClassDoc.superclassType(); |
|
530 |
supClassDoc = supClassDoc.superclass(); |
|
531 |
} |
|
532 |
if (classDoc.equals(supClassDoc)) { |
|
533 |
return null; |
|
534 |
} |
|
535 |
return sup; |
|
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
* Given a class, return the closest visible super class. |
|
540 |
* |
|
541 |
* @param classDoc the class we are searching the parent for. |
|
542 |
* @param configuration the current configuration of the doclet. |
|
543 |
* @return the closest visible super class. Return null if it cannot |
|
544 |
* be found (i.e. classDoc is java.lang.Object). |
|
545 |
*/ |
|
546 |
public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc, |
|
547 |
Configuration configuration) { |
|
548 |
if (classDoc == null) { |
|
549 |
return null; |
|
550 |
} |
|
551 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
552 |
while (supClassDoc != null && |
|
553 |
(! (supClassDoc.isPublic() || |
|
554 |
isLinkable(supClassDoc, configuration))) ) { |
|
555 |
supClassDoc = supClassDoc.superclass(); |
|
556 |
} |
|
557 |
if (classDoc.equals(supClassDoc)) { |
|
558 |
return null; |
|
559 |
} |
|
560 |
return supClassDoc; |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* Given a ClassDoc, return the name of its type (Class, Interface, etc.). |
|
565 |
* |
|
566 |
* @param cd the ClassDoc to check. |
|
567 |
* @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
|
568 |
* If false, the first letter of the name is capitalized. |
10 | 569 |
* @return |
570 |
*/ |
|
571 |
public static String getTypeName(Configuration config, |
|
572 |
ClassDoc cd, boolean lowerCaseOnly) { |
|
573 |
String typeName = ""; |
|
574 |
if (cd.isOrdinaryClass()) { |
|
575 |
typeName = "doclet.Class"; |
|
576 |
} else if (cd.isInterface()) { |
|
577 |
typeName = "doclet.Interface"; |
|
578 |
} else if (cd.isException()) { |
|
579 |
typeName = "doclet.Exception"; |
|
580 |
} else if (cd.isError()) { |
|
581 |
typeName = "doclet.Error"; |
|
582 |
} else if (cd.isAnnotationType()) { |
|
583 |
typeName = "doclet.AnnotationType"; |
|
584 |
} else if (cd.isEnum()) { |
|
585 |
typeName = "doclet.Enum"; |
|
586 |
} |
|
587 |
return config.getText( |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
588 |
lowerCaseOnly ? StringUtils.toLowerCase(typeName) : typeName); |
10 | 589 |
} |
590 |
||
591 |
/** |
|
17571 | 592 |
* Replace all tabs in a string with the appropriate number of spaces. |
593 |
* The string may be a multi-line string. |
|
14542 | 594 |
* @param configuration the doclet configuration defining the setting for the |
595 |
* tab length. |
|
17571 | 596 |
* @param text the text for which the tabs should be expanded |
597 |
* @return the text with all tabs expanded |
|
10 | 598 |
*/ |
17571 | 599 |
public static String replaceTabs(Configuration configuration, String text) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
600 |
if (!text.contains("\t")) |
17571 | 601 |
return text; |
602 |
||
603 |
final int tabLength = configuration.sourcetab; |
|
604 |
final String whitespace = configuration.tabSpaces; |
|
605 |
final int textLength = text.length(); |
|
606 |
StringBuilder result = new StringBuilder(textLength); |
|
607 |
int pos = 0; |
|
608 |
int lineLength = 0; |
|
609 |
for (int i = 0; i < textLength; i++) { |
|
610 |
char ch = text.charAt(i); |
|
611 |
switch (ch) { |
|
612 |
case '\n': case '\r': |
|
613 |
lineLength = 0; |
|
614 |
break; |
|
615 |
case '\t': |
|
616 |
result.append(text, pos, i); |
|
617 |
int spaceCount = tabLength - lineLength % tabLength; |
|
618 |
result.append(whitespace, 0, spaceCount); |
|
619 |
lineLength += spaceCount; |
|
620 |
pos = i + 1; |
|
621 |
break; |
|
622 |
default: |
|
623 |
lineLength++; |
|
624 |
} |
|
10 | 625 |
} |
17571 | 626 |
result.append(text, pos, textLength); |
627 |
return result.toString(); |
|
10 | 628 |
} |
629 |
||
19119 | 630 |
public static String normalizeNewlines(String text) { |
631 |
StringBuilder sb = new StringBuilder(); |
|
632 |
final int textLength = text.length(); |
|
633 |
final String NL = DocletConstants.NL; |
|
634 |
int pos = 0; |
|
635 |
for (int i = 0; i < textLength; i++) { |
|
636 |
char ch = text.charAt(i); |
|
637 |
switch (ch) { |
|
638 |
case '\n': |
|
639 |
sb.append(text, pos, i); |
|
640 |
sb.append(NL); |
|
641 |
pos = i + 1; |
|
642 |
break; |
|
643 |
case '\r': |
|
644 |
sb.append(text, pos, i); |
|
645 |
sb.append(NL); |
|
646 |
if (i + 1 < textLength && text.charAt(i + 1) == '\n') |
|
647 |
i++; |
|
648 |
pos = i + 1; |
|
649 |
break; |
|
650 |
} |
|
651 |
} |
|
652 |
sb.append(text, pos, textLength); |
|
653 |
return sb.toString(); |
|
654 |
} |
|
655 |
||
10 | 656 |
/** |
657 |
* The documentation for values() and valueOf() in Enums are set by the |
|
658 |
* doclet. |
|
659 |
*/ |
|
660 |
public static void setEnumDocumentation(Configuration configuration, |
|
661 |
ClassDoc classDoc) { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
662 |
for (MethodDoc currentMethod : classDoc.methods()) { |
10 | 663 |
if (currentMethod.name().equals("values") && |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
664 |
currentMethod.parameters().length == 0) { |
19510
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
665 |
StringBuilder sb = new StringBuilder(); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
666 |
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
|
667 |
sb.append("\n@return "); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
668 |
sb.append(configuration.getText("doclet.enum_values_doc.return")); |
d2afcb89b0e7
8020663: Restructure some properties to facilitate better translation
jjg
parents:
19119
diff
changeset
|
669 |
currentMethod.setRawCommentText(sb.toString()); |
10 | 670 |
} else if (currentMethod.name().equals("valueOf") && |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
671 |
currentMethod.parameters().length == 1) { |
10 | 672 |
Type paramType = currentMethod.parameters()[0].type(); |
673 |
if (paramType != null && |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
674 |
paramType.qualifiedTypeName().equals(String.class.getName())) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
675 |
StringBuilder sb = new StringBuilder(); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
676 |
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
|
677 |
sb.append("\n@param name "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
678 |
sb.append(configuration.getText("doclet.enum_valueof_doc.param_name")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
679 |
sb.append("\n@return "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
680 |
sb.append(configuration.getText("doclet.enum_valueof_doc.return")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
681 |
sb.append("\n@throws IllegalArgumentException "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
682 |
sb.append(configuration.getText("doclet.enum_valueof_doc.throws_ila")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
683 |
sb.append("\n@throws NullPointerException "); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
684 |
sb.append(configuration.getText("doclet.enum_valueof_doc.throws_npe")); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
685 |
currentMethod.setRawCommentText(sb.toString()); |
10 | 686 |
} |
687 |
} |
|
688 |
} |
|
689 |
} |
|
690 |
||
691 |
/** |
|
692 |
* Return true if the given Doc is deprecated. |
|
693 |
* |
|
694 |
* @param doc the Doc to check. |
|
695 |
* @return true if the given Doc is deprecated. |
|
696 |
*/ |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
697 |
public static boolean isDeprecated(Doc doc) { |
10 | 698 |
if (doc.tags("deprecated").length > 0) { |
699 |
return true; |
|
700 |
} |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
701 |
AnnotationDesc[] annotationDescList; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
702 |
if (doc instanceof PackageDoc) |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
703 |
annotationDescList = ((PackageDoc)doc).annotations(); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
704 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
705 |
annotationDescList = ((ProgramElementDoc)doc).annotations(); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
706 |
for (AnnotationDesc anno : annotationDescList) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
707 |
if (anno.annotationType().qualifiedName().equals( |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
22153
diff
changeset
|
708 |
Deprecated.class.getName())) { |
10 | 709 |
return true; |
710 |
} |
|
711 |
} |
|
712 |
return false; |
|
713 |
} |
|
15385 | 714 |
|
715 |
/** |
|
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
716 |
* 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
|
717 |
* getter or setter method. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
718 |
* @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
|
719 |
* @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
|
720 |
*/ |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
721 |
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
|
722 |
String propertyName = null; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
723 |
if (name.startsWith("get") || name.startsWith("set")) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
724 |
propertyName = name.substring(3); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
725 |
} else if (name.startsWith("is")) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
726 |
propertyName = name.substring(2); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
727 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
728 |
if ((propertyName == null) || propertyName.isEmpty()){ |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
729 |
return ""; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
730 |
} |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19667
diff
changeset
|
731 |
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
|
732 |
+ propertyName.substring(1); |
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 |
|
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 |
* 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
|
737 |
* 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
|
738 |
* documented in JavaFX mode. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
739 |
* |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
740 |
* @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
|
741 |
* @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
|
742 |
* @return list of filtered classes. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
743 |
*/ |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
744 |
public static ClassDoc[] filterOutPrivateClasses(final ClassDoc[] classes, |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
745 |
boolean javafx) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
746 |
if (!javafx) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
747 |
return classes; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
748 |
} |
22163 | 749 |
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
|
750 |
for (ClassDoc classDoc : classes) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
751 |
if (classDoc.isPrivate() || classDoc.isPackagePrivate()) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
752 |
continue; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
753 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
754 |
Tag[] aspTags = classDoc.tags("treatAsPrivate"); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
755 |
if (aspTags != null && aspTags.length > 0) { |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
756 |
continue; |
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 |
filteredOutClasses.add(classDoc); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
759 |
} |
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 |
return filteredOutClasses.toArray(new ClassDoc[0]); |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
15385
diff
changeset
|
762 |
} |
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 |
/** |
15385 | 765 |
* Test whether the given FieldDoc is one of the declaration annotation ElementTypes |
766 |
* defined in Java 5. |
|
767 |
* Instead of testing for one of the new enum constants added in Java 8, test for |
|
768 |
* the old constants. This prevents bootstrapping problems. |
|
769 |
* |
|
770 |
* @param elt The FieldDoc to test |
|
771 |
* @return true, iff the given ElementType is one of the constants defined in Java 5 |
|
772 |
* @since 1.8 |
|
773 |
*/ |
|
774 |
public static boolean isJava5DeclarationElementType(FieldDoc elt) { |
|
775 |
return elt.name().contentEquals(ElementType.ANNOTATION_TYPE.name()) || |
|
776 |
elt.name().contentEquals(ElementType.CONSTRUCTOR.name()) || |
|
777 |
elt.name().contentEquals(ElementType.FIELD.name()) || |
|
778 |
elt.name().contentEquals(ElementType.LOCAL_VARIABLE.name()) || |
|
779 |
elt.name().contentEquals(ElementType.METHOD.name()) || |
|
780 |
elt.name().contentEquals(ElementType.PACKAGE.name()) || |
|
781 |
elt.name().contentEquals(ElementType.PARAMETER.name()) || |
|
782 |
elt.name().contentEquals(ElementType.TYPE.name()); |
|
783 |
} |
|
24220
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
784 |
|
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 |
* A general purpose String comparator, which compares two Strings using a Collator |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
787 |
* strength of "SECONDARY", thus providing optimum case insensitive comparisons in |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
788 |
* most Locales. |
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) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
796 |
Collator collator = Collator.getInstance(); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
797 |
collator.setStrength(Collator.SECONDARY); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
798 |
return collator.compare(s1, s2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
799 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
800 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
801 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
802 |
* A comparator for index file uses, this sorts first on names, then on |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
803 |
* parameter types and finally on the fully qualified name. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
804 |
* @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
|
805 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
806 |
public static Comparator<Doc> makeComparatorForIndexUse() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
807 |
return new Util.DocComparator<Doc>() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
808 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
809 |
* compare two given Doc entities, first sort on name, if |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
810 |
* applicable on the method's parameter types, and finally on the |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
811 |
* fully qualified name of the entity. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
812 |
* |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
813 |
* @param d1 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
814 |
* @param d2 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
815 |
* @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
|
816 |
* 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
|
817 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
818 |
public int compare(Doc d1, Doc d2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
819 |
int result = compareStrings(d1.name(), d2.name()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
820 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
821 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
822 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
823 |
if (d1 instanceof ExecutableMemberDoc && d2 instanceof ExecutableMemberDoc) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
824 |
result = compareExecutableMembers( |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
825 |
(ExecutableMemberDoc) d1, |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
826 |
(ExecutableMemberDoc) d2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
827 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
828 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
829 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
830 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
831 |
if (d1 instanceof ProgramElementDoc && d2 instanceof ProgramElementDoc) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
832 |
return compareProgramElementDoc((ProgramElementDoc)d1, (ProgramElementDoc)d2); |
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 |
return 0; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
835 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
836 |
}; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
837 |
} |
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 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
840 |
* Comparator for ClassUse representations, this sorts on member names, |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
841 |
* fully qualified member names and then the parameter types if applicable. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
842 |
* @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
|
843 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
844 |
public static Comparator<Doc> makeComparatorForClassUse() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
845 |
return new Util.DocComparator<Doc>() { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
846 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
847 |
* compare two given Doc entities, first sort on name, and if |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
848 |
* applicable on the fully qualified name, and finally if applicable |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
849 |
* on the parameter types. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
850 |
* @param d1 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
851 |
* @param d2 - a Doc element. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
852 |
* @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
|
853 |
* 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
|
854 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
855 |
public int compare(Doc d1, Doc d2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
856 |
int result = compareStrings(d1.name(), d2.name()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
857 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
858 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
859 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
860 |
if (d1 instanceof ProgramElementDoc && d2 instanceof ProgramElementDoc) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
861 |
result = compareProgramElementDoc((ProgramElementDoc) d1, (ProgramElementDoc) d2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
862 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
863 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
864 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
865 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
866 |
if (d1 instanceof ExecutableMemberDoc && d2 instanceof ExecutableMemberDoc) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
867 |
return compareExecutableMembers((ExecutableMemberDoc)d1, (ExecutableMemberDoc)d2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
868 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
869 |
return 0; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
870 |
} |
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 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
873 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
874 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
875 |
* 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
|
876 |
* 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
|
877 |
* @param <T> a Doc entity |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
878 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
879 |
static abstract class DocComparator<T extends Doc> implements Comparator<Doc> { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
880 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
881 |
* compares two parameter arrays by first comparing the length of the arrays, and |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
882 |
* then each Type of the parameter in the array. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
883 |
* @param params1 the first parameter array. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
884 |
* @param params2 the first parameter array. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
885 |
* @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
|
886 |
* 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
|
887 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
888 |
protected int compareParameters(Parameter[] params1, Parameter[] params2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
889 |
if (params1.length == 0 && params2.length == 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
890 |
return 0; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
891 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
892 |
int result = Integer.compare(params1.length, params2.length); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
893 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
894 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
895 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
896 |
for (int i = 0; i < params1.length; i++) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
897 |
result = compareStrings(params1[i].typeName(), params2[i].typeName()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
898 |
if (result != 0) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
899 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
900 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
901 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
902 |
return 0; |
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 |
* Compares two MemberDocs, typically the name of a method, |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
907 |
* field or constructor. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
908 |
* @param e1 the first MemberDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
909 |
* @param e2 the second MemberDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
910 |
* @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
|
911 |
* 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
|
912 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
913 |
protected int compareMembers(MemberDoc e1, MemberDoc e2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
914 |
return compareStrings(e1.name(), e2.name()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
915 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
916 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
917 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
918 |
* Compares two ExecutableMemberDocs such as methods and constructors, |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
919 |
* as well as the parameters the entity might take. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
920 |
* @param m1 the first ExecutableMemberDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
921 |
* @param m2 the second ExecutableMemberDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
922 |
* @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
|
923 |
* 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
|
924 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
925 |
protected int compareExecutableMembers(ExecutableMemberDoc m1, ExecutableMemberDoc m2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
926 |
int result = compareMembers(m1, m2); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
927 |
if (result == 0) |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
928 |
result = compareParameters(m1.parameters(), m2.parameters()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
929 |
return result; |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
930 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
931 |
|
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
932 |
/** |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
933 |
* Compares the fully qualified names of the entities |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
934 |
* @param p1 the first ProgramElementDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
935 |
* @param p2 the first ProgramElementDoc. |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
936 |
* @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
|
937 |
* 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
|
938 |
*/ |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
939 |
protected int compareProgramElementDoc(ProgramElementDoc p1, ProgramElementDoc p2) { |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
940 |
return compareStrings(p1.qualifiedName(), p2.qualifiedName()); |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
941 |
} |
eb213562268d
8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents:
22165
diff
changeset
|
942 |
} |
10 | 943 |
} |