Tue, 14 May 2013 10:14:51 -0700
8010440: Replace int constants in LinkInfoImpl with enum
Reviewed-by: bpatel, darcy
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.IOException;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.formats.html.markup.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.internal.toolkit.builders.*;
34 import com.sun.tools.doclets.internal.toolkit.util.*;
36 /**
37 * Generate the Class Information Page.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 *
44 * @see com.sun.javadoc.ClassDoc
45 * @see java.util.Collections
46 * @see java.util.List
47 * @see java.util.ArrayList
48 * @see java.util.HashMap
49 *
50 * @author Atul M Dambalkar
51 * @author Robert Field
52 * @author Bhavesh Patel (Modified)
53 */
54 public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
55 implements AnnotationTypeWriter {
57 protected AnnotationTypeDoc annotationType;
59 protected Type prev;
61 protected Type next;
63 /**
64 * @param annotationType the annotation type being documented.
65 * @param prevType the previous class that was documented.
66 * @param nextType the next class being documented.
67 */
68 public AnnotationTypeWriterImpl(ConfigurationImpl configuration,
69 AnnotationTypeDoc annotationType, Type prevType, Type nextType)
70 throws Exception {
71 super(configuration, DocPath.forClass(annotationType));
72 this.annotationType = annotationType;
73 configuration.currentcd = annotationType.asClassDoc();
74 this.prev = prevType;
75 this.next = nextType;
76 }
78 /**
79 * Get this package link.
80 *
81 * @return a content tree for the package link
82 */
83 protected Content getNavLinkPackage() {
84 Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
85 packageLabel);
86 Content li = HtmlTree.LI(linkContent);
87 return li;
88 }
90 /**
91 * Get the class link.
92 *
93 * @return a content tree for the class link
94 */
95 protected Content getNavLinkClass() {
96 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel);
97 return li;
98 }
100 /**
101 * Get the class use link.
102 *
103 * @return a content tree for the class use link
104 */
105 protected Content getNavLinkClassUse() {
106 Content linkContent = getHyperLink(DocPaths.CLASS_USE.resolve(filename), useLabel);
107 Content li = HtmlTree.LI(linkContent);
108 return li;
109 }
111 /**
112 * Get link to previous class.
113 *
114 * @return a content tree for the previous class link
115 */
116 public Content getNavLinkPrevious() {
117 Content li;
118 if (prev != null) {
119 Content prevLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
120 LinkInfoImpl.Kind.CLASS, prev.asClassDoc(), "",
121 configuration.getText("doclet.Prev_Class"), true)));
122 li = HtmlTree.LI(prevLink);
123 }
124 else
125 li = HtmlTree.LI(prevclassLabel);
126 return li;
127 }
129 /**
130 * Get link to next class.
131 *
132 * @return a content tree for the next class link
133 */
134 public Content getNavLinkNext() {
135 Content li;
136 if (next != null) {
137 Content nextLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
138 LinkInfoImpl.Kind.CLASS, next.asClassDoc(), "",
139 configuration.getText("doclet.Next_Class"), true)));
140 li = HtmlTree.LI(nextLink);
141 }
142 else
143 li = HtmlTree.LI(nextclassLabel);
144 return li;
145 }
147 /**
148 * {@inheritDoc}
149 */
150 public Content getHeader(String header) {
151 String pkgname = (annotationType.containingPackage() != null)?
152 annotationType.containingPackage().name(): "";
153 String clname = annotationType.name();
154 Content bodyTree = getBody(true, getWindowTitle(clname));
155 addTop(bodyTree);
156 addNavLinks(true, bodyTree);
157 bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
158 HtmlTree div = new HtmlTree(HtmlTag.DIV);
159 div.addStyle(HtmlStyle.header);
160 if (pkgname.length() > 0) {
161 Content pkgNameContent = new StringContent(pkgname);
162 Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent);
163 div.addContent(pkgNameDiv);
164 }
165 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
166 LinkInfoImpl.Kind.CLASS_HEADER, annotationType, false);
167 Content headerContent = new StringContent(header);
168 Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
169 HtmlStyle.title, headerContent);
170 heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo)));
171 div.addContent(heading);
172 bodyTree.addContent(div);
173 return bodyTree;
174 }
176 /**
177 * {@inheritDoc}
178 */
179 public Content getAnnotationContentHeader() {
180 return getContentHeader();
181 }
183 /**
184 * {@inheritDoc}
185 */
186 public void addFooter(Content contentTree) {
187 contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
188 addNavLinks(false, contentTree);
189 addBottom(contentTree);
190 }
192 /**
193 * {@inheritDoc}
194 */
195 public void printDocument(Content contentTree) throws IOException {
196 printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
197 true, contentTree);
198 }
200 /**
201 * {@inheritDoc}
202 */
203 public Content getAnnotationInfoTreeHeader() {
204 return getMemberTreeHeader();
205 }
207 /**
208 * {@inheritDoc}
209 */
210 public Content getAnnotationInfo(Content annotationInfoTree) {
211 return getMemberTree(HtmlStyle.description, annotationInfoTree);
212 }
214 /**
215 * {@inheritDoc}
216 */
217 public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) {
218 annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR));
219 Content pre = new HtmlTree(HtmlTag.PRE);
220 addAnnotationInfo(annotationType, pre);
221 pre.addContent(modifiers);
222 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
223 LinkInfoImpl.Kind.CLASS_SIGNATURE, annotationType, false);
224 Content annotationName = new StringContent(annotationType.name());
225 Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo));
226 if (configuration.linksource) {
227 addSrcLink(annotationType, annotationName, pre);
228 pre.addContent(parameterLinks);
229 } else {
230 Content span = HtmlTree.SPAN(HtmlStyle.strong, annotationName);
231 span.addContent(parameterLinks);
232 pre.addContent(span);
233 }
234 annotationInfoTree.addContent(pre);
235 }
237 /**
238 * {@inheritDoc}
239 */
240 public void addAnnotationTypeDescription(Content annotationInfoTree) {
241 if(!configuration.nocomment) {
242 if (annotationType.inlineTags().length > 0) {
243 addInlineComment(annotationType, annotationInfoTree);
244 }
245 }
246 }
248 /**
249 * {@inheritDoc}
250 */
251 public void addAnnotationTypeTagInfo(Content annotationInfoTree) {
252 if(!configuration.nocomment) {
253 addTagsInfo(annotationType, annotationInfoTree);
254 }
255 }
257 /**
258 * {@inheritDoc}
259 */
260 public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) {
261 Content hr = new HtmlTree(HtmlTag.HR);
262 annotationInfoTree.addContent(hr);
263 Tag[] deprs = annotationType.tags("deprecated");
264 if (Util.isDeprecated(annotationType)) {
265 Content strong = HtmlTree.STRONG(deprecatedPhrase);
266 Content div = HtmlTree.DIV(HtmlStyle.block, strong);
267 if (deprs.length > 0) {
268 Tag[] commentTags = deprs[0].inlineTags();
269 if (commentTags.length > 0) {
270 div.addContent(getSpace());
271 addInlineDeprecatedComment(annotationType, deprs[0], div);
272 }
273 }
274 annotationInfoTree.addContent(div);
275 }
276 }
278 /**
279 * {@inheritDoc}
280 */
281 public void addAnnotationDetailsMarker(Content memberDetails) {
282 memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
283 }
285 /**
286 * {@inheritDoc}
287 */
288 protected Content getNavLinkTree() {
289 Content treeLinkContent = getHyperLink(DocPaths.PACKAGE_TREE,
290 treeLabel, "", "");
291 Content li = HtmlTree.LI(treeLinkContent);
292 return li;
293 }
295 /**
296 * Add summary details to the navigation bar.
297 *
298 * @param subDiv the content tree to which the summary detail links will be added
299 */
300 protected void addSummaryDetailLinks(Content subDiv) {
301 try {
302 Content div = HtmlTree.DIV(getNavSummaryLinks());
303 div.addContent(getNavDetailLinks());
304 subDiv.addContent(div);
305 } catch (Exception e) {
306 e.printStackTrace();
307 throw new DocletAbortException();
308 }
309 }
311 /**
312 * Get summary links for navigation bar.
313 *
314 * @return the content tree for the navigation summary links
315 */
316 protected Content getNavSummaryLinks() throws Exception {
317 Content li = HtmlTree.LI(summaryLabel);
318 li.addContent(getSpace());
319 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
320 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
321 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
322 Content liNavReq = new HtmlTree(HtmlTag.LI);
323 addNavSummaryLink(memberSummaryBuilder,
324 "doclet.navAnnotationTypeRequiredMember",
325 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq);
326 addNavGap(liNavReq);
327 ulNav.addContent(liNavReq);
328 Content liNavOpt = new HtmlTree(HtmlTag.LI);
329 addNavSummaryLink(memberSummaryBuilder,
330 "doclet.navAnnotationTypeOptionalMember",
331 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt);
332 ulNav.addContent(liNavOpt);
333 return ulNav;
334 }
336 /**
337 * Add the navigation summary link.
338 *
339 * @param builder builder for the member to be documented
340 * @param label the label for the navigation
341 * @param type type to be documented
342 * @param liNav the content tree to which the navigation summary link will be added
343 */
344 protected void addNavSummaryLink(MemberSummaryBuilder builder,
345 String label, int type, Content liNav) {
346 AbstractMemberWriter writer = ((AbstractMemberWriter) builder.
347 getMemberSummaryWriter(type));
348 if (writer == null) {
349 liNav.addContent(getResource(label));
350 } else {
351 liNav.addContent(writer.getNavSummaryLink(null,
352 ! builder.getVisibleMemberMap(type).noVisibleMembers()));
353 }
354 }
356 /**
357 * Get detail links for the navigation bar.
358 *
359 * @return the content tree for the detail links
360 */
361 protected Content getNavDetailLinks() throws Exception {
362 Content li = HtmlTree.LI(detailLabel);
363 li.addContent(getSpace());
364 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
365 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
366 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
367 AbstractMemberWriter writerOptional =
368 ((AbstractMemberWriter) memberSummaryBuilder.
369 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
370 AbstractMemberWriter writerRequired =
371 ((AbstractMemberWriter) memberSummaryBuilder.
372 getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
373 if (writerOptional != null){
374 Content liNavOpt = new HtmlTree(HtmlTag.LI);
375 writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt);
376 ulNav.addContent(liNavOpt);
377 } else if (writerRequired != null){
378 Content liNavReq = new HtmlTree(HtmlTag.LI);
379 writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq);
380 ulNav.addContent(liNavReq);
381 } else {
382 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember"));
383 ulNav.addContent(liNav);
384 }
385 return ulNav;
386 }
388 /**
389 * Add gap between navigation bar elements.
390 *
391 * @param liNav the content tree to which the gap will be added
392 */
393 protected void addNavGap(Content liNav) {
394 liNav.addContent(getSpace());
395 liNav.addContent("|");
396 liNav.addContent(getSpace());
397 }
399 /**
400 * {@inheritDoc}
401 */
402 public AnnotationTypeDoc getAnnotationTypeDoc() {
403 return annotationType;
404 }
405 }