author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45599 | langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/AnnotationTypeBuilder.java@8bc3a019f948 |
child 47272 | e0d686cdf608 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45599 | 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:
29957
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.builders; |
10 | 27 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
28 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
29 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
30 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
31 |
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
32 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40587 | 33 |
import jdk.javadoc.internal.doclets.toolkit.DocletException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
34 |
|
10 | 35 |
|
36 |
/** |
|
37 |
* Builds the summary for a given annotation type. |
|
38 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
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:
14258
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:
14258
diff
changeset
|
42 |
* deletion without notice.</b> |
10 | 43 |
* |
44 |
* @author Jamie Ho |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
45 |
* @author Bhavesh Patel (Modified) |
10 | 46 |
*/ |
47 |
public class AnnotationTypeBuilder extends AbstractBuilder { |
|
48 |
||
49 |
/** |
|
50 |
* The annotation type being documented. |
|
51 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
52 |
private final TypeElement annotationType; |
10 | 53 |
|
54 |
/** |
|
55 |
* The doclet specific writer. |
|
56 |
*/ |
|
14542 | 57 |
private final AnnotationTypeWriter writer; |
10 | 58 |
|
59 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
60 |
* The content tree for the annotation documentation. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
61 |
*/ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
62 |
private Content contentTree; |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
63 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
64 |
/** |
10 | 65 |
* Construct a new ClassBuilder. |
66 |
* |
|
14542 | 67 |
* @param context the build context. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
68 |
* @param annotationTypeElement the class being documented. |
14542 | 69 |
* @param writer the doclet specific writer. |
10 | 70 |
*/ |
14542 | 71 |
private AnnotationTypeBuilder(Context context, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
72 |
TypeElement annotationTypeElement, |
14542 | 73 |
AnnotationTypeWriter writer) { |
74 |
super(context); |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
75 |
this.annotationType = annotationTypeElement; |
14542 | 76 |
this.writer = writer; |
10 | 77 |
} |
78 |
||
79 |
/** |
|
40587 | 80 |
* Construct a new AnnotationTypeBuilder. |
10 | 81 |
* |
14542 | 82 |
* @param context the build context. |
10 | 83 |
* @param annotationTypeDoc the class being documented. |
84 |
* @param writer the doclet specific writer. |
|
40587 | 85 |
* @return an AnnotationTypeBuilder |
10 | 86 |
*/ |
14542 | 87 |
public static AnnotationTypeBuilder getInstance(Context context, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
88 |
TypeElement annotationTypeDoc, |
40587 | 89 |
AnnotationTypeWriter writer) { |
14542 | 90 |
return new AnnotationTypeBuilder(context, annotationTypeDoc, writer); |
10 | 91 |
} |
92 |
||
93 |
/** |
|
94 |
* {@inheritDoc} |
|
95 |
*/ |
|
40587 | 96 |
@Override |
97 |
public void build() throws DocletException { |
|
45599 | 98 |
buildAnnotationTypeDoc(contentTree); |
10 | 99 |
} |
100 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
101 |
/** |
40587 | 102 |
* Build the annotation type documentation. |
103 |
* |
|
104 |
* @param contentTree the content tree to which the documentation will be added |
|
105 |
* @throws DocletException if there is a problem building the documentation |
|
106 |
*/ |
|
45599 | 107 |
protected void buildAnnotationTypeDoc(Content contentTree) throws DocletException { |
40587 | 108 |
contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") + |
109 |
" " + utils.getSimpleName(annotationType)); |
|
110 |
Content annotationContentTree = writer.getAnnotationContentHeader(); |
|
45599 | 111 |
|
112 |
buildAnnotationTypeInfo(annotationContentTree); |
|
113 |
buildMemberSummary(annotationContentTree); |
|
114 |
buildAnnotationTypeMemberDetails(annotationContentTree); |
|
115 |
||
40587 | 116 |
writer.addAnnotationContentTree(contentTree, annotationContentTree); |
117 |
writer.addFooter(contentTree); |
|
118 |
writer.printDocument(contentTree); |
|
119 |
copyDocFiles(); |
|
120 |
} |
|
10 | 121 |
|
40587 | 122 |
/** |
123 |
* Copy the doc files for the current TypeElement if necessary. |
|
124 |
* |
|
125 |
* @throws DocletException if there is a problem building the documentation |
|
126 |
*/ |
|
127 |
private void copyDocFiles() throws DocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
128 |
PackageElement containingPackage = utils.containingPackage(annotationType); |
45599 | 129 |
if ((configuration.packages == null || |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
20237
diff
changeset
|
130 |
!configuration.packages.contains(containingPackage) && |
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
20237
diff
changeset
|
131 |
!containingPackagesSeen.contains(containingPackage))){ |
10 | 132 |
//Only copy doc files dir if the containing package is not |
133 |
//documented AND if we have not documented a class from the same |
|
134 |
//package already. Otherwise, we are making duplicate copies. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
135 |
utils.copyDocFiles(containingPackage); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
20237
diff
changeset
|
136 |
containingPackagesSeen.add(containingPackage); |
10 | 137 |
} |
40587 | 138 |
} |
10 | 139 |
|
140 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
141 |
* Build the annotation information tree documentation. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
142 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
143 |
* @param annotationContentTree the content tree to which the documentation will be added |
40587 | 144 |
* @throws DocletException if there is a problem building the documentation |
10 | 145 |
*/ |
45599 | 146 |
protected void buildAnnotationTypeInfo(Content annotationContentTree) |
40587 | 147 |
throws DocletException { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
148 |
Content annotationInfoTree = writer.getAnnotationInfoTreeHeader(); |
45599 | 149 |
|
150 |
buildDeprecationInfo(annotationInfoTree); |
|
151 |
buildAnnotationTypeSignature(annotationInfoTree); |
|
152 |
buildAnnotationTypeDescription(annotationInfoTree); |
|
153 |
buildAnnotationTypeTagInfo(annotationInfoTree); |
|
154 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
155 |
annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree)); |
10 | 156 |
} |
157 |
||
158 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
159 |
* If this annotation is deprecated, build the appropriate information. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
160 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
161 |
* @param annotationInfoTree the content tree to which the documentation will be added |
10 | 162 |
*/ |
45599 | 163 |
protected void buildDeprecationInfo(Content annotationInfoTree) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
164 |
writer.addAnnotationTypeDeprecationInfo(annotationInfoTree); |
10 | 165 |
} |
166 |
||
167 |
/** |
|
168 |
* Build the signature of the current annotation type. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
169 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
170 |
* @param annotationInfoTree the content tree to which the documentation will be added |
10 | 171 |
*/ |
45599 | 172 |
protected void buildAnnotationTypeSignature(Content annotationInfoTree) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
173 |
writer.addAnnotationTypeSignature(utils.modifiersToString(annotationType, true), |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
174 |
annotationInfoTree); |
10 | 175 |
} |
176 |
||
177 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
178 |
* Build the annotation type description. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
179 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
180 |
* @param annotationInfoTree the content tree to which the documentation will be added |
10 | 181 |
*/ |
45599 | 182 |
protected void buildAnnotationTypeDescription(Content annotationInfoTree) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
183 |
writer.addAnnotationTypeDescription(annotationInfoTree); |
10 | 184 |
} |
185 |
||
186 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
187 |
* Build the tag information for the current annotation type. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
188 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
189 |
* @param annotationInfoTree the content tree to which the documentation will be added |
10 | 190 |
*/ |
45599 | 191 |
protected void buildAnnotationTypeTagInfo(Content annotationInfoTree) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
192 |
writer.addAnnotationTypeTagInfo(annotationInfoTree); |
10 | 193 |
} |
194 |
||
195 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
196 |
* Build the member summary contents of the page. |
10 | 197 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
198 |
* @param annotationContentTree the content tree to which the documentation will be added |
40587 | 199 |
* @throws DocletException if there is a problem building the documentation |
10 | 200 |
*/ |
45599 | 201 |
protected void buildMemberSummary(Content annotationContentTree) throws DocletException { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
202 |
Content memberSummaryTree = writer.getMemberTreeHeader(); |
45599 | 203 |
builderFactory.getMemberSummaryBuilder(writer).build(memberSummaryTree); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
204 |
annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
205 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
206 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
207 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
208 |
* Build the member details contents of the page. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
209 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
210 |
* @param annotationContentTree the content tree to which the documentation will be added |
40587 | 211 |
* @throws DocletException if there is a problem building the documentation |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
212 |
*/ |
45599 | 213 |
protected void buildAnnotationTypeMemberDetails(Content annotationContentTree) |
40587 | 214 |
throws DocletException { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
215 |
Content memberDetailsTree = writer.getMemberTreeHeader(); |
45599 | 216 |
|
217 |
buildAnnotationTypeFieldDetails(memberDetailsTree); |
|
218 |
buildAnnotationTypeRequiredMemberDetails(memberDetailsTree); |
|
219 |
buildAnnotationTypeOptionalMemberDetails(memberDetailsTree); |
|
220 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
221 |
if (memberDetailsTree.isValid()) { |
20237
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
222 |
annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree)); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
223 |
} |
10 | 224 |
} |
225 |
||
226 |
/** |
|
20237
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
227 |
* Build the annotation type field documentation. |
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
228 |
* |
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
229 |
* @param memberDetailsTree the content tree to which the documentation will be added |
40587 | 230 |
* @throws DocletException if there is a problem building the documentation |
20237
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
231 |
*/ |
45599 | 232 |
protected void buildAnnotationTypeFieldDetails(Content memberDetailsTree) |
40587 | 233 |
throws DocletException { |
45599 | 234 |
builderFactory.getAnnotationTypeFieldsBuilder(writer).build(memberDetailsTree); |
20237
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
235 |
} |
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
236 |
|
b6d89903c867
8015249: javadoc fails to document static final fields in annotation types
bpatel
parents:
16560
diff
changeset
|
237 |
/** |
10 | 238 |
* Build the annotation type optional member documentation. |
239 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
240 |
* @param memberDetailsTree the content tree to which the documentation will be added |
40587 | 241 |
* @throws DocletException if there is a problem building the documentation |
10 | 242 |
*/ |
45599 | 243 |
protected void buildAnnotationTypeOptionalMemberDetails(Content memberDetailsTree) |
40587 | 244 |
throws DocletException { |
45599 | 245 |
builderFactory.getAnnotationTypeOptionalMemberBuilder(writer).build(memberDetailsTree); |
10 | 246 |
} |
247 |
||
248 |
/** |
|
249 |
* Build the annotation type required member documentation. |
|
250 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
251 |
* @param memberDetailsTree the content tree to which the documentation will be added |
40587 | 252 |
* @throws DocletException if there is a problem building the documentation |
10 | 253 |
*/ |
45599 | 254 |
protected void buildAnnotationTypeRequiredMemberDetails(Content memberDetailsTree) |
40587 | 255 |
throws DocletException { |
45599 | 256 |
builderFactory.getAnnotationTypeRequiredMemberBuilder(writer).build(memberDetailsTree); |
10 | 257 |
} |
258 |
} |