author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 22159 | 682da512ec17 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
2 |
* Copyright (c) 2003, 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; |
|
27 |
||
14258 | 28 |
import com.sun.javadoc.*; |
10 | 29 |
import com.sun.tools.doclets.internal.toolkit.builders.*; |
30 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
31 |
||
32 |
/** |
|
33 |
* An abstract implementation of a Doclet. |
|
34 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
35 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
36 |
* 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
|
37 |
* 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
|
38 |
* deletion without notice.</b> |
10 | 39 |
* |
40 |
* @author Jamie Ho |
|
41 |
*/ |
|
42 |
public abstract class AbstractDoclet { |
|
43 |
||
44 |
/** |
|
45 |
* The global configuration information for this run. |
|
46 |
*/ |
|
1475 | 47 |
public Configuration configuration; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
48 |
/* |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
49 |
* a handle to our utility methods |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
50 |
*/ |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
51 |
protected Utils utils; |
10 | 52 |
|
53 |
/** |
|
54 |
* The only doclet that may use this toolkit is {@value} |
|
55 |
*/ |
|
14542 | 56 |
private static final String TOOLKIT_DOCLET_NAME = |
57 |
com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName(); |
|
10 | 58 |
|
59 |
/** |
|
60 |
* Verify that the only doclet that is using this toolkit is |
|
61 |
* {@value #TOOLKIT_DOCLET_NAME}. |
|
62 |
*/ |
|
63 |
private boolean isValidDoclet(AbstractDoclet doclet) { |
|
64 |
if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) { |
|
65 |
configuration.message.error("doclet.Toolkit_Usage_Violation", |
|
66 |
TOOLKIT_DOCLET_NAME); |
|
67 |
return false; |
|
68 |
} |
|
69 |
return true; |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* The method that starts the execution of the doclet. |
|
74 |
* |
|
75 |
* @param doclet the doclet to start the execution for. |
|
76 |
* @param root the {@link RootDoc} that points to the source to document. |
|
77 |
* @return true if the doclet executed without error. False otherwise. |
|
78 |
*/ |
|
79 |
public boolean start(AbstractDoclet doclet, RootDoc root) { |
|
1475 | 80 |
configuration = configuration(); |
10 | 81 |
configuration.root = root; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
82 |
utils = configuration.utils; |
10 | 83 |
if (! isValidDoclet(doclet)) { |
84 |
return false; |
|
85 |
} |
|
86 |
try { |
|
87 |
doclet.startGeneration(root); |
|
16324 | 88 |
} catch (Configuration.Fault f) { |
89 |
root.printError(f.getMessage()); |
|
90 |
return false; |
|
20600
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
91 |
} catch (DocletAbortException e) { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
92 |
Throwable cause = e.getCause(); |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
93 |
if (cause != null) { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
94 |
if (cause.getLocalizedMessage() != null) { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
95 |
root.printError(cause.getLocalizedMessage()); |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
96 |
} else { |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
97 |
root.printError(cause.toString()); |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
98 |
} |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
99 |
} |
052970964bc1
6978886: javadoc shows stacktrace after print error resulting from disk full
kizune
parents:
16324
diff
changeset
|
100 |
return false; |
10 | 101 |
} catch (Exception exc) { |
102 |
return false; |
|
103 |
} |
|
104 |
return true; |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Indicate that this doclet supports the 1.5 language features. |
|
109 |
* @return JAVA_1_5, indicating that the new features are supported. |
|
110 |
*/ |
|
111 |
public static LanguageVersion languageVersion() { |
|
112 |
return LanguageVersion.JAVA_1_5; |
|
113 |
} |
|
114 |
||
115 |
||
116 |
/** |
|
117 |
* Create the configuration instance and returns it. |
|
118 |
* @return the configuration of the doclet. |
|
119 |
*/ |
|
120 |
public abstract Configuration configuration(); |
|
121 |
||
122 |
/** |
|
123 |
* 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
|
124 |
* writers, which will in turn generate the documentation files. Call the |
10 | 125 |
* TreeWriter generation first to ensure the Class Hierarchy is built |
126 |
* first and then can be used in the later generation. |
|
127 |
* |
|
128 |
* @see com.sun.javadoc.RootDoc |
|
129 |
*/ |
|
16324 | 130 |
private void startGeneration(RootDoc root) throws Configuration.Fault, Exception { |
10 | 131 |
if (root.classes().length == 0) { |
132 |
configuration.message. |
|
133 |
error("doclet.No_Public_Classes_To_Document"); |
|
134 |
return; |
|
135 |
} |
|
136 |
configuration.setOptions(); |
|
137 |
configuration.getDocletSpecificMsg().notice("doclet.build_version", |
|
138 |
configuration.getDocletSpecificBuildDate()); |
|
139 |
ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated); |
|
140 |
||
141 |
generateClassFiles(root, classtree); |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
142 |
configuration.utils.copyDocFiles(configuration, DocPaths.DOC_FILES); |
10 | 143 |
|
144 |
PackageListWriter.generate(configuration); |
|
145 |
generatePackageFiles(classtree); |
|
15723
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
146 |
generateProfileFiles(); |
10 | 147 |
|
148 |
generateOtherFiles(root, classtree); |
|
149 |
configuration.tagletManager.printReport(); |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Generate additional documentation that is added to the API documentation. |
|
154 |
* |
|
155 |
* @param root the RootDoc of source to document. |
|
156 |
* @param classtree the data structure representing the class tree. |
|
157 |
*/ |
|
158 |
protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception { |
|
159 |
BuilderFactory builderFactory = configuration.getBuilderFactory(); |
|
160 |
AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider(); |
|
161 |
constantsSummaryBuilder.build(); |
|
162 |
AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); |
|
163 |
serializedFormBuilder.build(); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
15723
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
167 |
* Generate the profile documentation. |
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
168 |
* |
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
169 |
*/ |
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
170 |
protected abstract void generateProfileFiles() throws Exception; |
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
171 |
|
58a73dac9ee4
8006124: javadoc/doclet should be updated to support profiles
bpatel
parents:
14542
diff
changeset
|
172 |
/** |
10 | 173 |
* Generate the package documentation. |
174 |
* |
|
175 |
* @param classtree the data structure representing the class tree. |
|
176 |
*/ |
|
177 |
protected abstract void generatePackageFiles(ClassTree classtree) throws Exception; |
|
178 |
||
179 |
/** |
|
180 |
* Generate the class documentation. |
|
181 |
* |
|
182 |
* @param classtree the data structure representing the class tree. |
|
183 |
*/ |
|
184 |
protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree); |
|
185 |
||
186 |
/** |
|
187 |
* Iterate through all classes and construct documentation for them. |
|
188 |
* |
|
189 |
* @param root the RootDoc of source to document. |
|
190 |
* @param classtree the data structure representing the class tree. |
|
191 |
*/ |
|
192 |
protected void generateClassFiles(RootDoc root, ClassTree classtree) { |
|
193 |
generateClassFiles(classtree); |
|
194 |
PackageDoc[] packages = root.specifiedPackages(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20600
diff
changeset
|
195 |
for (PackageDoc pkg : packages) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20600
diff
changeset
|
196 |
generateClassFiles(pkg.allClasses(), classtree); |
10 | 197 |
} |
198 |
} |
|
199 |
||
200 |
/** |
|
201 |
* Generate the class files for single classes specified on the command line. |
|
202 |
* |
|
203 |
* @param classtree the data structure representing the class tree. |
|
204 |
*/ |
|
205 |
private void generateClassFiles(ClassTree classtree) { |
|
206 |
String[] packageNames = configuration.classDocCatalog.packageNames(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20600
diff
changeset
|
207 |
for (String packageName : packageNames) { |
10 | 208 |
generateClassFiles(configuration.classDocCatalog.allClasses( |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
20600
diff
changeset
|
209 |
packageName), classtree); |
10 | 210 |
} |
211 |
} |
|
212 |
} |