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