author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2001, 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 |
||
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
28 |
import java.util.*; |
10 | 29 |
import com.sun.javadoc.*; |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
30 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
10 | 31 |
|
32 |
/** |
|
33 |
* This class acts as an artificial PackageDoc for classes specified |
|
34 |
* on the command line when running Javadoc. For example, if you |
|
35 |
* specify several classes from package java.lang, this class will catalog |
|
36 |
* those classes so that we can retrieve all of the classes from a particular |
|
37 |
* package later. |
|
38 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
40 |
* 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:
14259
diff
changeset
|
41 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
42 |
* deletion without notice.</b> |
10 | 43 |
* |
44 |
* @author Jamie Ho |
|
45 |
* @since 1.4 |
|
46 |
*/ |
|
47 |
||
48 |
public class ClassDocCatalog { |
|
49 |
||
50 |
/** |
|
51 |
* Stores the set of packages that the classes specified on the command line |
|
52 |
* belong to. Note that the default package is "". |
|
53 |
*/ |
|
868 | 54 |
private Set<String> packageSet; |
10 | 55 |
|
56 |
||
57 |
/** |
|
58 |
* Stores all classes for each package |
|
59 |
*/ |
|
868 | 60 |
private Map<String,Set<ClassDoc>> allClasses; |
10 | 61 |
|
62 |
/** |
|
63 |
* Stores ordinary classes (excluding Exceptions and Errors) for each |
|
64 |
* package |
|
65 |
*/ |
|
868 | 66 |
private Map<String,Set<ClassDoc>> ordinaryClasses; |
10 | 67 |
|
68 |
/** |
|
69 |
* Stores exceptions for each package |
|
70 |
*/ |
|
868 | 71 |
private Map<String,Set<ClassDoc>> exceptions; |
10 | 72 |
|
73 |
/** |
|
74 |
* Stores enums for each package. |
|
75 |
*/ |
|
868 | 76 |
private Map<String,Set<ClassDoc>> enums; |
10 | 77 |
|
78 |
/** |
|
79 |
* Stores annotation types for each package. |
|
80 |
*/ |
|
868 | 81 |
private Map<String,Set<ClassDoc>> annotationTypes; |
10 | 82 |
|
83 |
/** |
|
84 |
* Stores errors for each package |
|
85 |
*/ |
|
868 | 86 |
private Map<String,Set<ClassDoc>> errors; |
10 | 87 |
|
88 |
/** |
|
89 |
* Stores interfaces for each package |
|
90 |
*/ |
|
868 | 91 |
private Map<String,Set<ClassDoc>> interfaces; |
10 | 92 |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
93 |
private Configuration configuration; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
94 |
private Utils utils; |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
95 |
|
10 | 96 |
/** |
97 |
* Construct a new ClassDocCatalog. |
|
98 |
* |
|
99 |
* @param classdocs the array of ClassDocs to catalog |
|
100 |
*/ |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
101 |
public ClassDocCatalog (ClassDoc[] classdocs, Configuration config) { |
10 | 102 |
init(); |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
103 |
this.configuration = config; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
104 |
this.utils = config.utils; |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
105 |
for (ClassDoc classdoc : classdocs) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
106 |
addClassDoc(classdoc); |
10 | 107 |
} |
108 |
} |
|
109 |
||
110 |
/** |
|
111 |
* Construct a new ClassDocCatalog. |
|
112 |
* |
|
113 |
*/ |
|
114 |
public ClassDocCatalog () { |
|
115 |
init(); |
|
116 |
} |
|
117 |
||
118 |
private void init() { |
|
22163 | 119 |
allClasses = new HashMap<>(); |
120 |
ordinaryClasses = new HashMap<>(); |
|
121 |
exceptions = new HashMap<>(); |
|
122 |
enums = new HashMap<>(); |
|
123 |
annotationTypes = new HashMap<>(); |
|
124 |
errors = new HashMap<>(); |
|
125 |
interfaces = new HashMap<>(); |
|
126 |
packageSet = new HashSet<>(); |
|
10 | 127 |
} |
128 |
||
129 |
/** |
|
130 |
* Add the given class to the catalog. |
|
131 |
* @param classdoc the ClassDoc to add to the catelog. |
|
132 |
*/ |
|
133 |
public void addClassDoc(ClassDoc classdoc) { |
|
134 |
if (classdoc == null) { |
|
135 |
return; |
|
136 |
} |
|
137 |
addClass(classdoc, allClasses); |
|
138 |
if (classdoc.isOrdinaryClass()) { |
|
139 |
addClass(classdoc, ordinaryClasses); |
|
140 |
} else if (classdoc.isException()) { |
|
141 |
addClass(classdoc, exceptions); |
|
142 |
} else if (classdoc.isEnum()) { |
|
143 |
addClass(classdoc, enums); |
|
144 |
} else if (classdoc.isAnnotationType()) { |
|
145 |
addClass(classdoc, annotationTypes); |
|
146 |
} else if (classdoc.isError()) { |
|
147 |
addClass(classdoc, errors); |
|
148 |
} else if (classdoc.isInterface()) { |
|
149 |
addClass(classdoc, interfaces); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Add the given class to the given map. |
|
155 |
* @param classdoc the ClassDoc to add to the catelog. |
|
156 |
* @param map the Map to add the ClassDoc to. |
|
157 |
*/ |
|
868 | 158 |
private void addClass(ClassDoc classdoc, Map<String,Set<ClassDoc>> map) { |
10 | 159 |
|
160 |
PackageDoc pkg = classdoc.containingPackage(); |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
161 |
if (pkg.isIncluded() || (configuration.nodeprecated && utils.isDeprecated(pkg))) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
162 |
//No need to catalog this class if it's package is |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
163 |
//included on the command line or if -nodeprecated option is set |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
164 |
// and the containing package is marked as deprecated. |
10 | 165 |
return; |
166 |
} |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
167 |
String key = utils.getPackageName(pkg); |
868 | 168 |
Set<ClassDoc> s = map.get(key); |
10 | 169 |
if (s == null) { |
170 |
packageSet.add(key); |
|
22163 | 171 |
s = new HashSet<>(); |
10 | 172 |
} |
173 |
s.add(classdoc); |
|
174 |
map.put(key, s); |
|
175 |
||
176 |
} |
|
177 |
||
868 | 178 |
private ClassDoc[] getArray(Map<String,Set<ClassDoc>> m, String key) { |
179 |
Set<ClassDoc> s = m.get(key); |
|
10 | 180 |
if (s == null) { |
181 |
return new ClassDoc[] {}; |
|
182 |
} else { |
|
868 | 183 |
return s.toArray(new ClassDoc[] {}); |
10 | 184 |
} |
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* Return all of the classes specified on the command-line that |
|
189 |
* belong to the given package. |
|
14259 | 190 |
* @param pkgDoc the package to return the classes for. |
10 | 191 |
*/ |
192 |
public ClassDoc[] allClasses(PackageDoc pkgDoc) { |
|
193 |
return pkgDoc.isIncluded() ? |
|
194 |
pkgDoc.allClasses() : |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
195 |
getArray(allClasses, utils.getPackageName(pkgDoc)); |
10 | 196 |
} |
197 |
||
198 |
/** |
|
199 |
* Return all of the classes specified on the command-line that |
|
200 |
* belong to the given package. |
|
201 |
* @param packageName the name of the package specified on the |
|
202 |
* command-line. |
|
203 |
*/ |
|
204 |
public ClassDoc[] allClasses(String packageName) { |
|
205 |
return getArray(allClasses, packageName); |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Return the array of package names that this catalog stores |
|
210 |
* ClassDocs for. |
|
211 |
*/ |
|
212 |
public String[] packageNames() { |
|
868 | 213 |
return packageSet.toArray(new String[] {}); |
10 | 214 |
} |
215 |
||
216 |
/** |
|
217 |
* Return true if the given package is known to this catalog. |
|
218 |
* @param packageName the name to check. |
|
219 |
* @return true if this catalog has any information about |
|
220 |
* classes in the given package. |
|
221 |
*/ |
|
222 |
public boolean isKnownPackage(String packageName) { |
|
223 |
return packageSet.contains(packageName); |
|
224 |
} |
|
225 |
||
226 |
||
227 |
/** |
|
228 |
* Return all of the errors specified on the command-line |
|
229 |
* that belong to the given package. |
|
230 |
* @param packageName the name of the package specified on the |
|
231 |
* command-line. |
|
232 |
*/ |
|
233 |
public ClassDoc[] errors(String packageName) { |
|
234 |
return getArray(errors, packageName); |
|
235 |
} |
|
236 |
||
237 |
/** |
|
238 |
* Return all of the exceptions specified on the command-line |
|
239 |
* that belong to the given package. |
|
240 |
* @param packageName the name of the package specified on the |
|
241 |
* command-line. |
|
242 |
*/ |
|
243 |
public ClassDoc[] exceptions(String packageName) { |
|
244 |
return getArray(exceptions, packageName); |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* Return all of the enums specified on the command-line |
|
249 |
* that belong to the given package. |
|
250 |
* @param packageName the name of the package specified on the |
|
251 |
* command-line. |
|
252 |
*/ |
|
253 |
public ClassDoc[] enums(String packageName) { |
|
254 |
return getArray(enums, packageName); |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Return all of the annotation types specified on the command-line |
|
259 |
* that belong to the given package. |
|
260 |
* @param packageName the name of the package specified on the |
|
261 |
* command-line. |
|
262 |
*/ |
|
263 |
public ClassDoc[] annotationTypes(String packageName) { |
|
264 |
return getArray(annotationTypes, packageName); |
|
265 |
} |
|
266 |
||
267 |
/** |
|
268 |
* Return all of the interfaces specified on the command-line |
|
269 |
* that belong to the given package. |
|
270 |
* @param packageName the name of the package specified on the |
|
271 |
* command-line. |
|
272 |
*/ |
|
273 |
public ClassDoc[] interfaces(String packageName) { |
|
274 |
return getArray(interfaces, packageName); |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Return all of the ordinary classes specified on the command-line |
|
279 |
* that belong to the given package. |
|
280 |
* @param packageName the name of the package specified on the |
|
281 |
* command-line. |
|
282 |
*/ |
|
283 |
public ClassDoc[] ordinaryClasses(String packageName) { |
|
284 |
return getArray(ordinaryClasses, packageName); |
|
285 |
} |
|
286 |
} |