author | ksrini |
Mon, 05 Jun 2017 13:45:34 -0700 | |
changeset 45417 | f7479ee8de69 |
parent 43261 | d377e97291d8 |
child 45599 | 8bc3a019f948 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45417 | 2 |
* Copyright (c) 2003, 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.builders; |
10 | 27 |
|
28 |
import java.lang.reflect.*; |
|
29 |
import java.util.*; |
|
30 |
||
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; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
34 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40587 | 35 |
import jdk.javadoc.internal.doclets.toolkit.DocletException; |
40303 | 36 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
40587 | 37 |
import jdk.javadoc.internal.doclets.toolkit.Resources; |
43261 | 38 |
import jdk.javadoc.internal.doclets.toolkit.util.UncheckedDocletException; |
40587 | 39 |
import jdk.javadoc.internal.doclets.toolkit.util.InternalException; |
40 |
import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
42 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
43 |
import static javax.tools.Diagnostic.Kind.*; |
14258 | 44 |
|
10 | 45 |
/** |
46 |
* The superclass for all builders. A builder is a class that provides |
|
47 |
* the structure and content of API documentation. A builder is completely |
|
48 |
* doclet independent which means that any doclet can use builders to |
|
49 |
* construct documentation, as long as it impelements the appropriate |
|
50 |
* writer interfaces. For example, if a doclet wanted to use |
|
51 |
* {@link ConstantsSummaryBuilder} to build a constant summary, all it has to |
|
52 |
* do is implement the ConstantsSummaryWriter interface and pass it to the |
|
53 |
* builder using a WriterFactory. |
|
54 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
55 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
56 |
* 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
|
57 |
* 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
|
58 |
* deletion without notice.</b> |
10 | 59 |
* |
60 |
* @author Jamie Ho |
|
61 |
*/ |
|
62 |
||
63 |
public abstract class AbstractBuilder { |
|
14542 | 64 |
public static class Context { |
65 |
/** |
|
66 |
* The configuration used in this run of the doclet. |
|
67 |
*/ |
|
45417 | 68 |
final BaseConfiguration configuration; |
14542 | 69 |
|
70 |
/** |
|
71 |
* Keep track of which packages we have seen for |
|
72 |
* efficiency purposes. We don't want to copy the |
|
73 |
* doc files multiple times for a single package. |
|
74 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
75 |
final Set<PackageElement> containingPackagesSeen; |
14542 | 76 |
|
77 |
/** |
|
78 |
* Shared parser for the builder XML file |
|
79 |
*/ |
|
80 |
final LayoutParser layoutParser; |
|
81 |
||
45417 | 82 |
Context(BaseConfiguration configuration, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
83 |
Set<PackageElement> containingPackagesSeen, |
14542 | 84 |
LayoutParser layoutParser) { |
85 |
this.configuration = configuration; |
|
86 |
this.containingPackagesSeen = containingPackagesSeen; |
|
87 |
this.layoutParser = layoutParser; |
|
88 |
} |
|
89 |
} |
|
10 | 90 |
|
91 |
/** |
|
92 |
* The configuration used in this run of the doclet. |
|
93 |
*/ |
|
45417 | 94 |
protected final BaseConfiguration configuration; |
10 | 95 |
|
40303 | 96 |
protected final Messages messages; |
40587 | 97 |
protected final Resources resources; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
98 |
protected final Utils utils; |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
99 |
|
10 | 100 |
/** |
101 |
* Keep track of which packages we have seen for |
|
102 |
* efficiency purposes. We don't want to copy the |
|
103 |
* doc files multiple times for a single package. |
|
104 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
105 |
protected final Set<PackageElement> containingPackagesSeen; |
14542 | 106 |
|
107 |
protected final LayoutParser layoutParser; |
|
10 | 108 |
|
109 |
/** |
|
110 |
* True if we want to print debug output. |
|
111 |
*/ |
|
112 |
protected static final boolean DEBUG = false; |
|
113 |
||
114 |
/** |
|
115 |
* Construct a Builder. |
|
40587 | 116 |
* @param c a context providing information used in this run of the doclet |
10 | 117 |
*/ |
14542 | 118 |
public AbstractBuilder(Context c) { |
119 |
this.configuration = c.configuration; |
|
40303 | 120 |
this.messages = configuration.getMessages(); |
40587 | 121 |
this.resources = configuration.getResources(); |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
122 |
this.utils = configuration.utils; |
14542 | 123 |
this.containingPackagesSeen = c.containingPackagesSeen; |
124 |
this.layoutParser = c.layoutParser; |
|
10 | 125 |
} |
126 |
||
127 |
/** |
|
128 |
* Return the name of this builder. |
|
129 |
* |
|
130 |
* @return the name of the builder. |
|
131 |
*/ |
|
132 |
public abstract String getName(); |
|
133 |
||
134 |
/** |
|
135 |
* Build the documentation. |
|
136 |
* |
|
40587 | 137 |
* @throws DocletException if there is a problem building the documentation |
10 | 138 |
*/ |
40587 | 139 |
public abstract void build() throws DocletException; |
10 | 140 |
|
141 |
/** |
|
5855 | 142 |
* Build the documentation, as specified by the given XML element. |
10 | 143 |
* |
5855 | 144 |
* @param node the XML element that specifies which component to document. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
145 |
* @param contentTree content tree to which the documentation will be added |
40587 | 146 |
* @throws DocletException if there is a problem building the documentation |
10 | 147 |
*/ |
40587 | 148 |
protected void build(XMLNode node, Content contentTree) throws DocletException { |
5855 | 149 |
String component = node.name; |
150 |
try { |
|
40587 | 151 |
String methodName = "build" + component; |
152 |
if (DEBUG) { |
|
153 |
configuration.reporter.print(ERROR, |
|
154 |
"DEBUG: " + getClass().getName() + "." + methodName); |
|
155 |
} |
|
156 |
Method method = getClass().getMethod(methodName, XMLNode.class, Content.class); |
|
157 |
method.invoke(this, node, contentTree); |
|
158 |
||
5855 | 159 |
} catch (NoSuchMethodException e) { |
40587 | 160 |
// Use SimpleDocletException instead of InternalException because there is nothing |
161 |
// informative about about the place the exception occurred, here in this method. |
|
162 |
// The problem is either a misconfigured doclet.xml file or a missing method in the |
|
163 |
// user-supplied(?) doclet |
|
164 |
String message = resources.getText("doclet.builder.unknown.component", component); |
|
165 |
throw new SimpleDocletException(message, e); |
|
166 |
||
5855 | 167 |
} catch (InvocationTargetException e) { |
40303 | 168 |
Throwable cause = e.getCause(); |
40587 | 169 |
if (cause instanceof DocletException) { |
170 |
throw (DocletException) cause; |
|
43261 | 171 |
} else if (cause instanceof UncheckedDocletException) { |
172 |
throw (DocletException) cause.getCause(); |
|
40303 | 173 |
} else { |
40587 | 174 |
// use InternalException, so that a stacktrace showing the position of |
175 |
// the internal exception is generated |
|
176 |
String message = resources.getText("doclet.builder.exception.in.component", component, |
|
177 |
e.getCause()); |
|
178 |
throw new InternalException(message, e.getCause()); |
|
40303 | 179 |
} |
40587 | 180 |
|
181 |
} catch (ReflectiveOperationException e) { |
|
182 |
// Use SimpleDocletException instead of InternalException because there is nothing |
|
183 |
// informative about about the place the exception occurred, here in this method. |
|
184 |
// The problem is specific to the method being invoked, such as illegal access |
|
185 |
// or illegal argument. |
|
186 |
String message = resources.getText("doclet.builder.exception.in.component", component, e); |
|
187 |
throw new SimpleDocletException(message, e.getCause()); |
|
10 | 188 |
} |
189 |
} |
|
190 |
||
191 |
/** |
|
5855 | 192 |
* Build the documentation, as specified by the children of the given XML element. |
193 |
* |
|
194 |
* @param node the XML element that specifies which components to document. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
195 |
* @param contentTree content tree to which the documentation will be added |
40587 | 196 |
* @throws DocletException if there is a problem while building the children |
5855 | 197 |
*/ |
40587 | 198 |
protected void buildChildren(XMLNode node, Content contentTree) throws DocletException { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
199 |
for (XMLNode child : node.children) |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
200 |
build(child, contentTree); |
5855 | 201 |
} |
10 | 202 |
} |