author | ksrini |
Thu, 07 Dec 2017 14:15:14 -0800 | |
changeset 48213 | 59696a3595bd |
parent 47395 | 2ea4edfdef8e |
child 49879 | 601277b1d582 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45417 | 2 |
* Copyright (c) 1998, 2017, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.util; |
10 | 27 |
|
14258 | 28 |
import java.util.*; |
29 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
30 |
import javax.lang.model.element.Element; |
40511 | 31 |
import javax.lang.model.element.ModuleElement; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
32 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
33 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
34 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
35 |
import jdk.javadoc.doclet.DocletEnvironment; |
45417 | 36 |
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
40303 | 37 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
47395
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.Kind; |
10 | 39 |
|
40 |
/** |
|
41 |
* Build the mapping of each Unicode character with it's member lists |
|
42 |
* containing members names starting with it. Also build a list for all the |
|
43 |
* Unicode characters which start a member name. Member name is |
|
44 |
* classkind or field or method or constructor name. |
|
45 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
46 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
47 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
48 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
49 |
* deletion without notice.</b> |
10 | 50 |
* |
51 |
* @see java.lang.Character |
|
52 |
* @author Atul M Dambalkar |
|
53 |
*/ |
|
54 |
public class IndexBuilder { |
|
55 |
||
56 |
/** |
|
57 |
* Mapping of each Unicode Character with the member list containing |
|
58 |
* members with names starting with it. |
|
59 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
60 |
private final Map<Character, SortedSet<Element>> indexmap; |
10 | 61 |
|
62 |
/** |
|
63 |
* Don't generate deprecated information if true. |
|
64 |
*/ |
|
65 |
private boolean noDeprecated; |
|
66 |
||
67 |
/** |
|
68 |
* Build this Index only for classes? |
|
69 |
*/ |
|
70 |
private boolean classesOnly; |
|
71 |
||
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
72 |
/** |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
73 |
* Indicates javafx mode. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
74 |
*/ |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
75 |
private boolean javafx; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
76 |
|
45417 | 77 |
private final BaseConfiguration configuration; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
78 |
private final Utils utils; |
37752
4243173b58db
8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents:
37009
diff
changeset
|
79 |
private final Comparator<Element> comparator; |
10 | 80 |
|
81 |
/** |
|
82 |
* Constructor. Build the index map. |
|
83 |
* |
|
84 |
* @param configuration the current configuration of the doclet. |
|
85 |
* @param noDeprecated true if -nodeprecated option is used, |
|
86 |
* false otherwise. |
|
87 |
*/ |
|
45417 | 88 |
public IndexBuilder(BaseConfiguration configuration, boolean noDeprecated) { |
10 | 89 |
this(configuration, noDeprecated, false); |
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Constructor. Build the index map. |
|
94 |
* |
|
95 |
* @param configuration the current configuration of the doclet. |
|
96 |
* @param noDeprecated true if -nodeprecated option is used, |
|
97 |
* false otherwise. |
|
98 |
* @param classesOnly Include only classes in index. |
|
99 |
*/ |
|
45417 | 100 |
public IndexBuilder(BaseConfiguration configuration, boolean noDeprecated, |
10 | 101 |
boolean classesOnly) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
102 |
this.configuration = configuration; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
103 |
this.utils = configuration.utils; |
40303 | 104 |
|
105 |
Messages messages = configuration.getMessages(); |
|
10 | 106 |
if (classesOnly) { |
40303 | 107 |
messages.notice("doclet.Building_Index_For_All_Classes"); |
10 | 108 |
} else { |
40303 | 109 |
messages.notice("doclet.Building_Index"); |
10 | 110 |
} |
40303 | 111 |
|
10 | 112 |
this.noDeprecated = noDeprecated; |
113 |
this.classesOnly = classesOnly; |
|
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
114 |
this.javafx = configuration.javafx; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
115 |
this.indexmap = new TreeMap<>(); |
37752
4243173b58db
8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents:
37009
diff
changeset
|
116 |
comparator = classesOnly |
4243173b58db
8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents:
37009
diff
changeset
|
117 |
? utils.makeAllClassesComparator() |
4243173b58db
8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents:
37009
diff
changeset
|
118 |
: utils.makeIndexUseComparator(); |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
37752
diff
changeset
|
119 |
buildIndexMap(configuration.docEnv); |
10 | 120 |
} |
121 |
||
122 |
/** |
|
123 |
* Get all the members in all the Packages and all the Classes |
|
124 |
* given on the command line. Form separate list of those members depending |
|
125 |
* upon their names. |
|
126 |
* |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40303
diff
changeset
|
127 |
* @param docEnv the doclet environment |
10 | 128 |
*/ |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40303
diff
changeset
|
129 |
protected void buildIndexMap(DocletEnvironment docEnv) { |
42277 | 130 |
Set<PackageElement> packages = configuration.getSpecifiedPackageElements(); |
131 |
Set<TypeElement> classes = configuration.getIncludedTypeElements(); |
|
10 | 132 |
if (!classesOnly) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
133 |
if (packages.isEmpty()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
134 |
Set<PackageElement> set = new HashSet<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
135 |
for (TypeElement aClass : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
136 |
PackageElement pkg = utils.containingPackage(aClass); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
137 |
if (pkg != null && !pkg.isUnnamed()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
138 |
set.add(pkg); |
10 | 139 |
} |
140 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
141 |
adjustIndexMap(set); |
10 | 142 |
} else { |
143 |
adjustIndexMap(packages); |
|
144 |
} |
|
145 |
} |
|
146 |
adjustIndexMap(classes); |
|
147 |
if (!classesOnly) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
148 |
for (TypeElement aClass : classes) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
149 |
if (shouldAddToIndexMap(aClass)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
150 |
putMembersInIndexMap(aClass); |
10 | 151 |
} |
152 |
} |
|
40511 | 153 |
if (configuration.showModules) { |
154 |
addModulesToIndexMap(); |
|
155 |
} |
|
10 | 156 |
} |
157 |
} |
|
158 |
||
159 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
160 |
* Put all the members(fields, methods and constructors) in the te |
10 | 161 |
* to the indexmap. |
162 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
163 |
* @param te TypeElement whose members will be added to the indexmap. |
10 | 164 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
165 |
protected void putMembersInIndexMap(TypeElement te) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
166 |
adjustIndexMap(utils.getAnnotationFields(te)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
167 |
adjustIndexMap(utils.getFields(te)); |
47395
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
168 |
VisibleMemberMap vmm = configuration.getVisibleMemberMap(te, Kind.METHODS); |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
169 |
adjustIndexMap(vmm.getMembers(te)); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
170 |
adjustIndexMap(utils.getConstructors(te)); |
42263 | 171 |
adjustIndexMap(utils.getEnumConstants(te)); |
10 | 172 |
} |
173 |
||
174 |
||
175 |
/** |
|
176 |
* Adjust list of members according to their names. Check the first |
|
177 |
* character in a member name, and then add the member to a list of members |
|
178 |
* for that particular unicode character. |
|
179 |
* |
|
180 |
* @param elements Array of members. |
|
181 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
182 |
protected void adjustIndexMap(Iterable<? extends Element> elements) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
183 |
for (Element element : elements) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
184 |
if (shouldAddToIndexMap(element)) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
185 |
String name = utils.isPackage(element) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
186 |
? utils.getPackageName((PackageElement)element) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
187 |
: utils.getSimpleName(element); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
188 |
char ch = (name.length() == 0) ? |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
189 |
'*' : |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
190 |
Character.toUpperCase(name.charAt(0)); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
191 |
Character unicode = ch; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
192 |
SortedSet<Element> list = indexmap.computeIfAbsent(unicode, |
37752
4243173b58db
8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents:
37009
diff
changeset
|
193 |
c -> new TreeSet<>(comparator)); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
194 |
list.add(element); |
10 | 195 |
} |
196 |
} |
|
197 |
} |
|
198 |
||
199 |
/** |
|
40511 | 200 |
* Add all the modules to index map. |
201 |
*/ |
|
202 |
protected void addModulesToIndexMap() { |
|
203 |
for (ModuleElement mdle : configuration.modules) { |
|
45771
e447c20c3ff9
8182736: javadoc generates bad names and broken module graph links
jjg
parents:
42277
diff
changeset
|
204 |
String mdleName = mdle.getQualifiedName().toString(); |
40511 | 205 |
char ch = (mdleName.length() == 0) |
206 |
? '*' |
|
207 |
: Character.toUpperCase(mdleName.charAt(0)); |
|
208 |
Character unicode = ch; |
|
209 |
SortedSet<Element> list = indexmap.computeIfAbsent(unicode, |
|
210 |
c -> new TreeSet<>(comparator)); |
|
211 |
list.add(mdle); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
216 |
* Should this element be added to the index map? |
10 | 217 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
218 |
protected boolean shouldAddToIndexMap(Element element) { |
37009
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
35426
diff
changeset
|
219 |
if (utils.isHidden(element)) { |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
35426
diff
changeset
|
220 |
return false; |
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
221 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
222 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
223 |
if (utils.isPackage(element)) |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
224 |
// Do not add to index map if -nodeprecated option is set and the |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
225 |
// package is marked as deprecated. |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
226 |
return !(noDeprecated && configuration.utils.isDeprecated(element)); |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
227 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
228 |
// Do not add to index map if -nodeprecated option is set and if the |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
229 |
// element is marked as deprecated or the containing package is marked as |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
230 |
// deprecated. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
231 |
return !(noDeprecated && |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
232 |
(configuration.utils.isDeprecated(element) || |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
233 |
configuration.utils.isDeprecated(utils.containingPackage(element)))); |
10 | 234 |
} |
235 |
||
236 |
/** |
|
237 |
* Return a map of all the individual member lists with Unicode character. |
|
238 |
* |
|
239 |
* @return Map index map. |
|
240 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
241 |
public Map<Character, SortedSet<Element>> getIndexMap() { |
10 | 242 |
return indexmap; |
243 |
} |
|
244 |
||
245 |
/** |
|
246 |
* Return the sorted list of members, for passed Unicode Character. |
|
247 |
* |
|
248 |
* @param index index Unicode character. |
|
249 |
* @return List member list for specific Unicode character. |
|
250 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
251 |
public List<? extends Element> getMemberList(Character index) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
252 |
SortedSet<Element> set = indexmap.get(index); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
253 |
if (set == null) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
254 |
return null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
255 |
List<Element> out = new ArrayList<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
256 |
out.addAll(set); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
257 |
return out; |
10 | 258 |
} |
259 |
||
260 |
/** |
|
261 |
* Array of IndexMap keys, Unicode characters. |
|
262 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
263 |
public List<Character> index() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
264 |
return new ArrayList<>(indexmap.keySet()); |
10 | 265 |
} |
266 |
} |