author | ksrini |
Mon, 05 Jun 2017 13:45:34 -0700 | |
changeset 45417 | f7479ee8de69 |
parent 45157 | f5f796453339 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
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 |
||
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
30 |
import javax.lang.model.element.ModuleElement; |
35426
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 |
|
45417 | 33 |
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
40303 | 34 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
35 |
|
10 | 36 |
|
37 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
38 |
* Process and manage grouping of elements, as specified by "-group" option on |
10 | 39 |
* the command line. |
40 |
* <p> |
|
41 |
* For example, if user has used -group option as |
|
42 |
* -group "Core Packages" "java.*" -group "CORBA Packages" "org.omg.*", then |
|
43 |
* the packages specified on the command line will be grouped according to their |
|
44 |
* names starting with either "java." or "org.omg.". All the other packages |
|
45 |
* which do not fall in the user given groups, are grouped in default group, |
|
46 |
* named as either "Other Packages" or "Packages" depending upon if "-group" |
|
47 |
* option used or not at all used respectively. |
|
48 |
* </p> |
|
49 |
* <p> |
|
50 |
* Also the packages are grouped according to the longest possible match of |
|
51 |
* their names with the grouping information provided. For example, if there |
|
52 |
* are two groups, like -group "Lang" "java.lang" and -group "Core" "java.*", |
|
53 |
* will put the package java.lang in the group "Lang" and not in group "Core". |
|
54 |
* </p> |
|
55 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
56 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
57 |
* 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
|
58 |
* 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
|
59 |
* deletion without notice.</b> |
10 | 60 |
* |
61 |
* @author Atul M Dambalkar |
|
62 |
*/ |
|
63 |
public class Group { |
|
64 |
||
65 |
/** |
|
66 |
* Map of regular expressions with the corresponding group name. |
|
67 |
*/ |
|
22163 | 68 |
private Map<String,String> regExpGroupMap = new HashMap<>(); |
10 | 69 |
|
70 |
/** |
|
71 |
* List of regular expressions sorted according to the length. Regular |
|
72 |
* expression with longest length will be first in the sorted order. |
|
73 |
*/ |
|
22163 | 74 |
private List<String> sortedRegExpList = new ArrayList<>(); |
10 | 75 |
|
76 |
/** |
|
77 |
* List of group names in the same order as given on the command line. |
|
78 |
*/ |
|
22163 | 79 |
private List<String> groupList = new ArrayList<>(); |
10 | 80 |
|
81 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
82 |
* Map of non-regular expressions(possible package or module names) with the |
10 | 83 |
* corresponding group name. |
84 |
*/ |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
85 |
private Map<String,String> elementNameGroupMap = new HashMap<>(); |
10 | 86 |
|
87 |
/** |
|
88 |
* The global configuration information for this run. |
|
89 |
*/ |
|
45417 | 90 |
private final BaseConfiguration configuration; |
40303 | 91 |
private Messages messages; |
10 | 92 |
|
93 |
/** |
|
94 |
* Since we need to sort the keys in the reverse order(longest key first), |
|
95 |
* the compare method in the implementing class is doing the reverse |
|
96 |
* comparison. |
|
97 |
*/ |
|
868 | 98 |
private static class MapKeyComparator implements Comparator<String> { |
99 |
public int compare(String key1, String key2) { |
|
100 |
return key2.length() - key1.length(); |
|
10 | 101 |
} |
102 |
} |
|
103 |
||
45417 | 104 |
public Group(BaseConfiguration configuration) { |
10 | 105 |
this.configuration = configuration; |
40303 | 106 |
messages = configuration.getMessages(); |
10 | 107 |
} |
108 |
||
109 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
110 |
* Depending upon the format of the module name provided in the "-group" |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
111 |
* option, generate two separate maps. There will be a map for mapping |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
112 |
* regular expression(only meta character allowed is '*' and that is at the |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
113 |
* end of the regular expression) on to the group name. And another map |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
114 |
* for mapping (possible) module names(if the name format doesn't contain |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
115 |
* meta character '*', then it is assumed to be a module name) on to the |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
116 |
* group name. This will also sort all the regular expressions found in the |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
117 |
* reverse order of their lengths, i.e. longest regular expression will be |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
118 |
* first in the sorted list. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
119 |
* |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
120 |
* @param groupname The name of the group from -group option. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
121 |
* @param moduleNameFormList List of the module name formats. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
122 |
*/ |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
123 |
public boolean checkModuleGroups(String groupname, String moduleNameFormList) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
124 |
String[] mdlPatterns = moduleNameFormList.split(":"); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
125 |
if (groupList.contains(groupname)) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
126 |
initMessages(); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
127 |
messages.warning("doclet.Groupname_already_used", groupname); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
128 |
return false; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
129 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
130 |
groupList.add(groupname); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
131 |
for (String mdlPattern : mdlPatterns) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
132 |
if (mdlPattern.length() == 0) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
133 |
initMessages(); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
134 |
messages.warning("doclet.Error_in_grouplist", groupname, moduleNameFormList); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
135 |
return false; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
136 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
137 |
if (mdlPattern.endsWith("*")) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
138 |
mdlPattern = mdlPattern.substring(0, mdlPattern.length() - 1); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
139 |
if (foundGroupFormat(regExpGroupMap, mdlPattern)) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
140 |
return false; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
141 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
142 |
regExpGroupMap.put(mdlPattern, groupname); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
143 |
sortedRegExpList.add(mdlPattern); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
144 |
} else { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
145 |
if (foundGroupFormat(elementNameGroupMap, mdlPattern)) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
146 |
return false; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
147 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
148 |
elementNameGroupMap.put(mdlPattern, groupname); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
149 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
150 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
151 |
Collections.sort(sortedRegExpList, new MapKeyComparator()); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
152 |
return true; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
153 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
154 |
|
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
155 |
/** |
10 | 156 |
* Depending upon the format of the package name provided in the "-group" |
157 |
* option, generate two separate maps. There will be a map for mapping |
|
158 |
* regular expression(only meta character allowed is '*' and that is at the |
|
159 |
* end of the regular expression) on to the group name. And another map |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
160 |
* for mapping (possible) package names(if the name format doesn't contain |
10 | 161 |
* meta character '*', then it is assumed to be a package name) on to the |
162 |
* group name. This will also sort all the regular expressions found in the |
|
163 |
* reverse order of their lengths, i.e. longest regular expression will be |
|
164 |
* first in the sorted list. |
|
165 |
* |
|
166 |
* @param groupname The name of the group from -group option. |
|
167 |
* @param pkgNameFormList List of the package name formats. |
|
168 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
169 |
public boolean checkPackageGroups(String groupname, String pkgNameFormList) { |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
170 |
String[] pkgPatterns = pkgNameFormList.split(":"); |
10 | 171 |
if (groupList.contains(groupname)) { |
40303 | 172 |
initMessages(); |
173 |
messages.warning("doclet.Groupname_already_used", groupname); |
|
10 | 174 |
return false; |
175 |
} |
|
176 |
groupList.add(groupname); |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
177 |
for (String pkgPattern : pkgPatterns) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
178 |
if (pkgPattern.length() == 0) { |
40303 | 179 |
initMessages(); |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
180 |
messages.warning("doclet.Error_in_grouplist", groupname, pkgNameFormList); |
10 | 181 |
return false; |
182 |
} |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
183 |
if (pkgPattern.endsWith("*")) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
184 |
pkgPattern = pkgPattern.substring(0, pkgPattern.length() - 1); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
185 |
if (foundGroupFormat(regExpGroupMap, pkgPattern)) { |
10 | 186 |
return false; |
187 |
} |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
188 |
regExpGroupMap.put(pkgPattern, groupname); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
189 |
sortedRegExpList.add(pkgPattern); |
10 | 190 |
} else { |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
191 |
if (foundGroupFormat(elementNameGroupMap, pkgPattern)) { |
10 | 192 |
return false; |
193 |
} |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
194 |
elementNameGroupMap.put(pkgPattern, groupname); |
10 | 195 |
} |
196 |
} |
|
197 |
Collections.sort(sortedRegExpList, new MapKeyComparator()); |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
40303 | 201 |
// Lazy init of the messages for now, because Group is created |
45417 | 202 |
// in BaseConfiguration before configuration is fully initialized. |
40303 | 203 |
private void initMessages() { |
204 |
if (messages == null) { |
|
205 |
messages = configuration.getMessages(); |
|
206 |
} |
|
207 |
} |
|
208 |
||
10 | 209 |
/** |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
210 |
* Search if the given map has the given element format. |
10 | 211 |
* |
212 |
* @param map Map to be searched. |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
213 |
* @param elementFormat The format to search. |
10 | 214 |
* |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
215 |
* @return true if element name format found in the map, else false. |
10 | 216 |
*/ |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
217 |
boolean foundGroupFormat(Map<String,?> map, String elementFormat) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
218 |
if (map.containsKey(elementFormat)) { |
40303 | 219 |
initMessages(); |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
220 |
messages.error("doclet.Same_element_name_used", elementFormat); |
10 | 221 |
return true; |
222 |
} |
|
223 |
return false; |
|
224 |
} |
|
225 |
||
226 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
227 |
* Group the modules according the grouping information provided on the |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
228 |
* command line. Given a list of modules, search each module name in |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
229 |
* regular expression map as well as module name map to get the |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
230 |
* corresponding group name. Create another map with mapping of group name |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
231 |
* to the module list, which will fall under the specified group. If any |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
232 |
* module doesn't belong to any specified group on the command line, then |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
233 |
* a new group named "Other Modules" will be created for it. If there are |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
234 |
* no groups found, in other words if "-group" option is not at all used, |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
235 |
* then all the modules will be grouped under group "Modules". |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
236 |
* |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
237 |
* @param modules Specified modules. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
238 |
* @return map of group names and set of module elements. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
239 |
*/ |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
240 |
public Map<String, SortedSet<ModuleElement>> groupModules(Set<ModuleElement> modules) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
241 |
Map<String, SortedSet<ModuleElement>> groupModuleMap = new HashMap<>(); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
242 |
String defaultGroupName = |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
243 |
(elementNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())? |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
244 |
configuration.getResources().getText("doclet.Modules") : |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
245 |
configuration.getResources().getText("doclet.Other_Modules"); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
246 |
// if the user has not used the default group name, add it |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
247 |
if (!groupList.contains(defaultGroupName)) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
248 |
groupList.add(defaultGroupName); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
249 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
250 |
for (ModuleElement mdl : modules) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
251 |
String moduleName = mdl.isUnnamed() ? null : mdl.getQualifiedName().toString(); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
252 |
String groupName = mdl.isUnnamed() ? null : elementNameGroupMap.get(moduleName); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
253 |
// if this module is not explicitly assigned to a group, |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
254 |
// try matching it to group specified by regular expression |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
255 |
if (groupName == null) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
256 |
groupName = regExpGroupName(moduleName); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
257 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
258 |
// if it is in neither group map, put it in the default |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
259 |
// group |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
260 |
if (groupName == null) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
261 |
groupName = defaultGroupName; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
262 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
263 |
getModuleList(groupModuleMap, groupName).add(mdl); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
264 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
265 |
return groupModuleMap; |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
266 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
267 |
|
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
268 |
/** |
10 | 269 |
* Group the packages according the grouping information provided on the |
270 |
* command line. Given a list of packages, search each package name in |
|
271 |
* regular expression map as well as package name map to get the |
|
272 |
* corresponding group name. Create another map with mapping of group name |
|
273 |
* to the package list, which will fall under the specified group. If any |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
274 |
* package doesn't belong to any specified group on the command line, then |
10 | 275 |
* a new group named "Other Packages" will be created for it. If there are |
276 |
* no groups found, in other words if "-group" option is not at all used, |
|
277 |
* then all the packages will be grouped under group "Packages". |
|
278 |
* |
|
279 |
* @param packages Packages specified on the command line. |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
280 |
* @return map of group names and set of package elements |
10 | 281 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
282 |
public Map<String, SortedSet<PackageElement>> groupPackages(Set<PackageElement> packages) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
283 |
Map<String, SortedSet<PackageElement>> groupPackageMap = new HashMap<>(); |
10 | 284 |
String defaultGroupName = |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
285 |
(elementNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())? |
40303 | 286 |
configuration.getResources().getText("doclet.Packages") : |
287 |
configuration.getResources().getText("doclet.Other_Packages"); |
|
10 | 288 |
// if the user has not used the default group name, add it |
289 |
if (!groupList.contains(defaultGroupName)) { |
|
290 |
groupList.add(defaultGroupName); |
|
291 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
292 |
for (PackageElement pkg : packages) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
293 |
String pkgName = pkg.isUnnamed() ? null : configuration.utils.getPackageName(pkg); |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
294 |
String groupName = pkg.isUnnamed() ? null : elementNameGroupMap.get(pkgName); |
10 | 295 |
// if this package is not explicitly assigned to a group, |
296 |
// try matching it to group specified by regular expression |
|
297 |
if (groupName == null) { |
|
298 |
groupName = regExpGroupName(pkgName); |
|
299 |
} |
|
300 |
// if it is in neither group map, put it in the default |
|
301 |
// group |
|
302 |
if (groupName == null) { |
|
303 |
groupName = defaultGroupName; |
|
304 |
} |
|
305 |
getPkgList(groupPackageMap, groupName).add(pkg); |
|
306 |
} |
|
307 |
return groupPackageMap; |
|
308 |
} |
|
309 |
||
310 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
311 |
* Search for element name in the sorted regular expression |
10 | 312 |
* list, if found return the group name. If not, return null. |
313 |
* |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
314 |
* @param elementName Name of element to be found in the regular |
10 | 315 |
* expression list. |
316 |
*/ |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
317 |
String regExpGroupName(String elementName) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
318 |
for (String regexp : sortedRegExpList) { |
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
319 |
if (elementName.startsWith(regexp)) { |
868 | 320 |
return regExpGroupMap.get(regexp); |
10 | 321 |
} |
322 |
} |
|
323 |
return null; |
|
324 |
} |
|
325 |
||
326 |
/** |
|
327 |
* For the given group name, return the package list, on which it is mapped. |
|
328 |
* Create a new list, if not found. |
|
329 |
* |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
330 |
* @param map Map to be searched for group name. |
10 | 331 |
* @param groupname Group name to search. |
332 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
333 |
SortedSet<PackageElement> getPkgList(Map<String, SortedSet<PackageElement>> map, |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
334 |
String groupname) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
335 |
return map.computeIfAbsent(groupname, g -> new TreeSet<>(configuration.utils.makePackageComparator())); |
10 | 336 |
} |
337 |
||
338 |
/** |
|
45157
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
339 |
* For the given group name, return the module list, on which it is mapped. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
340 |
* Create a new list, if not found. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
341 |
* |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
342 |
* @param map Map to be searched for group name. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
343 |
* @param groupname Group name to search. |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
344 |
*/ |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
345 |
SortedSet<ModuleElement> getModuleList(Map<String, SortedSet<ModuleElement>> map, |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
346 |
String groupname) { |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
347 |
return map.computeIfAbsent(groupname, g -> new TreeSet<>(configuration.utils.makeModuleComparator())); |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
348 |
} |
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
349 |
|
f5f796453339
8178043: Support grouping modules in unified javadoc
bpatel
parents:
40303
diff
changeset
|
350 |
/** |
10 | 351 |
* Return the list of groups, in the same order as specified |
352 |
* on the command line. |
|
353 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1475
diff
changeset
|
354 |
public List<String> getGroupList() { |
10 | 355 |
return groupList; |
356 |
} |
|
357 |
} |