author | mcimadamore |
Fri, 16 Dec 2016 15:27:34 +0000 | |
changeset 42827 | 36468b5fa7f4 |
parent 42277 | 2668b0bc7ad7 |
child 43261 | d377e97291d8 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
2 |
* Copyright (c) 2003, 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:
26269
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
27 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
28 |
import java.util.SortedSet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
29 |
import java.util.TreeSet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
30 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
31 |
import javax.lang.model.SourceVersion; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
32 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
33 |
import javax.lang.model.element.TypeElement; |
10 | 34 |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
35 |
import jdk.javadoc.doclet.Doclet; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
36 |
import jdk.javadoc.doclet.DocletEnvironment; |
40587 | 37 |
import jdk.javadoc.doclets.StandardDoclet; |
38 |
import jdk.javadoc.internal.doclets.formats.html.HtmlDoclet; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
40587 | 42 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
43 |
import jdk.javadoc.internal.doclets.toolkit.util.InternalException; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
44 |
import jdk.javadoc.internal.doclets.toolkit.util.PackageListWriter; |
40587 | 45 |
import jdk.javadoc.internal.doclets.toolkit.util.ResourceIOException; |
46 |
import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
47 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
48 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
49 |
import static javax.tools.Diagnostic.Kind.*; |
10 | 50 |
|
51 |
/** |
|
52 |
* An abstract implementation of a Doclet. |
|
53 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
54 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
55 |
* 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
|
56 |
* 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
|
57 |
* deletion without notice.</b> |
10 | 58 |
* |
59 |
* @author Jamie Ho |
|
60 |
*/ |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
61 |
public abstract class AbstractDoclet implements Doclet { |
10 | 62 |
|
63 |
/** |
|
64 |
* The global configuration information for this run. |
|
65 |
*/ |
|
40303 | 66 |
private Configuration configuration; |
67 |
||
68 |
protected Messages messages; |
|
69 |
||
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
70 |
/* |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
71 |
* a handle to our utility methods |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
72 |
*/ |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
73 |
protected Utils utils; |
10 | 74 |
|
75 |
/** |
|
76 |
* The only doclet that may use this toolkit is {@value} |
|
77 |
*/ |
|
14542 | 78 |
private static final String TOOLKIT_DOCLET_NAME = |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
79 |
jdk.javadoc.internal.doclets.formats.html.HtmlDoclet.class.getName(); |
10 | 80 |
|
81 |
/** |
|
82 |
* Verify that the only doclet that is using this toolkit is |
|
83 |
* {@value #TOOLKIT_DOCLET_NAME}. |
|
84 |
*/ |
|
26269
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
85 |
private boolean isValidDoclet() { |
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
86 |
if (!getClass().getName().equals(TOOLKIT_DOCLET_NAME)) { |
40303 | 87 |
messages.error("doclet.Toolkit_Usage_Violation", |
10 | 88 |
TOOLKIT_DOCLET_NAME); |
89 |
return false; |
|
90 |
} |
|
91 |
return true; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* The method that starts the execution of the doclet. |
|
96 |
* |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
97 |
* @param docEnv the {@link DocletEnvironment}. |
10 | 98 |
* @return true if the doclet executed without error. False otherwise. |
99 |
*/ |
|
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
100 |
@Override |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
101 |
public boolean run(DocletEnvironment docEnv) { |
42277 | 102 |
configuration = getConfiguration(); |
103 |
configuration.initConfiguration(docEnv); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
104 |
configuration.cmtUtils = new CommentUtils(configuration); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
105 |
configuration.utils = new Utils(configuration); |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
106 |
utils = configuration.utils; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
107 |
configuration.workArounds = new WorkArounds(configuration); |
40303 | 108 |
messages = configuration.getMessages(); |
109 |
||
26269
0d8efbb110b4
8054925: [javadoc] refactor the Doclet start method.
ksrini
parents:
25874
diff
changeset
|
110 |
if (!isValidDoclet()) { |
10 | 111 |
return false; |
112 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
113 |
|
10 | 114 |
try { |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
115 |
startGeneration(docEnv); |
40587 | 116 |
return true; |
117 |
||
118 |
} catch (DocFileIOException e) { |
|
119 |
switch (e.mode) { |
|
120 |
case READ: |
|
121 |
messages.error("doclet.exception.read.file", |
|
122 |
e.fileName.getPath(), e.getCause()); |
|
123 |
break; |
|
124 |
case WRITE: |
|
125 |
messages.error("doclet.exception.write.file", |
|
126 |
e.fileName.getPath(), e.getCause()); |
|
20600
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
127 |
} |
41451 | 128 |
dumpStack(configuration.dumpOnError, e); |
40587 | 129 |
|
130 |
} catch (ResourceIOException e) { |
|
131 |
messages.error("doclet.exception.read.resource", |
|
132 |
e.resource.getPath(), e.getCause()); |
|
41451 | 133 |
dumpStack(configuration.dumpOnError, e); |
40587 | 134 |
|
135 |
} catch (SimpleDocletException e) { |
|
136 |
configuration.reporter.print(ERROR, e.getMessage()); |
|
41451 | 137 |
dumpStack(configuration.dumpOnError, e); |
40587 | 138 |
|
139 |
} catch (InternalException e) { |
|
140 |
configuration.reporter.print(ERROR, e.getMessage()); |
|
141 |
reportInternalError(e.getCause()); |
|
142 |
||
143 |
} catch (DocletException | RuntimeException | Error e) { |
|
144 |
messages.error("doclet.internal.exception", e); |
|
145 |
reportInternalError(e); |
|
10 | 146 |
} |
40587 | 147 |
|
148 |
return false; |
|
149 |
} |
|
150 |
||
151 |
private void reportInternalError(Throwable t) { |
|
152 |
if (getClass().equals(StandardDoclet.class) || getClass().equals(HtmlDoclet.class)) { |
|
153 |
System.err.println(configuration.getResources().getText("doclet.internal.report.bug")); |
|
154 |
} |
|
155 |
dumpStack(true, t); |
|
156 |
} |
|
157 |
||
158 |
private void dumpStack(boolean enabled, Throwable t) { |
|
159 |
if (enabled && t != null) { |
|
160 |
t.printStackTrace(System.err); |
|
161 |
} |
|
10 | 162 |
} |
163 |
||
164 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
165 |
* Returns the SourceVersion indicating the features supported by this doclet. |
40587 | 166 |
* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
167 |
* @return SourceVersion |
10 | 168 |
*/ |
40315
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
169 |
@Override |
9e994c77db6a
8160137: HTMLDoclet and AbstractDoclet should implement Doclet
jjg
parents:
40303
diff
changeset
|
170 |
public SourceVersion getSupportedSourceVersion() { |
39090
10c2cda4358d
8159396: javadoc getSupportedVersion returns 8 instead of 9
ksrini
parents:
36526
diff
changeset
|
171 |
return SourceVersion.RELEASE_9; |
10 | 172 |
} |
173 |
||
174 |
/** |
|
175 |
* Create the configuration instance and returns it. |
|
40587 | 176 |
* |
10 | 177 |
* @return the configuration of the doclet. |
178 |
*/ |
|
42277 | 179 |
public abstract Configuration getConfiguration(); |
10 | 180 |
|
181 |
/** |
|
182 |
* Start the generation of files. Call generate methods in the individual |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
183 |
* writers, which will in turn generate the documentation files. Call the |
10 | 184 |
* TreeWriter generation first to ensure the Class Hierarchy is built |
185 |
* first and then can be used in the later generation. |
|
186 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
187 |
* @see jdk.doclet.DocletEnvironment |
40587 | 188 |
* @throws DocletException if there is a problem while generating the documentation |
10 | 189 |
*/ |
40587 | 190 |
private void startGeneration(DocletEnvironment docEnv) throws DocletException { |
42277 | 191 |
if (configuration.getIncludedTypeElements().isEmpty()) { |
40303 | 192 |
messages.error("doclet.No_Public_Classes_To_Document"); |
10 | 193 |
return; |
194 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
195 |
if (!configuration.setOptions()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
196 |
return; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
197 |
} |
40303 | 198 |
messages.notice("doclet.build_version", |
10 | 199 |
configuration.getDocletSpecificBuildDate()); |
200 |
ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated); |
|
201 |
||
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
202 |
generateClassFiles(docEnv, classtree); |
10 | 203 |
|
204 |
PackageListWriter.generate(configuration); |
|
205 |
generatePackageFiles(classtree); |
|
36526 | 206 |
generateModuleFiles(); |
10 | 207 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40315
diff
changeset
|
208 |
generateOtherFiles(docEnv, classtree); |
10 | 209 |
configuration.tagletManager.printReport(); |
210 |
} |
|
211 |
||
212 |
/** |
|
213 |
* Generate additional documentation that is added to the API documentation. |
|
214 |
* |
|
40587 | 215 |
* @param docEnv the DocletEnvironment |
216 |
* @param classtree the data structure representing the class tree |
|
217 |
* @throws DocletException if there is a problem while generating the documentation |
|
10 | 218 |
*/ |
40587 | 219 |
protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree) |
220 |
throws DocletException { |
|
10 | 221 |
BuilderFactory builderFactory = configuration.getBuilderFactory(); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
222 |
AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuilder(); |
10 | 223 |
constantsSummaryBuilder.build(); |
224 |
AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); |
|
225 |
serializedFormBuilder.build(); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
36526 | 229 |
* Generate the module documentation. |
230 |
* |
|
40587 | 231 |
* @throws DocletException if there is a problem while generating the documentation |
232 |
* |
|
36526 | 233 |
*/ |
40587 | 234 |
protected abstract void generateModuleFiles() throws DocletException; |
36526 | 235 |
|
236 |
/** |
|
10 | 237 |
* Generate the package documentation. |
238 |
* |
|
40587 | 239 |
* @param classtree the data structure representing the class tree |
240 |
* @throws DocletException if there is a problem while generating the documentation |
|
10 | 241 |
*/ |
40587 | 242 |
protected abstract void generatePackageFiles(ClassTree classtree) throws DocletException; |
10 | 243 |
|
244 |
/** |
|
245 |
* Generate the class documentation. |
|
246 |
* |
|
40587 | 247 |
* @param arr the set of types to be documented |
248 |
* @param classtree the data structure representing the class tree |
|
249 |
* @throws DocletException if there is a problem while generating the documentation |
|
10 | 250 |
*/ |
40587 | 251 |
protected abstract void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree) |
252 |
throws DocletException; |
|
10 | 253 |
|
254 |
/** |
|
255 |
* Iterate through all classes and construct documentation for them. |
|
256 |
* |
|
40587 | 257 |
* @param docEnv the DocletEnvironment |
258 |
* @param classtree the data structure representing the class tree |
|
259 |
* @throws DocletException if there is a problem while generating the documentation |
|
10 | 260 |
*/ |
40587 | 261 |
protected void generateClassFiles(DocletEnvironment docEnv, ClassTree classtree) |
262 |
throws DocletException { |
|
10 | 263 |
generateClassFiles(classtree); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
264 |
SortedSet<PackageElement> packages = new TreeSet<>(utils.makePackageComparator()); |
42277 | 265 |
packages.addAll(configuration.getSpecifiedPackageElements()); |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42277
diff
changeset
|
266 |
configuration.modulePackages.values().stream().forEach(packages::addAll); |
40587 | 267 |
for (PackageElement pkg : packages) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
268 |
generateClassFiles(utils.getAllClasses(pkg), classtree); |
40587 | 269 |
} |
10 | 270 |
} |
271 |
||
272 |
/** |
|
273 |
* Generate the class files for single classes specified on the command line. |
|
274 |
* |
|
40587 | 275 |
* @param classtree the data structure representing the class tree |
276 |
* @throws DocletException if there is a problem while generating the documentation |
|
10 | 277 |
*/ |
40587 | 278 |
private void generateClassFiles(ClassTree classtree) throws DocletException { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
279 |
SortedSet<PackageElement> packages = configuration.typeElementCatalog.packages(); |
40587 | 280 |
for (PackageElement pkg : packages) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
26269
diff
changeset
|
281 |
generateClassFiles(configuration.typeElementCatalog.allClasses(pkg), classtree); |
40587 | 282 |
} |
10 | 283 |
} |
284 |
} |