author | ksrini |
Sun, 10 Apr 2016 08:41:00 -0700 | |
changeset 37009 | 476d8d615222 |
parent 35426 | 374342e56a56 |
child 37752 | 4243173b58db |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 1998, 2016, 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; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
31 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
32 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
33 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
34 |
import jdk.javadoc.doclet.DocletEnvironment; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.toolkit.Configuration; |
10 | 36 |
|
37 |
/** |
|
38 |
* Build the mapping of each Unicode character with it's member lists |
|
39 |
* containing members names starting with it. Also build a list for all the |
|
40 |
* Unicode characters which start a member name. Member name is |
|
41 |
* classkind or field or method or constructor name. |
|
42 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
43 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
44 |
* 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
|
45 |
* 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
|
46 |
* deletion without notice.</b> |
10 | 47 |
* |
48 |
* @see java.lang.Character |
|
49 |
* @author Atul M Dambalkar |
|
50 |
*/ |
|
51 |
public class IndexBuilder { |
|
52 |
||
53 |
/** |
|
54 |
* Mapping of each Unicode Character with the member list containing |
|
55 |
* members with names starting with it. |
|
56 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
57 |
private final Map<Character, SortedSet<Element>> indexmap; |
10 | 58 |
|
59 |
/** |
|
60 |
* Don't generate deprecated information if true. |
|
61 |
*/ |
|
62 |
private boolean noDeprecated; |
|
63 |
||
64 |
/** |
|
65 |
* Build this Index only for classes? |
|
66 |
*/ |
|
67 |
private boolean classesOnly; |
|
68 |
||
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
69 |
/** |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
70 |
* Indicates javafx mode. |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
71 |
*/ |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
72 |
private boolean javafx; |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
73 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
74 |
private final Configuration configuration; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
75 |
private final Utils utils; |
10 | 76 |
|
77 |
/** |
|
78 |
* Constructor. Build the index map. |
|
79 |
* |
|
80 |
* @param configuration the current configuration of the doclet. |
|
81 |
* @param noDeprecated true if -nodeprecated option is used, |
|
82 |
* false otherwise. |
|
83 |
*/ |
|
84 |
public IndexBuilder(Configuration configuration, boolean noDeprecated) { |
|
85 |
this(configuration, noDeprecated, false); |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Constructor. Build the index map. |
|
90 |
* |
|
91 |
* @param configuration the current configuration of the doclet. |
|
92 |
* @param noDeprecated true if -nodeprecated option is used, |
|
93 |
* false otherwise. |
|
94 |
* @param classesOnly Include only classes in index. |
|
95 |
*/ |
|
96 |
public IndexBuilder(Configuration configuration, boolean noDeprecated, |
|
97 |
boolean classesOnly) { |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
98 |
this.configuration = configuration; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
99 |
this.utils = configuration.utils; |
10 | 100 |
if (classesOnly) { |
101 |
configuration.message.notice("doclet.Building_Index_For_All_Classes"); |
|
102 |
} else { |
|
103 |
configuration.message.notice("doclet.Building_Index"); |
|
104 |
} |
|
105 |
this.noDeprecated = noDeprecated; |
|
106 |
this.classesOnly = classesOnly; |
|
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
107 |
this.javafx = configuration.javafx; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
108 |
this.indexmap = new TreeMap<>(); |
10 | 109 |
buildIndexMap(configuration.root); |
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Get all the members in all the Packages and all the Classes |
|
114 |
* given on the command line. Form separate list of those members depending |
|
115 |
* upon their names. |
|
116 |
* |
|
117 |
* @param root Root of the documemt. |
|
118 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
119 |
protected void buildIndexMap(DocletEnvironment root) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
120 |
Set<PackageElement> packages = utils.getSpecifiedPackages(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
121 |
Set<TypeElement> classes = root.getIncludedClasses(); |
10 | 122 |
if (!classesOnly) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
123 |
if (packages.isEmpty()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
124 |
Set<PackageElement> set = new HashSet<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
125 |
for (TypeElement aClass : classes) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
126 |
PackageElement pkg = utils.containingPackage(aClass); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
127 |
if (pkg != null && !pkg.isUnnamed()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
128 |
set.add(pkg); |
10 | 129 |
} |
130 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
131 |
adjustIndexMap(set); |
10 | 132 |
} else { |
133 |
adjustIndexMap(packages); |
|
134 |
} |
|
135 |
} |
|
136 |
adjustIndexMap(classes); |
|
137 |
if (!classesOnly) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
138 |
for (TypeElement aClass : classes) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
139 |
if (shouldAddToIndexMap(aClass)) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
140 |
putMembersInIndexMap(aClass); |
10 | 141 |
} |
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
147 |
* Put all the members(fields, methods and constructors) in the te |
10 | 148 |
* to the indexmap. |
149 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
150 |
* @param te TypeElement whose members will be added to the indexmap. |
10 | 151 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
152 |
protected void putMembersInIndexMap(TypeElement te) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
153 |
adjustIndexMap(utils.getAnnotationFields(te)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
154 |
adjustIndexMap(utils.getFields(te)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
155 |
adjustIndexMap(utils.getMethods(te)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
156 |
adjustIndexMap(utils.getConstructors(te)); |
10 | 157 |
} |
158 |
||
159 |
||
160 |
/** |
|
161 |
* Adjust list of members according to their names. Check the first |
|
162 |
* character in a member name, and then add the member to a list of members |
|
163 |
* for that particular unicode character. |
|
164 |
* |
|
165 |
* @param elements Array of members. |
|
166 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
167 |
protected void adjustIndexMap(Iterable<? extends Element> elements) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
168 |
for (Element element : elements) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
169 |
if (shouldAddToIndexMap(element)) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
170 |
String name = utils.isPackage(element) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
171 |
? utils.getPackageName((PackageElement)element) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
172 |
: utils.getSimpleName(element); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
173 |
char ch = (name.length() == 0) ? |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
174 |
'*' : |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
175 |
Character.toUpperCase(name.charAt(0)); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
176 |
Character unicode = ch; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
177 |
SortedSet<Element> list = indexmap.computeIfAbsent(unicode, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
178 |
c -> new TreeSet<>(utils.makeIndexUseComparator())); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
16319
diff
changeset
|
179 |
list.add(element); |
10 | 180 |
} |
181 |
} |
|
182 |
} |
|
183 |
||
184 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
185 |
* Should this element be added to the index map? |
10 | 186 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
187 |
protected boolean shouldAddToIndexMap(Element element) { |
37009
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
35426
diff
changeset
|
188 |
if (utils.isHidden(element)) { |
476d8d615222
8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents:
35426
diff
changeset
|
189 |
return false; |
16319
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
190 |
} |
e586bfeb39c5
7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents:
14260
diff
changeset
|
191 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
192 |
if (utils.isPackage(element)) |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
193 |
// 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
|
194 |
// package is marked as deprecated. |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
195 |
return !(noDeprecated && configuration.utils.isDeprecated(element)); |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
196 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
197 |
// 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
|
198 |
// 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
|
199 |
// deprecated. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
200 |
return !(noDeprecated && |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24297
diff
changeset
|
201 |
(configuration.utils.isDeprecated(element) || |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
202 |
configuration.utils.isDeprecated(utils.containingPackage(element)))); |
10 | 203 |
} |
204 |
||
205 |
/** |
|
206 |
* Return a map of all the individual member lists with Unicode character. |
|
207 |
* |
|
208 |
* @return Map index map. |
|
209 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
210 |
public Map<Character, SortedSet<Element>> getIndexMap() { |
10 | 211 |
return indexmap; |
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* Return the sorted list of members, for passed Unicode Character. |
|
216 |
* |
|
217 |
* @param index index Unicode character. |
|
218 |
* @return List member list for specific Unicode character. |
|
219 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
220 |
public List<? extends Element> getMemberList(Character index) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
221 |
SortedSet<Element> set = indexmap.get(index); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
222 |
if (set == null) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
223 |
return null; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
224 |
List<Element> out = new ArrayList<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
225 |
out.addAll(set); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
226 |
return out; |
10 | 227 |
} |
228 |
||
229 |
/** |
|
230 |
* Array of IndexMap keys, Unicode characters. |
|
231 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
232 |
public List<Character> index() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
233 |
return new ArrayList<>(indexmap.keySet()); |
10 | 234 |
} |
235 |
} |