29 |
29 |
30 import javax.lang.model.element.Element; |
30 import javax.lang.model.element.Element; |
31 import javax.lang.model.element.PackageElement; |
31 import javax.lang.model.element.PackageElement; |
32 |
32 |
33 import jdk.javadoc.internal.doclets.toolkit.Configuration; |
33 import jdk.javadoc.internal.doclets.toolkit.Configuration; |
|
34 import jdk.javadoc.internal.doclets.toolkit.Messages; |
34 |
35 |
35 |
36 |
36 /** |
37 /** |
37 * Process and manage grouping of packages, as specified by "-group" option on |
38 * Process and manage grouping of packages, as specified by "-group" option on |
38 * the command line. |
39 * the command line. |
85 |
86 |
86 /** |
87 /** |
87 * The global configuration information for this run. |
88 * The global configuration information for this run. |
88 */ |
89 */ |
89 private final Configuration configuration; |
90 private final Configuration configuration; |
|
91 private Messages messages; |
90 |
92 |
91 /** |
93 /** |
92 * Since we need to sort the keys in the reverse order(longest key first), |
94 * Since we need to sort the keys in the reverse order(longest key first), |
93 * the compare method in the implementing class is doing the reverse |
95 * the compare method in the implementing class is doing the reverse |
94 * comparison. |
96 * comparison. |
99 } |
101 } |
100 } |
102 } |
101 |
103 |
102 public Group(Configuration configuration) { |
104 public Group(Configuration configuration) { |
103 this.configuration = configuration; |
105 this.configuration = configuration; |
|
106 messages = configuration.getMessages(); |
104 } |
107 } |
105 |
108 |
106 /** |
109 /** |
107 * Depending upon the format of the package name provided in the "-group" |
110 * Depending upon the format of the package name provided in the "-group" |
108 * option, generate two separate maps. There will be a map for mapping |
111 * option, generate two separate maps. There will be a map for mapping |
118 * @param pkgNameFormList List of the package name formats. |
121 * @param pkgNameFormList List of the package name formats. |
119 */ |
122 */ |
120 public boolean checkPackageGroups(String groupname, String pkgNameFormList) { |
123 public boolean checkPackageGroups(String groupname, String pkgNameFormList) { |
121 StringTokenizer strtok = new StringTokenizer(pkgNameFormList, ":"); |
124 StringTokenizer strtok = new StringTokenizer(pkgNameFormList, ":"); |
122 if (groupList.contains(groupname)) { |
125 if (groupList.contains(groupname)) { |
123 configuration.message.warning("doclet.Groupname_already_used", groupname); |
126 initMessages(); |
|
127 messages.warning("doclet.Groupname_already_used", groupname); |
124 return false; |
128 return false; |
125 } |
129 } |
126 groupList.add(groupname); |
130 groupList.add(groupname); |
127 while (strtok.hasMoreTokens()) { |
131 while (strtok.hasMoreTokens()) { |
128 String id = strtok.nextToken(); |
132 String id = strtok.nextToken(); |
129 if (id.length() == 0) { |
133 if (id.length() == 0) { |
130 configuration.message.warning("doclet.Error_in_packagelist", groupname, pkgNameFormList); |
134 initMessages(); |
|
135 messages.warning("doclet.Error_in_packagelist", groupname, pkgNameFormList); |
131 return false; |
136 return false; |
132 } |
137 } |
133 if (id.endsWith("*")) { |
138 if (id.endsWith("*")) { |
134 id = id.substring(0, id.length() - 1); |
139 id = id.substring(0, id.length() - 1); |
135 if (foundGroupFormat(regExpGroupMap, id)) { |
140 if (foundGroupFormat(regExpGroupMap, id)) { |
146 } |
151 } |
147 Collections.sort(sortedRegExpList, new MapKeyComparator()); |
152 Collections.sort(sortedRegExpList, new MapKeyComparator()); |
148 return true; |
153 return true; |
149 } |
154 } |
150 |
155 |
|
156 // Lazy init of the messages for now, because Group is created |
|
157 // in Configuration before configuration is fully initialized. |
|
158 private void initMessages() { |
|
159 if (messages == null) { |
|
160 messages = configuration.getMessages(); |
|
161 } |
|
162 } |
|
163 |
151 /** |
164 /** |
152 * Search if the given map has given the package format. |
165 * Search if the given map has given the package format. |
153 * |
166 * |
154 * @param map Map to be searched. |
167 * @param map Map to be searched. |
155 * @param pkgFormat The pacakge format to search. |
168 * @param pkgFormat The pacakge format to search. |
156 * |
169 * |
157 * @return true if package name format found in the map, else false. |
170 * @return true if package name format found in the map, else false. |
158 */ |
171 */ |
159 boolean foundGroupFormat(Map<String,?> map, String pkgFormat) { |
172 boolean foundGroupFormat(Map<String,?> map, String pkgFormat) { |
160 if (map.containsKey(pkgFormat)) { |
173 if (map.containsKey(pkgFormat)) { |
161 configuration.message.error("doclet.Same_package_name_used", pkgFormat); |
174 initMessages(); |
|
175 messages.error("doclet.Same_package_name_used", pkgFormat); |
162 return true; |
176 return true; |
163 } |
177 } |
164 return false; |
178 return false; |
165 } |
179 } |
166 |
180 |
179 */ |
193 */ |
180 public Map<String, SortedSet<PackageElement>> groupPackages(Set<PackageElement> packages) { |
194 public Map<String, SortedSet<PackageElement>> groupPackages(Set<PackageElement> packages) { |
181 Map<String, SortedSet<PackageElement>> groupPackageMap = new HashMap<>(); |
195 Map<String, SortedSet<PackageElement>> groupPackageMap = new HashMap<>(); |
182 String defaultGroupName = |
196 String defaultGroupName = |
183 (pkgNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())? |
197 (pkgNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())? |
184 configuration.message.getText("doclet.Packages") : |
198 configuration.getResources().getText("doclet.Packages") : |
185 configuration.message.getText("doclet.Other_Packages"); |
199 configuration.getResources().getText("doclet.Other_Packages"); |
186 // if the user has not used the default group name, add it |
200 // if the user has not used the default group name, add it |
187 if (!groupList.contains(defaultGroupName)) { |
201 if (!groupList.contains(defaultGroupName)) { |
188 groupList.add(defaultGroupName); |
202 groupList.add(defaultGroupName); |
189 } |
203 } |
190 for (PackageElement pkg : packages) { |
204 for (PackageElement pkg : packages) { |